Skip to content

DistributedDataParallel raises an internal reducer assertion when a backward pass arrives unexpectedly

DDP's gradient reducer arms itself for exactly one backward pass per forward and disarms once that pass is finalised. A second backward, or a backward whose forward was run under a different synchronisation context, arrives when the reducer is not armed and trips an internal assertion whose text invites you to file a PyTorch bug.

Quick answer

Count your backward calls: DDP expects exactly one per forward. Disable static_graph to confirm, use non-reentrant gradient checkpointing, and keep each forward and its backward inside the same no_sync context.

Symptom
[rank0]: RuntimeError: expect_autograd_hooks_ INTERNAL ASSERT FAILED at "../torch/csrc/distributed/c10d/reducer.cpp":1603, please report a bug to PyTorch.
Root cause
The reducer keeps a flag saying a backward pass is expected. DDP sets it when it prepares for backward and clears it when that pass is finalised, and the assertion fires when hooks arrive while the flag is clear. The condition is therefore about counting and ordering, not about the values in any tensor.
Recommended fix
Ensure exactly one backward call per DDP forward. Where several losses exist, sum them into one scalar and call backward once rather than backwarding each tensor.
How Denpex helps
Denpex investigates DistributedDataParallel raises an internal reducer assertion when a backward pass arrives unexpectedly 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.
Distributed Training#ddp#distributeddataparallel#reducer#static_graph#gradient-checkpointing#no_sync

What this failure is

An internal assertion in DDP's gradient reducer raised when autograd hooks fire while the reducer is not armed for a backward pass, caused by backward counting or synchronisation-context mismatches rather than by a defect in PyTorch.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about DistributedDataParallel raises an internal reducer assertion when a backward pass arrives unexpectedly. 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 cloud diagnoses per day

Why it happens (the mechanism)

DDP overlaps gradient reduction with backward computation by attaching hooks to parameters and reducing buckets as they fill. That only works if it knows when a backward begins and ends, so it arms itself before one and disarms after. Anything that produces an extra backward, or that moves a backward relative to the forward it belongs to, breaks the bookkeeping rather than the mathematics, and the assertion is the bookkeeping noticing.

What you'll observe

  • The error asks you to report a bug to PyTorch, which is almost never the right response
  • The same model trains correctly on a single GPU and only fails once wrapped in DDP
  • It appears after enabling gradient checkpointing or a static graph, neither of which mentions backward counting
  • The traceback points into C++ reducer internals with no application frame to act on

Common symptoms and what they mean

Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.

SymptomPossible explanation
RuntimeError: expect_autograd_hooks_ INTERNAL ASSERT FAILED at ../torch/csrc/distributed/c10d/reducer.cppThe reducer keeps a flag saying a backward pass is expected. DDP sets it when it prepares for backward and clears it when that pass is finalised, and the assertion fires when hooks arrive while the flag is clear. The condition is therefore about counting and ordering, not about the values in any tensor.
please report a bug to PyTorch appended to the assertion textStatic graph tightens the contract: it promises the same graph and exactly one backward per iteration so the reducer can precompute its bucket order. A second backward, or a backward on a second returned tensor, then reaches a reducer that has already finalised and is no longer expecting anything.
The failure appearing only when the model is wrapped in DistributedDataParallelGradient checkpointing conflicts by re-running the forward during backward, which can fire the same hooks twice. Its reentrant implementation is the one that does this; the non-reentrant implementation exists partly to be compatible with hook-based systems like DDP.
Onset coinciding with enabling static_graph or gradient checkpointing rather than with a model changeUsing no_sync incorrectly desynchronises the same flag. If a forward runs inside the context and its backward outside it, or the reverse, the reducer's expectation and the actual sequence diverge and the assertion is how that divergence surfaces.

Which systems are affected

  • DDP with static_graph enabled, which assumes one unchanging backward per iteration
  • Gradient checkpointing under DDP, where the forward is re-run during backward and can re-fire hooks
  • Gradient accumulation using no_sync, where a forward and its backward can end up on opposite sides of the context
  • Models returning several tensors that are each backwarded separately

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.

  • ✓Count backward calls per forward in the training step. More than one against the DDP-wrapped module is the condition the assertion describes.
  • ✓Disable static_graph and re-run. Success identifies the strict contract as the trigger even when the underlying pattern is what needs changing.
  • ✓Disable gradient checkpointing and re-run. Working with one of the two enabled but not both is the signature of the reentrant checkpointing conflict.

Root cause

  • The reducer keeps a flag saying a backward pass is expected. DDP sets it when it prepares for backward and clears it when that pass is finalised, and the assertion fires when hooks arrive while the flag is clear. The condition is therefore about counting and ordering, not about the values in any tensor.
  • Static graph tightens the contract: it promises the same graph and exactly one backward per iteration so the reducer can precompute its bucket order. A second backward, or a backward on a second returned tensor, then reaches a reducer that has already finalised and is no longer expecting anything.
  • Gradient checkpointing conflicts by re-running the forward during backward, which can fire the same hooks twice. Its reentrant implementation is the one that does this; the non-reentrant implementation exists partly to be compatible with hook-based systems like DDP.
  • Using no_sync incorrectly desynchronises the same flag. If a forward runs inside the context and its backward outside it, or the reverse, the reducer's expectation and the actual sequence diverge and the assertion is how that divergence surfaces.

The fix and how to prevent it

