Parallelism Strategies Guide
Megatron Core supports multiple parallelism strategies that can be combined to efficiently train models from billions to trillions of parameters across thousands of GPUs.
Overview
The following table summarizes supported parallelism strategies.
Data Parallelism (DP)
Standard Distributed Data Parallel (DDP)
Replicate the model across GPUs and split the batch.
Each GPU has a full copy of the model and processes a portion of the batch.
Megatron Fully-Sharded Data Parallel (Megatron-FSDP)
Shard model parameters, gradients, and optimizer states across GPUs to reduce memory utilization.
Sharding Strategies
--data-parallel-sharding-strategy supports the following options:
optim- Shard optimizer states only (ZeRO-1)optim_grads- Shard gradients + optimizer (ZeRO-2)optim_grads_params- Shard parameters + gradients + optimizer (ZeRO-3)
If --num-distributed-optimizer-instances is > 1, then hierarchical data parallelism is enabled.
--outer-dp-sharding-strategy supports the following options:
no_shard(Hybrid-Sharded Data Parallelism) - Replicate the model state across outer data parallel ranks.optim(Hybrid-FSDP) - Shard the optimizer state across the outer data parallel ranks.- Requires
--data-parallel-sharding-strategy optim_grads_params.
- Requires
When to Use
- Large models with large or fused compute kernels to hide communications under.
- Integrated with TP, CP, EP, and easily composable with heterogeneous parallelisms.
- With SM-reducing optimizations from NCCL and activation offloading from TransformerEngine.
- Using
fully_shardwithout depending on Megatron-LM.
Tensor Parallelism (TP)
Split individual model layers across GPUs. Recommended for large hidden dimensions.
When to Use
- Model layers do not fit on a single GPU
- Large hidden dimensions (4096+)
- Usually combined with DP and PP
Pipeline Parallelism (PP)
Split model layers across GPUs vertically (by depth).
When to Use
- Very deep models (50+ layers)
- Combine with TP for large models
- Helps distribute memory across GPUs
Context Parallelism (CP)
Split long sequences across GPUs for efficient long-context training.
When to Use
- Long sequences (8K+ tokens)
- Reduces activation memory
- Can combine with TP, PP, DP
Refer to the Context Parallel Overview for a detailed guide with performance analysis.
Expert Parallelism (EP)
Distribute experts across GPUs in Mixture-of-Experts models.
Important: When combining EP with TP, you must enable Sequence Parallelism:
Parallelism Selection Guide
For a list of supported configurations, refer to Megatron Bridge Supported Models.
Language Models
Recommended language model configurations:
Mixture-of-Experts Models
Recommended mixture-of-experts configurations:
Combining Strategies
Total GPU Count
The total number of GPUs is calculated as:
Example: LLaMA-3 70B on 64 GPUs
Performance Optimizations
Communication Overlap
Enable overlapping of communication with computation:
Distributed Optimizer
Recommended for all multi-GPU training:
Benefits
- Faster checkpointing
- Reduced memory when combined with FSDP
- Better performance at scale
Sequence Parallelism
Always enable when using TP:
Reduces activation memory by sharding sequence dimension in LayerNorm and Dropout.
Choosing the Right Strategy
Start Simple
- Begin with Data Parallelism (DP) only.
- Add Tensor Parallelism (TP) if the model does not fit.
- Add Pipeline Parallelism (PP) for very large models.
- Add Context Parallelism (CP) for long sequences.
Memory Constraints
- Use FSDP to split model state per GPU.
- Use TP to split large layers.
- Use PP to split model depth.
- Enable activation checkpointing or offloading for extreme cases.
Communication Bottlenecks
- Reduce TP degree (increases memory per GPU).
- Increase PP degree (may reduce efficiency).
- Use CP instead of larger TP for long sequences.
Next Steps
- API Reference: Refer to Tensor Parallel and Pipeline Parallel in the API documentation
- Advanced Features: Refer to Megatron-FSDP, MoE, and Distributed Optimizer
- Performance Tuning: Refer to the NVIDIA NeMo Performance Guide