Skip to content

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.

Quick answer

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 matches RMSNorm Variance Overflow in FP16 across every rank in a distributed run and reports which rank failed first, so you act on the initiating node instead of the loudest one.
Model#Numerical Instability

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.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about RMSNorm Variance Overflow in FP16. Paste your own crash log or traceback below and get the real root cause for YOUR run, not this generic entry. No account, no card. Logs are masked at ingress and never saved to account history.

training_logs.txt
No log to hand? Try one:

3 free diagnoses/day

Want 14 days on the Scale plan?

Request an evaluation code. A verified workplace organization activates up to 50 diagnoses a day, alerts, history, and follow-up questions. No credit card or automatic subscription.

Evaluate one incident

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

SymptomWhy 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`.

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 analysis

No 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 extension

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

Evaluate Denpex on your own logs

Request a Scale evaluation code. A verified workplace organization activates 14 days with up to 50 diagnoses a day. Every account keeps its current diagnosis allowance and gets a verification path. No card or automatic subscription.

We send a single-use code tied to that address. Static provider and TLD rules do not reject valid addresses. Account trust determines the benefit after signup.

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.