Before a 256-GPU pretraining cluster is built, how would you decide whether the program standardizes on FSDP2, DeepSpeed or Megatron-Core?
answer
- what the model code must become
- which parallel dimensions you need
- sequence length and experts on the roadmap
- NVLink domain against inter-node network
- pilot on a slice, measure, then commit
basics
~20 sDecide on conditions, not brand: whether sharded data parallelism alone fits the model, whether the roadmap needs tensor, pipeline, context or expert parallelism, how the interconnect is shaped, and whether the team can rewrite model code into Megatron-Core's layers.
solid answer
~50 sI would write the deciding conditions down first. If the model fits with sharded data parallelism alone, FSDP2's `fully_shard` or DeepSpeed ZeRO-3 shard an existing PyTorch model without rewriting its layers; at 70B on 256 GPUs that is about 4.4 GB of model state per GPU, but every layer is gathered across 32 nodes twice per step. If the roadmap needs tensor, pipeline, context and expert parallelism together, Megatron-Core provides them as one grid with its distributed optimizer, at the price of building the model from its parallel layers. Long sequences and MoE narrow the choice: DeepSpeed brings Ulysses and an `ep_size` MoE layer, Megatron-Core brings four context-parallel modes and an expert grid; FSDP2 composes with DTensor tensor parallelism on a 2D mesh. Then run each finalist on a few nodes of the target interconnect, compare step time and memory, and commit with the criteria recorded.
go deeper
Recall the three engines and the one thing each is known for: FSDP2 shards PyTorch parameters, DeepSpeed configures ZeRO stages, Megatron-Core lays out tensor, pipeline, context and expert groups.
Explain what each engine requires from the model code and which parallel dimensions each provides, so a choice can be checked against a model's size and sequence length.
Turn the roadmap and cluster shape into concrete requirements — group sizes inside the NVLink domain, offload needs, long-context and expert parallelism — and design the pilot that tests them.
Own the trade between rewrite cost, scaling headroom and operating burden across three release trains, and record the conditions that would reopen the decision instead of crowning an engine.
## What the decision commits Choosing a **sharding engine** for a pretraining program is not choosing a library call. It fixes how the model code is written, which parallel dimensions are available when the model or sequence grows, how memory pressure is relieved, and which release train the platform team follows. The three engines in this comparison — PyTorch 2.14's FSDP2, DeepSpeed 0.19 and Megatron-Core 0.19 — overlap more than their names suggest, so the honest answer is a set of conditions, each checked against the plan. ## The engines on the same axes | Axis | FSDP2 (`fully_shard`) | DeepSpeed | Megatron-Core | |---|---|---|---| | Model code | any `nn.Module`; call per block, names unchanged | existing PyTorch model plus a JSON config; ZeRO needs no layer rewrite | model built from Megatron-Core's config and parallel layers | | Sharded data parallel | DTensor `Shard(0)`; hybrid via a 2D mesh | ZeRO stages 1-3 | distributed optimizer; Megatron-FSDP | | Tensor parallel | DTensor TP on one mesh dimension, FSDP on the other | AutoTP, sized by `tensor_parallel.autotp_size` | built in, with sequence parallelism | | Pipeline parallel | `torch.distributed.pipelining` stages and schedules, a separate package | `PipelineModule` and its pipeline engine, which accepts ZeRO stage 1 at most | built in, with virtual stages | | Long sequences | nothing in FSDP2 itself | Ulysses `DistributedAttention` | context parallelism, four communication types | | Mixture of experts | `shard_placement_fn` can put expert parameters on another mesh | `MoE(..., ep_size=...)` | expert grid with its own tensor and data sizes | | Memory beyond the GPU | `CPUOffloadPolicy` (host memory) | `offload_optimizer` / `offload_param` to CPU or NVMe | optimizer CPU offload | ## The deciding conditions 1. **Does sharded data parallelism alone fit?** At 70B on 256 GPUs, ZeRO-3 or FSDP2 leaves about 4.4 GB of model state per GPU. The cost is communication: every layer's weights are gathered across all 256 ranks, spanning 32 nodes, in forward and again in backward. FSDP2's hybrid mesh or integer `reshard_after_forward` and DeepSpeed's bucket and overlap settings soften this; tensor parallelism inside the node removes much of it. 2. **What does the roadmap add?** A long-context phase needs Ulysses or context parallelism; an MoE sibling needs expert parallelism and a placement for its all-to-all. If both are coming, an engine that already composes them saves integration work later. 3. **How is the cluster shaped?** The NVLink domain size (8 here) bounds tensor and expert groups; the inter-node network carries pipeline, data-parallel and ZeRO-3 traffic. A slower inter-node network favours keeping more parallelism inside the node. 4. **Who owns the model code?** A team that iterates on architectures in plain PyTorch pays a rewrite to move onto Megatron-Core's layers; a team training one well-known architecture at scale may find that rewrite already done. 5. **How is it operated?** Release cadence, version pinning across three moving projects, and checkpoint conversion between engines (that subject belongs to the checkpointing material) all land on the platform team. ## Running the decision - Build a pilot on four nodes of the target hardware: the same model slice, the same sequence length, each finalist engine. - Record step time, peak memory and the share of time in communication — measuring those is the profiling material's subject. - Write the criteria and the numbers into the decision record, with the condition that would reopen it (a new sequence length, an MoE model, a different interconnect). - Keep the boundary porous: Megatron-Core also runs FSDP-style sharding, and FSDP2 composes with DTensor tensor parallelism, so the choice is about the default path, not an exclusive door. ## What weak answers say - "One engine is simply the fastest" — speed depends on model shape, sequence length and interconnect. - "Megatron-Core is only for pipeline parallelism" — it provides tensor, pipeline, context, expert and data-parallel groups and a distributed optimizer. - "FSDP2 cannot combine with tensor parallelism" — it composes with DTensor tensor parallelism on a 2D mesh. - Choosing before the interconnect and the roadmap are known.
- The program's next model is a 64-expert MoE. How does that change the engine decision?It adds a hard requirement: expert parallelism with its all-to-all kept inside the NVLink domain. DeepSpeed provides `MoE(..., ep_size=...)`; Megatron-Core provides an expert grid whose expert tensor size, expert-parallel size and dispatcher are set separately from the dense layout; FSDP2's `shard_placement_fn` can place expert parameters on a separate mesh but leaves the token exchange to the model code. Pilot the MoE model, not only the dense one.
- What would make you revisit a decision to standardize on ZeRO-3 for the 70B model?Evidence that per-layer gathers across 32 nodes dominate step time even with overlap tuned, a long-context phase needing a degree beyond the model's key-value heads, or an MoE model whose experts need placement inside nodes. Each is a written trigger in the decision record, so the revisit is planned rather than a crisis.
- One engine is always fastest, whatever the model and cluster
- FSDP2 cannot be combined with tensor parallelism
- Megatron-Core only adds pipeline parallelism on top of data parallelism
- The interconnect does not matter once memory fits
- The engine can be picked before the sequence-length and MoE roadmap is known
Assumes PyTorch 2.14.1 for FSDP2 (fully_shard, CPUOffloadPolicy, shard_placement_fn), DeepSpeed 0.19.7 and Megatron-Core 0.19.2; each engine's feature set is checked against those releases only.