Skip to content

Variable Sequence Length Shape Exchange Deadlock

When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock.

Quick answer

When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next].

Symptom
Rank stalled in torch.distributed.irecv
Root cause
When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock.
Recommended fix
batch_p2p_comm=False
How Denpex helps
Denpex investigates Variable Sequence Length Shape Exchange Deadlock 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.
Network#P2P Communication

What this failure is

Variable Sequence Length Shape Exchange Deadlock is a Network failure seen during ML training runs. When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock. Common tags: P2P Communication.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about Variable Sequence Length Shape Exchange Deadlock. 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)

The hang produces no crash logs or exceptions. Engineers often assume a NCCL hardware issue or a hanging compute kernel, when it is purely a software-level logical deadlock in the P2P communication schedule.

What you'll observe

  • Process stuck in _communicate_shapes()
  • Rank stalled in torch.distributed.irecv
  • Watchdog timeout during pipeline parallel P2P communication

Common symptoms and what they mean

SymptomWhy it happens
Training hangs indefinitely on the first training step or during transition between steady-state and cooldown in the 1F1B pipeline schedule.When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock.
GPU utilization drops to 0% while processes remain active.When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock.

Which systems are affected

  • Megatron-LM
  • PyTorch Distributed
  • NCCL

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.

  • ✓Use `py-spy dump --pid <pid>` on the hanging processes and look for `_communicate_shapes()` in the stack trace.
  • ✓Check if `--variable-seq-lengths` is passed in the training arguments.
  • ✓Verify if the pipeline parallel size (PP) is >= 4.

Root cause

  • When `--variable-seq-lengths` and `batch_p2p_comm=True` are enabled with Pipeline Parallelism (PP >= 4), the `_communicate_shapes()` function enforces a strict, fixed point-to-point operation ordering: [send_prev, recv_prev, send_next, recv_next]. During the transition phases of the pipeline schedule, this strict ordering causes circular waits (Rank A waiting on Rank B, while Rank B waits on Rank A for a different operation), leading to a distributed deadlock.

The fix and how to prevent it

Searchable error signature

search key
Rank stalled in torch.distributed.irecv

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

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.