Clip gradients unit-wise relative to weight norms (AGC)
Why it matters AGC let normaliser-free ResNets (NFNets) train at large batch sizes without batch norm.
Global norm clipping uses one threshold for the whole model. Adaptive gradient clipping instead compares each unit's gradient to the size of its own weights.
Write agc(W, G, clip=0.01, eps=1e-3). W and G are (out, in) arrays; each row is one output unit. For each row i, let wn = max(||W_i||, eps) and gn = ||G_i|| (L2 norms). If gn > clip * wn, scale that row of G by clip * wn / gn; otherwise leave it. Return the clipped G as a float array.
def agc(W, G, clip=0.01, eps=1e-3)Example
agc([[3, 4], [0, 0]], [[0.3, 0.4], [1, 0]], clip=0.01) is [[0.03, 0.04], [0.00001, 0]]: row 1 is cut to 1% of its weight norm 5, row 2 uses the eps floor.
Understand the idea
A gradient step is dangerous when it is large compared to the weights it changes: moving a weight of size 0.01 by 1 wrecks it, moving a weight of size 100 by 1 barely matters. Adaptive clipping caps each unit's update at a small fraction of that unit's own weight size. Like a pay rise capped at a percentage of current salary rather than a fixed amount.
Tiny example: row weights [3, 4] have norm 5. With clip 0.01 the limit is 0.05. The gradient [0.3, 0.4] has norm 0.5, ten times too big, so it is scaled by 0.1 to [0.03, 0.04].
Rule: limit_i = clip * max(||W_i||, eps); if ||G_i|| > limit_i then G_i *= limit_i / ||G_i||.
It is the key trick in normaliser-free networks and is also tried for stabilising large-batch transformer training.
Shapes and data flow
W, G (out, in); row norms (out, 1); scale broadcasts across in