Summary
Global-norm clipping shortens a finite gradient by one common factor, preserving its direction when the factor is positive. For threshold , use , leaving a zero vector unchanged. This caps the gradient norm, not every optimizer’s eventual update.
The fixture has , norm ten, and threshold five. Scaling by one-half produces with norm five. Ordinary SGD with learning rate moves by , norm .
Learning objective
Shorten the whole gradient vector without changing its direction
Derivation
Does clipping rotate this gradient toward an axis?
Among vectors inside the radius- Euclidean ball, radial projection minimizes distance to . Cauchy-Schwarz makes the nearest nonzero candidate parallel to ; its permitted length is . This geometric guarantee neither diagnoses a loss spike nor makes a nonfinite gradient usable. Check finiteness before stepping; infinity multiplied by zero does not produce a repaired direction.
Two flavors
Global-norm clipping (the standard)
Compute the norm over the declared optimizer parameter set after its intended accumulation and synchronization:
Use that same factor for every included tensor. For sharded gradients, aggregate squared norms over unique shards; replicated data-parallel copies are not additional parameter coordinates.
Per-parameter clipping
Separate tensor caps change relative scaling and generally rotate the concatenated gradient.
Value clipping
Coordinate clipping to turns into , with norm and a different direction. That is a coordinate bound, not the radius-five constraint.
How to pick the threshold
Log the preclip norm, nonfinite frequency, clipping frequency, and actual optimizer update norm. Threshold units depend on loss reduction, parameterization, and batch accumulation. Rare clipping may be an intentional safety limit; frequent clipping warrants checking the intended learning-rate and loss-scale interaction. Validate a threshold against the training objective rather than treating an architecture-wide number as universal.
Combined with mixed precision
If loss scaling is used, finish accumulation and unscale once before clipping. Otherwise the threshold applies to scaled units; dividing afterward changes the effective cap. BF16 frequently runs without a loss scaler; format choice alone does not imply one.
Change the Requirement
Bound Parameter Movement
New task: Cap the final optimizer displacement rather than its input gradient.
Picture and change: Inspect momentum, preconditioning, learning rate, and decay before choosing an update-level constraint.
Check: With velocity and rule , the fixture gives , not a norm-five update.
Use when: The requirement concerns actual parameter movement. The bound applies to ordinary SGD without those additional transformations.
Accumulate Before Clipping
New task: Combine several microbatches into one optimizer step under a declared summed-loss convention.
Picture and change: Sum contributions first, then clip the combined gradient.
Check: Scalar contributions and sum to ; clipping each to five before adding instead gives zero.
Use when: Multiple backward calls represent one update. For mean loss, apply the correct sample-count normalization; averaging unequal batch means defines a different gradient.
Common pitfalls
- Wrong constrained object. Tensor, coordinate, example, gradient, and update clipping solve different problems.
- Wrong units. Unscale before measuring the threshold when using AMP scaling.
- Invalid directions. Skip or diagnose nonfinite gradients; do not expect a norm projection to repair them.
- Missing diagnosis. Repeated large gradients can reflect data, initialization, objective, or numerical issues; clipping alone identifies none.
Reconstruct
Does threshold one bound every AdamW step by its learning rate?
No. Saved moments, coordinate scaling, and decoupled decay also contribute to parameter movement. The ordinary-SGD bound cannot be transferred without inspecting the actual update rule.