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.
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 matches Variable Sequence Length Shape Exchange Deadlock 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.
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.
Is this what broke your run? Paste your log.
You're reading about Variable Sequence Length Shape Exchange Deadlock. 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.
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.
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
| Symptom | Why 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.
Searchable error signature
Rank stalled in torch.distributed.irecvUse 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 analysisNo 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 extensionRoot 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
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.
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.