Exercises — Gradient clipping
Quick reference for everything below:
Level 1 — Recognition
Exercise 1.1 (L1)
State, without computing anything, whether each gradient gets modified by clip-by-norm with threshold : (a) (b) (c) .
Recall Solution 1.1
WHAT: compare to . WHY: the rule modifies only when (strictly).
- (a) → unchanged (factor ).
- (b) → unchanged (factor ). Exactly on the leash counts as safe.
- (c) → shrunk by .
Exercise 1.2 (L1)
Which flavor of clipping preserves the gradient's direction in general: clip-by-norm or clip-by-value?
Recall Solution 1.2
Clip-by-norm. It multiplies the whole vector by one scalar , so points the same way. Clip-by-value clamps each coordinate separately, changing component ratios, so it can rotate the arrow. Mnemonic: Norm = Nice direction; Value = Violates direction.
Exercise 1.3 (L1)
Where in the training pipeline is clipping applied? Choose: (A) inside the loss function, (B) after backprop, before the optimizer step, (C) after the optimizer step.
Recall Solution 1.3
(B). Backprop produces the raw gradient; clip it, then hand the clipped gradient to the optimizer. It never touches the loss or the model itself.
Level 2 — Application
Exercise 2.1 (L2)
Clip-by-norm. , . Find and verify .
Recall Solution 2.1
WHAT: norm first. . WHY: need to know if . Since : . WHY: Case 2 shrink factor. . Check: . ✓
Exercise 2.2 (L2)
Same vector , but now clip-by-value with . Find and its norm. Did the direction change?
Recall Solution 2.2
WHAT: clamp each coordinate into . , . So . Norm — note this is still larger than 5! Value-clipping does not bound the norm. Direction: original ratio ; new ratio . Direction changed. See the figure below.

Exercise 2.3 (L2)
Clip-by-norm. , . Find .
Recall Solution 2.3
. Since : . . Check: . ✓
Exercise 2.4 (L2)
Clip-by-norm with leaves unchanged. What can you conclude about ?
Recall Solution 2.4
Unchanged means , i.e. , which requires , i.e. . So the norm is at most 3.
Level 3 — Analysis
Exercise 3.1 (L3)
A step is with learning rate . Before clipping, . With clip-by-norm , what is the length of the actual weight step ? Compare to the unclipped step length.
Recall Solution 3.1
WHAT: after clipping, (since it lands exactly on the leash). Step length . Unclipped: . Analysis: clipping cut the step from down to — a reduction — while keeping the same direction. That -length leap is exactly the "fly off the cliff" jump clipping prevents.
Exercise 3.2 (L3)
Two layers have gradient blocks (norm ) and (norm ), stacked into one global vector . Global clip-by-norm with . By what factor is each block scaled, and what are the two new block norms? Why is using the global norm important here?
Recall Solution 3.2
WHAT: global norm . Since : . Both blocks are scaled by the same : new norms and . Check total: . ✓ WHY global: one shared keeps the between-layer ratio intact (). Clipping each layer to its own budget would destroy that ratio and change the true descent direction.
Exercise 3.3 (L3)
Explain in one line why gradient clipping cannot cure vanishing gradients.
Recall Solution 3.3
The factor is always : it can only shrink or leave unchanged. It has no mechanism to grow a tiny gradient, and vanishing = tiny gradients. Cure requires architecture — see Exploding and vanishing gradients, gating in Recurrent Neural Networks, and Weight initialization.
Level 4 — Synthesis
Exercise 4.1 (L4)
Design a threshold. Over 5 batches the observed unclipped gradient norms are: You want clipping to fire on the rare spike only, not on normal steps. Pick a reasonable , state which batches get clipped under your choice, and justify.
Recall Solution 4.1
WHAT: find a above the "normal" cluster but below the spike. Normal norms sit around –; the spike is . A choice like sits comfortably above the cluster. Which fire: only batch 4 (). Batches with norms are all → untouched. Justify: the whole point is to clip only the occasional cliff, not throttle every step. clips ... actually only the single true outlier fires, which is exactly the desired rare-spike behavior. Any roughly in works; too small (e.g. ) would clip batches 1,3,4 (the norm exceeds 1 there), needlessly capping normal learning.
Exercise 4.2 (L4)
You clip-by-norm with , and after clipping the update still diverges (loss → NaN). Give two distinct plausible causes and a fix for each. (Use vault topics.)
Recall Solution 4.2
Cause A — learning rate too high. Even a leashed step can be too big if is large. Fix: lower or use an adaptive optimizer, see Optimizers - SGD Adam RMSProp.
Cause B — clip applied in the wrong place. With Adam, clipping after the moment estimates (instead of on raw grads) can let a spike corrupt the running moments first. Fix: clip raw gradients before the optimizer's moment update (standard clip_grad_norm_ placement).
(Bonus cause: pathological loss geometry — a true cliff — analyzed via Loss landscapes and cliffs; stabilize with Batch Normalization or better Weight initialization.)
Level 5 — Mastery
Exercise 5.1 (L5)
Prove that after clip-by-norm, the output norm satisfies for all cases, including . Handle the zero gradient explicitly.
Recall Solution 5.1
Let . Case : , so since . ✓ Case : factor is (because ), so and . ✓ Case (zero gradient): . The formula's is undefined, but any finite scaling of is ; implementations guard with or a branch, giving . Then . ✓ All cases give .
Exercise 5.2 (L5)
Show that clip-by-norm equals clip-by-value only in a special case, and characterize it. (Hint: think about a single coordinate.)
Recall Solution 5.2
Clip-by-value clamps coordinates independently; clip-by-norm scales all coordinates by the same . For the two outputs to be identical, the value-clip must be a uniform scalar multiple of .
- 1-D case: with a single component , direction is trivially preserved. Value-clip gives ; norm-clip with gives — identical. So in 1-D they always coincide (with ).
- Higher-D: they coincide iff no coordinate is clipped, i.e. and ; then both are the identity. Otherwise value-clip changes ratios while norm-clip preserves them, so they differ. Characterization: equal exactly when either (i) the gradient is 1-dimensional, or (ii) no clipping is needed at all.
Exercise 5.3 (L5)
Let be a -dimensional vector with all equal positive components . Clip-by-norm with threshold . Show the per-coordinate result and find the value of at which a single coordinate first exceeds a value-clip bound . Take .
Recall Solution 5.3
. If , factor , so each clipped coordinate is With : (whenever , i.e. ). Compare to a value bound : a single norm-clipped coordinate is always for , so norm-clipping keeps every coordinate under the value bound automatically here. The unclipped coordinate never reaches , so value-clip alone would never fire for this vector even as — yet the norm . This is the sharpest illustration that value-clipping does not control the norm. Sanity at : , exactly on the leash, , unchanged. ✓
Connections
- Exploding and vanishing gradients
- Backpropagation through time
- Recurrent Neural Networks
- Optimizers - SGD Adam RMSProp
- Weight initialization
- Batch Normalization
- Loss landscapes and cliffs