3.2.14 · D5Training Deep Networks

Question bank — Gradient clipping

1,277 words6 min readBack to topic

Before we start, one shared vocabulary so nothing is used before it's earned:


True or false — justify

TF1. "Gradient clipping changes the loss function the network is minimizing."
False — it only edits the update step (). The loss and the model are untouched; you're just refusing to take an oversized step.
TF2. "Clip-by-norm changes the direction of the gradient."
False — it multiplies the entire vector by a single positive scalar . Scaling by one number rotates nothing; only the length shrinks.
TF3. "Clip-by-value always leaves the direction unchanged."
False — clamping components independently changes their ratios. turns a arrow into , a genuinely different direction.
TF4. "If , clip-by-norm returns exactly ."
True — then , so and . Safe gradients are never distorted.
TF5. "Gradient clipping can rescue vanishing gradients."
False — the can only pick a factor , so clipping shrinks large arrows and never grows small ones. Vanishing needs better init, gating, or residual paths.
TF6. "After clip-by-norm in Case 2, the new norm is exactly ."
True — with , so . It lands precisely on the leash, not below.
TF7. "Clipping and lowering the learning rate are interchangeable."
False — a lower shrinks every step uniformly, including good ones; clipping only touches the rare spikes. Clipping preserves fast learning on normal batches.
TF8. "Clip-by-value with bound guarantees ."
False — each component is , but the whole vector can be longer. has norm ; per-coordinate bounds don't bound the length.
TF9. "Global-norm clipping and per-layer clipping give the same update."
False — global uses one norm over all params, keeping inter-layer proportions; per-layer rescales each block differently, distorting the overall direction.
TF10. "Clipping is only ever needed for RNNs."
False — it's near-mandatory for RNNs/LSTMs and helps BPTT, but also stabilizes Transformers and GANs wherever the loss has cliffs.

Spot the error

SE1. "Set to be maximally safe from explosions."
The error is over-clipping: a tiny clips almost every step, effectively throttling the learning rate and stalling training. Clip only occasional spikes, not the norm.
SE2. "Clip after the optimizer update so the weights are already clean."
Wrong order — clipping edits the gradient, so it must run after backprop, before the optimizer step. Post-update there's no gradient left to clip.
SE3. "With Adam, clip the moment estimates , not the raw gradient."
The standard placement clips the raw gradient before Adam's moments are computed (clip_grad_norm_). Clipping the moments mixes clipping into an already-smoothed quantity.
SE4. ", , clip-by-value gives a shorter, safe gradient."
It gives whose norm is not below , and the direction flipped from to . Clip-by-value here neither shortens enough nor preserves direction.
SE5. "The clip factor can be applied unconditionally, no needed."
Then a safe gradient with would be amplified by , injecting instability. The is what guarantees "shrink-only".
SE6. "Batch Normalization removes any need for clipping."
Batch Normalization tames activation scales but doesn't cap the rare gradient cliff spike in recurrent unrolls; the two address different failure modes and often coexist.

Why questions

WHY1. Why keep the gradient's direction but not its magnitude near a cliff?
At a cliff the local linear approximation breaks down, so the size of becomes unreliable, but which way is downhill is still roughly right — so we trust direction and cap length.
WHY2. Why a global norm rather than clipping each parameter?
One shared factor keeps the relative gradient sizes between layers intact, preserving the true steepest-descent direction; per-layer factors would warp it.
WHY3. Why does the collapse two cases into one formula?
For it selects (do nothing); for it selects (shrink). Both the "safe" and "too big" branches fall out of a single expression.
WHY4. Why do exploding gradients cause NaN loss?
A huge step overshoots the valley into a higher-loss region, whose even-bigger gradient overshoots further — a runaway that overflows floating point into Inf/NaN.
WHY5. Why does depth make explosions likely?
Backprop multiplies per-layer Jacobians; if their typical singular value exceeds , the product grows like a geometric series in depth (, ), blowing up. See Exploding and vanishing gradients.
WHY6. Why is watching the unclipped gradient-norm histogram the right way to pick ?
It shows what the norms actually look like, so you can set above the bulk and below the rare spikes — clipping the tail, not the body.

Edge cases

EC1. " (all zeros), clip-by-norm — what happens?"
, so conceptually picks and . In code the short-circuits so you never divide by zero; a zero gradient stays zero.
EC2. " exactly — clip or not?"
On the boundary , so returns and is unchanged. Clipping only bites strictly above the threshold.
EC3. "A single component is huge but the norm is still ."
Clip-by-norm does nothing (norm is under the leash), even though one coordinate is large. If you need a hard per-coordinate cap, that's the specific job of clip-by-value.
EC4. "Every component equals exactly under clip-by-value."
Each is on its own boundary, so clip-by-value leaves them all unchanged — but the resulting norm can be large ( for components), which clip-by-value never controls.
EC5. "Gradient is safe on every step for the whole run — is clipping doing anything?"
No effective change: every step picks factor . That's a sign may be set high (harmless) — clipping is a dormant safety leash that only activates on spikes.
EC6. "Two layers, one with tiny gradients, one with huge — clip-by-norm applied globally."
The single global factor shrinks both proportionally, so the tiny layer's already-small gradient gets even smaller. This is accepted because preserving direction matters more; if it's a problem, the real fix is architecture/init, not per-layer clipping.

Connections