DeepSpeed MoE + ZeRO-3 Hang. Missing Leaf Module Marking
DeepSpeed ZeRO-3 with Mixture-of-Experts (MoE) models hangs during training because MoE blocks need to be marked as leaf modules for ZeRO-3 parameter gathering. Without this marking, ZeRO-3 attempts to gather parameters recursively through the MoE router, causing deadlocks. Denpex detects the MoE+ZeRO-3 hang pattern and recommends the leaf module fix.
DeepSpeed ZeRO-3 with Mixture-of-Experts (MoE) models hangs during training because MoE blocks need to be marked as leaf modules for ZeRO-3 parameter gathering.
- Symptom
nvidia-smi shows 0% GPU utilization on all ranks during the hang- Root cause
- ZeRO-3 parameter gathering traverses the model hierarchy recursively, entering MoE router logic during the gather phase. MoE routers have conditional parameter access (only active experts per token), which creates deadlocks when ZeRO-3 tries to gather all expert parameters simultaneously. Without leaf module marking, ZeRO-3 doesn't know to treat MoE blocks as atomic units that should not be recursively decomposed.
- Recommended fix
- Mark MoE blocks as leaf modules: deepspeed.zero.set_z3_leaf_modules(model, [MoEBlockClass])
- How Denpex helps
- Denpex investigates DeepSpeed MoE + ZeRO-3 Hang. Missing Leaf Module Marking 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.
What this failure is
DeepSpeed MoE + ZeRO-3 Hang. Missing Leaf Module Marking is a Distributed Training failure seen during ML training runs. DeepSpeed ZeRO-3 with Mixture-of-Experts (MoE) models hangs during training because MoE blocks need to be marked as leaf modules for ZeRO-3 parameter gathering. Without this marking, ZeRO-3 attempts to gather parameters recursively through the MoE router, causing deadlocks. Denpex detects the MoE+ZeRO-3 hang pattern and recommends the leaf module fix. Common tags: Deepspeed, Moe, Zero3, Leaf Module.
Is this what broke your run? Paste your log.
You're reading about DeepSpeed MoE + ZeRO-3 Hang. Missing Leaf Module Marking. 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.
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
Why it happens (the mechanism)
ZeRO-3 parameter gathering traverses the model hierarchy recursively, entering MoE router logic during the gather phase. MoE routers have conditional parameter access (only active experts per token), which creates deadlocks when ZeRO-3 tries to gather all expert parameters simultaneously. Without leaf module marking, ZeRO-3 doesn't know to treat MoE blocks as atomic units that should not be recursively decomposed. The hang occurs because rank 0 is waiting for rank 1's expert parameters while rank 1 is stuck in the MoE router. Taken together, these mechanisms explain why the failure is reproducible, why it tends to surface on specific workloads or scales, and why generic mitigation attempts often fall short without addressing the underlying cause.
What you'll observe
- Training with DeepSpeed ZeRO-3 and MoE models hangs at the first forward pass
- NCCL timeout occurs during parameter gathering for MoE layers
- The hang is specific to MoE models. Non-MoE models with the same ZeRO-3 config work fine
Common symptoms and what they mean
Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.
| Symptom | Possible explanation |
|---|---|
| Training hangs with NCCL timeout during the first forward pass through MoE layers | ZeRO-3 parameter gathering traverses the model hierarchy recursively, entering MoE router logic during the gather phase |
| nvidia-smi shows 0% GPU utilization on all ranks during the hang | MoE routers have conditional parameter access (only active experts per token), which creates deadlocks when ZeRO-3 tries to gather all expert parameters simultaneously |
| DeepSpeed logs show parameter gathering initiated but never completing for MoE parameters | Without leaf module marking, ZeRO-3 doesn't know to treat MoE blocks as atomic units that should not be recursively decomposed |
| No error output. The job just hangs indefinitely | The hang occurs because rank 0 is waiting for rank 1's expert parameters while rank 1 is stuck in the MoE router |
Which systems are affected
- DeepSpeed ZeRO-3 with Mixture-of-Experts models (Mixtral, Switch Transformer, etc.)
- DeepSpeed with expert-parallel training
- Models using Megablocks or ScatterMoE with DeepSpeed ZeRO-3
- DeepSpeed versions before v0.14.0
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.
- ✓Reproduce the failure from a clean checkpoint/seed: the symptom must appear without warm-up state from a previous run.
- ✓Verified signal present: Training hangs with NCCL timeout during the first forward pass through MoE layers
- ✓Verified signal present: nvidia-smi shows 0% GPU utilization on all ranks during the hang
- ✓Verified signal present: DeepSpeed logs show parameter gathering initiated but never completing for MoE parameters
- ✓Verified signal present: No error output. The job just hangs indefinitely
- ✓A targeted fix from the "How to fix it" section eliminates or substantially reduces the symptom within one validation pass.
Root cause
- ZeRO-3 parameter gathering traverses the model hierarchy recursively, entering MoE router logic during the gather phase
- MoE routers have conditional parameter access (only active experts per token), which creates deadlocks when ZeRO-3 tries to gather all expert parameters simultaneously
- Without leaf module marking, ZeRO-3 doesn't know to treat MoE blocks as atomic units that should not be recursively decomposed
- The hang occurs because rank 0 is waiting for rank 1's expert parameters while rank 1 is stuck in the MoE router
The fix and how to prevent it
How to fix it
- Mark MoE blocks as leaf modules: deepspeed.zero.set_z3_leaf_modules(model, [MoEBlockClass])
- Upgrade DeepSpeed to v0.14.0+ which has better MoE+ZeRO-3 integration
- If using Hugging Face: wrap MoE layers with deepspeed.zero.HfDeepSpeedConfig for automatic leaf module detection
- As a diagnostic: try ZeRO stage 2 (which doesn't require parameter gathering) to confirm the hang is ZeRO-3 specific
- Use Denpex to detect MoE+ZeRO-3 hang patterns and recommend the leaf module configuration
Step-by-step remediation
- 1Mark MoE blocks as leaf modules: deepspeed.zero.set_z3_leaf_modules(model, [MoEBlockClass])
- 2Upgrade DeepSpeed to v0.14.0+ which has better MoE+ZeRO-3 integration
- 3If using Hugging Face: wrap MoE layers with deepspeed.zero.HfDeepSpeedConfig for automatic leaf module detection
- 4As a diagnostic: try ZeRO stage 2 (which doesn't require parameter gathering) to confirm the hang is ZeRO-3 specific
- 5Use Denpex to detect MoE+ZeRO-3 hang patterns and recommend the leaf module configuration
How to prevent it
- Always mark MoE blocks as leaf modules when using DeepSpeed ZeRO-3 with MoE models
- Test MoE models with ZeRO-3 in staging before production training
- Include MoE leaf module configuration in DeepSpeed training templates
- Use Denpex to validate DeepSpeed configuration for MoE models before training
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.
Searchable error signature
nvidia-smi shows 0% GPU utilization on all ranks during the hangUse 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 logsNo 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 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 extensionDeepSpeed errors in context
DeepSpeed changes when parameters, gradients and optimizer state are created, partitioned, gathered and offloaded. The hub separates ZeRO, memory, checkpoint and pipeline failures by lifecycle phase.
Compare related deepspeed errorsRelated failures to investigate next
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.