How to fix it

  • Ensure exactly one backward call per DDP forward. Where several losses exist, sum them into one scalar and call backward once rather than backwarding each tensor.
  • Turn off static_graph first when diagnosing. It is the strictest contract and the most common thing to have enabled without realising what it promises.
  • Pass the non-reentrant option to gradient checkpointing, which is the implementation compatible with DDP's hooks, when checkpointing and DDP must be combined.
  • Keep each forward and its matching backward on the same side of a no_sync context, and check accumulation loops where the boundary can drift by one step.
  • Where several independent backward passes are genuinely required, run them against the unwrapped module and handle gradient reduction explicitly rather than fighting the reducer.
  • Read the instruction to report a bug as boilerplate attached to every internal assertion, not as a diagnosis; the trigger is almost always one of the usage patterns above.

Step-by-step remediation

  1. 1Instrument the training step and confirm exactly one backward call per DDP forward.
  2. 2Set static_graph to false and re-run to confirm it is the trigger.
  3. 3Pass the non-reentrant option to gradient checkpointing if it is enabled.
  4. 4Ensure each forward and its matching backward are both inside or both outside the context.
  5. 5Run them against the unwrapped module and reduce gradients explicitly.

How to prevent it

  • Introduce static_graph and gradient checkpointing one at a time, so an assertion can be attributed to whichever was added.
  • Assert one backward per iteration in the training loop while developing, which turns a confusing C++ assertion into a local failure with a stack you own.
  • Review accumulation loops for off-by-one boundaries whenever the accumulation factor or the batch schedule changes.

Save this diagnosis and catch the next crash automatically

All root cause, fix, and prevention steps above are free to read. Create a free account with any email or GitHub to keep your saved diagnosis history across the encyclopedia and run cloud checks, or use a work email below for the 30-day Team evaluation. No card required.

Or start a 30-day free Team trial (work email)

Verified work email unlocks all 14 fleet diagnostic tools, Slack alerts, and team history for 30 days. No card and no automatic charge.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.
Already have an account? Sign in

Searchable error signature

search key
[rank0]: RuntimeError: expect_autograd_hooks_ INTERNAL ASSERT FAILED at "../torch/csrc/distributed/c10d/reducer.cpp":1603, please report a bug to PyTorch.
[rank0]: No no_sync() context - works without error

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.

Diagnose your own log automatically

The root cause and fix steps above stay free. Create a free account to analyze full job logs, attribute the first failed rank, and keep saved incident history.

Sign up free. Analyze your cluster logs

No credit card. Daily allowance follows verified trust tier. Instant access.

Why the recommended fix works

Collapsing several losses into one backward restores the one-per-forward assumption the reducer is built on. Non-reentrant checkpointing avoids re-running the forward in a way that re-fires hooks. Aligning no_sync boundaries makes the reducer's expectation and the actual sequence agree again. All three fix the sequence rather than suppressing the check.

Best practices by model family

Model / StackRecommendationNotes
Several losses from one forwardSum to one scalar, call backward onceRestores the one-backward-per-forward contract.
static_graph enabledDisable it while diagnosingIt is the strictest contract and the most common trigger.
Gradient checkpointing with DDPUse the non-reentrant implementationThe reentrant one re-runs the forward and can re-fire hooks.
Gradient accumulationKeep forward and backward on one side of no_syncA boundary that drifts by one step desynchronises the reducer.

With the fix vs without the fix

DimensionWith the fixWithout the fix
What the assertion measuresBackward count and orderingAssumed to indicate corrupted gradients
Report a bug to PyTorchBoilerplate on every internal assertRead as a diagnosis
Why single-GPU worksNo reducer, so no bookkeeping to breakTaken as evidence the model is correct under DDP

Diagnostic note

“The phrase please report a bug to PyTorch does real harm here. It is attached to every internal assertion regardless of cause, and it points people at an upstream issue tracker when the trigger is in their own training loop. Treat it as boilerplate. The genuinely useful signal is what changed immediately before: enabling static_graph, enabling checkpointing, or altering an accumulation schedule are the three that produce almost all occurrences.”

Visual fingerprint

The reducer arms once and disarms once
  forward  ->  reducer ARMED (expect_autograd_hooks_ = true)
  backward ->  buckets reduce  ->  finalize  ->  DISARMED

  second backward on the same forward:
  backward ->  hooks fire while DISARMED  ->  INTERNAL ASSERT FAILED
DDP arms the reducer when it prepares for a backward pass and disarms it once that pass is finalised. A second backward fires hooks while the reducer is disarmed, which is the condition the assertion reports.

Diagnose this failure in VS Code

Select the traceback or open the failed terminal, then run Denpex locally to inspect matched failure patterns, supporting evidence and next checks without uploading the log. Verify recommendations against your workload before changing production.

Install the free VS Code extension

PyTorch GPU errors in context

PyTorch training errors commonly originate at tensor device placement, DataLoader /dev/shm IPC, or checkpoint state restoration.

Compare related pytorch gpu errors

Frequently asked questions

Questions engineers and on-call staff commonly ask about this failure.

Should I report this to PyTorch?
Almost certainly not. That text is attached to every internal assertion. The trigger is usually multiple backward passes, reentrant gradient checkpointing, or a misplaced no_sync boundary.
It works without DDP. Is my model wrong?
The model is fine. Without DDP there is no reducer, so there is no backward-pass bookkeeping to violate.
Why did enabling static_graph cause this?
It promises the graph is unchanging and there is exactly one backward per iteration, which lets the reducer precompute bucket order. A second backward then reaches an already-finalised reducer.
Can I keep gradient checkpointing?
Yes, with the non-reentrant implementation. The reentrant one re-runs the forward during backward and can fire the same hooks twice.

Don't just read the fix, diagnose your run

The encyclopedia explains documented failure patterns. Denpex investigates your logs, configuration and stack, shows the supporting evidence, and asks for missing details when needed.