Model and Inference EngineeringTraining execution and recoveryStaff
Why must loss-scaled gradients be unscaled before norm clipping?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An fp16 training loop scales loss by 1,024, accumulates a true gradient norm of 2, clips the stored scaled gradients to norm 1, and then calls GradScaler.step. Calculate the effective norm and explain the correct order. Include accumulation, nonfinite gradients, sharded global norms and why this diagnosis may not apply to bf16 without loss scaling.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Look at whether clipping happens before or after gradient unscaling. In a common fp16 AMP setup, the trainer multiplies loss by a scale S before backpropagation to avoid tiny gradients underflowing. The resulting .grad values are scaled too. If the code clips those values to norm one and then GradScaler divides by S, the unscaled gradient can have norm about 1/S, not one. That changes the intended gradient bound. The effect on parameter movement depends on the optimizer and its history. PyTorch's AMP examples explicitly call scaler.unscale_(optimizer) before gradient inspection or clipping.
Use a simple number check. Let the true accumulated gradient norm be 2, and the loss scale be 1024. Its scaled norm is 2048. Clipping that to 1 and then unscaling leaves norm about 0.00098. Correct ordering unscales to norm 2, then clips to 1. This illustration assumes ordinary global norm clipping and no other gradient transforms. It is worth measuring the real values because a changing loss scale can make the symptom intermittent.
The safe order for this setup is accumulate all intended microbatches, unscale once for the optimizer, inspect nonfinite values, clip the unscaled gradients, then let the scaler decide whether to execute the optimizer step and update its scale. Do not unscale in the middle of accumulation and keep adding scaled gradients afterward. Log the scale, norm before and after clipping, skipped-step count and parameter delta. Compare a small deterministic update to a full-precision baseline where possible.
What if the model uses bf16 and no loss scaler? Then this specific explanation may not apply. Ask which precision path and scaler are actually active. The gradient norm is clipped on every microbatch. Why is the accumulated norm still too large? covers clipping each microbatch before accumulation and Every FSDP rank clipped its gradients. Why was the global update still too large? covers clipping each shard independently. Here the completed gradient is clipped at the right time in the batch, but in the wrong units.
The clipping bound is expressed in the units of the real gradient. With scale 1,024, a threshold of 1 applied to stored gradients is effectively a threshold of 1/1,024 on the unscaled vector. This is a gradient-norm bound, not a guarantee that Adam’s parameter displacement has that same norm. Its moving averages and normalization introduce another transformation after clipping.
A trace for one update should contain both the scaled norm and the norm after unscale, with labels stating which is which. Compare the clipping coefficient with an independent reference using the final accumulated gradient. If the unscaled norm is already below the limit, clipping should leave it unchanged apart from numerical effects. Also include a deliberately nonfinite gradient and verify that the configured scaler/optimizer path skips unsafe updates rather than treating a clipped value as healthy.
For sharded training, apply the supported full-model norm operation after unscale. Clipping each shard independently can produce another error even when scale handling is correct. With multiple optimizers, unscale the gradients owned by each optimizer according to its step contract and avoid applying the operation twice to the same optimizer in one update. A successful loss decrease over several batches is weaker evidence than showing the intended gradient and parameter delta for one controlled step.
For plain SGD without momentum, the parameter change scales directly with this gradient, so the illustrative ordering error shrinks its update by about 1,024. Adam can partially or largely cancel uniform gradient scaling through its moment normalization, depending on history, epsilon and changing scales. The clipping-order bug is real in either case, but poor learning requires checking the observed optimizer updates rather than inferring them solely from the gradient norm.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux