RMSNorm Variance Overflow in FP16
In RMSNorm, the sum of squared activations is computed. In large models (e.g., hidden dimension > 4096), summing the squares of fp16 activations can easily exceed 65,504 (the maximum fp16 value), causing an overflow to infinity. The subsequent step computes `1.0 / sqrt(inf)`, which results in 0. The activations are zeroed out, killing gradients and causing NaNs upon backpropagation.
In RMSNorm, the sum of squared activations is computed.
- Root cause
- In RMSNorm, the sum of squared activations is computed. In large models (e.g.
- Recommended fix
- Cast to FP32 for Variance Calculation variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True) Casting the activations to fp32 before squaring and summing prevents the intermediate sum from overflowing, returning a safe fp16 value upon downcast.
- How Denpex helps
- Denpex investigates RMSNorm Variance Overflow in FP16 using the evidence you provide or your connected workload collects. Earlier rank, host or application evidence is needed to distinguish an initiating failure from a downstream report.
What this failure is
RMSNorm Variance Overflow in FP16 is a Model failure seen during ML training runs. In RMSNorm, the sum of squared activations is computed. In large models (e.g., hidden dimension > 4096), summing the squares of fp16 activations can easily exceed 65,504 (the maximum fp16 value), causing an overflow to infinity. The subsequent step computes `1.0 / sqrt(inf)`, which results in 0. The activations are zeroed out, killing gradients and causing NaNs upon backpropagation. Common tags: Numerical Instability.
Is this what broke your run? Paste your log.
You're reading about RMSNorm Variance Overflow in FP16. Paste your own traceback and relevant evidence for an investigation of your workload, with a next action or a specific missing fact. A reference entry does not establish your cause. No account or card for the free diagnosis. Review data handling before submitting sensitive logs.
Before uploading, review cloud data handling and local options.
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
Why it happens (the mechanism)
It appears as a standard exploding gradient issue, leading developers to aggressively tune learning rates or initialization, when in fact it is a deterministic precision limit.
What you'll observe
- Loss is NaN at step 0
- Gradients containing NaNs in LayerNorm/RMSNorm
Common symptoms and what they mean
| Symptom | Why it happens |
|---|---|
| Model loss becomes NaN almost immediately at the start of training or unexpectedly during training. | In RMSNorm, the sum of squared activations is computed. In large models (e.g., hidden dimension > 4096), summing the squares of fp16 activations can easily exceed 65,504 (the maximum fp16 value), causing an overflow to infinity. The subsequent step computes `1.0 / sqrt(inf)`, which results in 0. The activations are zeroed out, killing gradients and causing NaNs upon backpropagation. |
| Activations following the RMSNorm layer are mostly zeros or NaNs. | In RMSNorm, the sum of squared activations is computed. In large models (e.g., hidden dimension > 4096), summing the squares of fp16 activations can easily exceed 65,504 (the maximum fp16 value), causing an overflow to infinity. The subsequent step computes `1.0 / sqrt(inf)`, which results in 0. The activations are zeroed out, killing gradients and causing NaNs upon backpropagation. |
Which systems are affected
- PyTorch
- LLaMA
- Custom Transformers
How to confirm this is the problem
Use this checklist to test the hypothesis against a small reproduction. No single line proves the root cause, so preserve the preceding events and compare one variable at a time.
- ✓Check if hidden dimensions are extremely large.
- ✓Log the intermediate `sum(x**2)` inside the RMSNorm layer to see if it hits `inf`.
Root cause
- In RMSNorm, the sum of squared activations is computed. In large models (e.g., hidden dimension > 4096), summing the squares of fp16 activations can easily exceed 65,504 (the maximum fp16 value), causing an overflow to infinity. The subsequent step computes `1.0 / sqrt(inf)`, which results in 0. The activations are zeroed out, killing gradients and causing NaNs upon backpropagation.
The fix and how to prevent it
The fix and the prevention pattern
The root cause is on this page and stays free. A free account adds the exact remediation steps, saved history, and the fix on every entry in the encyclopedia.
Sign up free. Unlock the full analysisNo credit card. Daily allowance follows verified trust tier. Instant access.
Diagnose this failure in VS Code
Select the traceback or open the failed terminal, then run Denpex locally to see the initiating rank, collateral failures, exact fix, and verification command without uploading the log.
Install the free VS Code extensionReferences
Don't just read the fix, diagnose your run
The encyclopedia tells you what went wrong. Denpex tells you what went wrong in YOUR training run. With your logs, your config, and your stack.