3.2.14 · D3Training Deep Networks

Worked examples — Gradient clipping

2,423 words11 min readBack to topic

Before anything, let us re-anchor the two tools in plain words so every symbol below is earned.


The scenario matrix

Every clipping problem is one of these cells. The examples below each carry a tag like (A2).

# Cell class What makes it special Covered by
A1 Norm, safe gradient → no change Ex 1
A2 Norm, exploding gradient → shrink Ex 2
A3 Norm, exactly on the leash (boundary) Ex 3
A4 Norm, negative components signs must survive scaling Ex 4
B1 Value clip, mixed signs each coord clamped to Ex 5
B2 Value vs norm on same direction distortion shown Ex 6
C1 Zero / degenerate gradient , division danger Ex 7
C2 Scalar (1-D) gradient norm = absolute value Ex 7
D1 Real-world word problem RNN loss spike, pick behaviour Ex 8
D2 Exam twist solve for the threshold Ex 9

Worked examples

Ex 1 — safe gradient, clip-by-norm (A1)

Ex 2 — exploding gradient, clip-by-norm (A2)

Figure — Gradient clipping

Look at the figure: the black arrow is the raw of length . The red arrow is — it lands exactly on the dashed circle of radius , lying along the same ray. The circle is the "leash": any raw arrow poking outside it gets pulled back onto its rim.

Ex 3 — exactly on the leash (A3)

Ex 4 — negative components survive scaling (A4)

Ex 5 — clip-by-value, mixed signs (B1)

Ex 6 — same vector, two rules, direction contrast (B2)

Figure — Gradient clipping

In the figure the black arrow is . The red arrow is the norm-clipped result sitting on the ray at length ; the grey arrow is the value-clipped — visibly rotated away from the original ray. Same start, different destinations.

Ex 7 — zero gradient & scalar gradient (degenerate) (C1, C2)

Ex 8 — real-world word problem: an RNN loss spike (D1)

Ex 9 — exam twist: solve for the threshold (D2)


Recall Rapid self-test (predict, then reveal)

Do these in your head using "same arrow, shorter arrow." , : shrink factor and result? ::: , , , length . , , clip-by-norm: result? ::: — safe branch, no division, no NaN. value-clipped at : result and did direction change? ::: ; direction , yes it changed. Clip-by-norm output length always equals what when clipping fires? ::: The threshold exactly.


Connections