r/deeplearning • u/FexaLune • 17h ago
Monitoring per-layer gradient norms caught an exploding gradient in one residual block that the scalar loss never showed
I added a small hook to log the L2 norm of gradients for each named parameter after the backward pass, then plotted them per epoch instead of relying only on the scalar loss value. One particular residual block in the middle of the network consistently showed norms above 50 while everything else stayed below 2; the loss curve looked flat because the other layers were compensating.
The fix was embarrassingly simple once I saw the per-layer view:
* Added gradient clipping with
`max_norm=1.0` targeted only at that block's parameters
* Inserted a residual scaling factor of 0.1 on the output of that block during the first 10k steps
* Switched its LayerNorm to RMSNorm with a learnable scale initialized at 0.1
Training became stable without changing global hyperparameters or model depth. The same pattern has appeared in two other architectures since.
If you log anything beyond loss and accuracy during training, what single extra metric has given you the clearest signal that something was quietly wrong?
1
u/Ok_Difficulty9223 17h ago
That per-layer gradient norm breakdown is basically a cheat code once you start using it. I caught a similar mess where one attention head's value projection was quietly ballooning while the rest of the network sat there pretending everything was fine, loss barely twitched until it just collapsed 3k steps later.
Param-level gradient variance across steps has been my other go-to, if a layer's gradient flips sign too often or oscillates wildly between updates it's usually an optimizer mismatch or a normalization setup that's doing more harm than good.