Skip to content

AdamW Epsilon Underflow in FP16

The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8. Thus, 1e-8 underflows to 0.0. During the optimizer update, this leads to a division by zero if the gradient variance estimate is also close to zero, producing NaNs.

Quick answer

The default epsilon value for Adam/AdamW is 1e-8.

Root cause
The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8.
Recommended fix
Increase AdamW epsilon to an FP16-safe value optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3, eps=1e-5) A larger epsilon like 1e-5 or 1e-4 is representable in float16, preventing division by zero during the parameter update calculation.
How Denpex helps
Denpex investigates AdamW Epsilon Underflow 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.
Optimizer#Numerical Underflow

What this failure is

AdamW Epsilon Underflow in FP16 is a Optimizer failure seen during ML training runs. The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8. Thus, 1e-8 underflows to 0.0. During the optimizer update, this leads to a division by zero if the gradient variance estimate is also close to zero, producing NaNs. Common tags: Numerical Underflow.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about AdamW Epsilon Underflow 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.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free diagnoses/day

Why it happens (the mechanism)

Engineers usually suspect exploding gradients and try to apply gradient clipping, which completely fails to fix an underflow-induced division by zero.

What you'll observe

  • Loss becomes NaN without gradient explosion
  • Optimizer state contains NaNs

Common symptoms and what they mean

SymptomWhy it happens
Gradient norm remains small and stable, but loss suddenly turns NaN.The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8. Thus, 1e-8 underflows to 0.0. During the optimizer update, this leads to a division by zero if the gradient variance estimate is also close to zero, producing NaNs.
Model crashes during the optimizer step rather than the forward/backward pass.The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8. Thus, 1e-8 underflows to 0.0. During the optimizer update, this leads to a division by zero if the gradient variance estimate is also close to zero, producing NaNs.

Which systems are affected

  • PyTorch
  • Hugging Face 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.

  • ✓Disable AMP to see if the problem disappears.
  • ✓Inspect optimizer parameters (`optimizer.param_groups[0]['eps']`).

Root cause

  • The default epsilon value for Adam/AdamW is 1e-8. In float16, the smallest representable positive normal number is ~5.96e-8. Thus, 1e-8 underflows to 0.0. During the optimizer update, this leads to a division by zero if the gradient variance estimate is also close to zero, producing NaNs.

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

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.