Skip to content

Missing GradScaler Update in AMP Loop

When using `torch.cuda.amp.autocast()`, gradients are computed in float16. The dynamic range of float16 is narrow, causing gradients to overflow to infinity. If a `GradScaler` is not used, or if `scaler.update()` is omitted, the scale factor isn't adjusted to prevent these overflows, leading to NaN gradients and subsequently NaN loss.

Quick answer

When using `torch.

Symptom
RuntimeError: Function 'LogSoftmaxBackward' returned nan values in its 0th output
Root cause
When using `torch.cuda.amp.
Recommended fix
Wrap optimizer step and loss backward with GradScaler scaler = torch.cuda.amp.GradScaler() scaler.scale(loss).backward() scaler.step(optimizer) scaler.update() GradScaler multiplies the loss by a scale factor to prevent float16 underflow/overflow, then un-scales gradients before applying updates.
How Denpex helps
Denpex matches Missing GradScaler Update in AMP Loop 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.
Precision#Mixed Precision (AMP)

What this failure is

Missing GradScaler Update in AMP Loop is a Precision failure seen during ML training runs. When using `torch.cuda.amp.autocast()`, gradients are computed in float16. The dynamic range of float16 is narrow, causing gradients to overflow to infinity. If a `GradScaler` is not used, or if `scaler.update()` is omitted, the scale factor isn't adjusted to prevent these overflows, leading to NaN gradients and subsequently NaN loss. Common tags: Mixed Precision (AMP).

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about Missing GradScaler Update in AMP Loop. 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)

The crash often happens randomly during training, making it look like a data issue or a learning rate explosion, when it's purely a numerical precision limitation of FP16.

What you'll observe

  • Loss goes to NaN
  • RuntimeError: Function 'LogSoftmaxBackward' returned nan values in its 0th output

Common symptoms and what they mean

SymptomWhy it happens
Model trains normally for a few steps and then loss suddenly jumps to NaN.When using `torch.cuda.amp.autocast()`, gradients are computed in float16. The dynamic range of float16 is narrow, causing gradients to overflow to infinity. If a `GradScaler` is not used, or if `scaler.update()` is omitted, the scale factor isn't adjusted to prevent these overflows, leading to NaN gradients and subsequently NaN loss.
Weights become filled with NaN.When using `torch.cuda.amp.autocast()`, gradients are computed in float16. The dynamic range of float16 is narrow, causing gradients to overflow to infinity. If a `GradScaler` is not used, or if `scaler.update()` is omitted, the scale factor isn't adjusted to prevent these overflows, leading to NaN gradients and subsequently NaN loss.

Which systems are affected

  • PyTorch
  • CUDA

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 `torch.cuda.amp.autocast()` is used without `torch.cuda.amp.GradScaler()`.
  • Print `scaler.get_scale()` to see if it drops to 0 or explodes.

Searchable error signature

search key
RuntimeError: Function 'LogSoftmaxBackward' returned nan values in its 0th output

Use this text as a lookup key in logs and upstream issue trackers. It is not presented as a captured customer log. Confirm the cause from your own preceding events, versions, configuration and the cited references.

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

  • When using `torch.cuda.amp.autocast()`, gradients are computed in float16. The dynamic range of float16 is narrow, causing gradients to overflow to infinity. If a `GradScaler` is not used, or if `scaler.update()` is omitted, the scale factor isn't adjusted to prevent these overflows, leading to NaN gradients and subsequently NaN loss.

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.