Gradient Explosion: When Your Model Produces 100,000x Gradients

2026-07-04 BUG-003 Pipeline: PASS Detection: 100%
+24
Gap (healthy → bug)
100%
Detection rate
0%
False positives
BUG-003 Anomaly Chart

Anomalies detected: 0 (healthy) → 24 (bug) → 1 (fixed)

1. The Bug

The MPS backend (Apple Silicon GPU) produces gradients that are 100x–100,000x too large. The gradients are finite (no NaN), so standard monitoring doesn't catch them — the model silently converges to wrong weights.

Upstream: pytorch#177116 — OPEN, labeled module: mps, triaged.

2. Reproduction (CPU simulation)

model = nn.Sequential(nn.Linear(8,32), nn.ReLU(), nn.Linear(32,16), nn.ReLU(), nn.Linear(16,2))
x_corrupted = torch.randn(4, 8) * 100  # simulates MPS corruption
out = model(x_corrupted); out.sum().backward()
# Gradients: ~100-100,000x too large — but still finite!

3. NeuralDBG Diagnosis

With the DeepMLP architecture (12 layers, skip connections), NeuralDBG captures 24 anomalies vs 0 in the healthy baseline:

4. Why Standard Tools Miss This

SignalTensorBoardW&BNeuralDBG
Loss NaNYesYesYes
Gradient norm spikeManualManualAuto
Gradient health transitionNoNoYes
Causal chainNoNoYes

5. End-to-End Pipeline

The full NeuralSuite closed loop works on this bug:

[1/4] Healthy: 0 anomalies
[2/4] Bug: 24 anomalies (DETECTED, gap +24)
      Chain: data_anomaly → gradient[exploding] → optimizer[diverging]
[3/4] Fix: normal data restored
[4/4] Validate: 1 anomaly (RESOLVED)
VERDICT: PASS

Causal Chain

graph LR A["data_anomaly
LayerNorm_0
[distribution_shift]"] -->|"Temporal(0)
conf=0.80"| B["gradient_health
Linear_head
[exploding]"] B -->|"Temporal(2)
conf=0.70"| C["optimizer_instability
optimizer
[diverging]"] style A fill:#a371f7,stroke:#a371f7,color:#fff style B fill:#f85149,stroke:#f85149,color:#fff style C fill:#d29922,stroke:#d29922,color:#fff

Detection Metrics

PhaseAnomaliesEventsStatus
Healthy baseline046Clean
Bug injected2470Detected
After fix146Resolved
Key insight: Gradients can be wrong but finite — invisible to NaN-based monitoring. NeuralDBG catches the NORMAL→EXPLODING state transition before NaN appears.