FSDP vs Megatron-LM: which scales LLM training better?
FSDP is simpler and enough while a model fits on one 8-GPU machine. Megatron-LM's tensor and pipeline split wins across machines on slow links.
FSDP is simpler and enough while a model fits on one 8-GPU machine. Megatron-LM's tensor and pipeline split wins across machines on slow links.
Run one torchrun per machine against a shared rendezvous, check the network math first, and debug hangs with the right flags. Tested commands inside.
Save model, optimizer, scheduler, scaler, RNG and data position in one atomic torch.save, then load all of it. Tested code and what breaks if you skip a part.
Write shards to a new step prefix, then a checksummed manifest, then a latest pointer. A crash test shows why that order is the commit.
Gradient checkpointing recomputes activations in the backward pass to save GPU memory. How it works, PyTorch and Hugging Face code, and when it pays.
The PyTorch speed levers in payoff order, from BF16 autocast to CUDA graphs, with sourced speedups, a timing harness and what each is worth in dollars.
Use FSDP by default. Use DeepSpeed ZeRO-3 when only CPU optimizer offload makes the model fit. Memory math for 8B and 70B, configs and a decision rule.
Make your script save and resume, size the GPU by memory, time a 200-step probe, then launch with a cost cap. A worked $1.67 run, with the code.
Use DDP until params, grads and AdamW state stop fitting on one GPU, about 3.75B params on an 80 GB H100. Then shard with FSDP. The memory math, worked.
Read what the OOM error says, then cut the biggest consumer: activations, optimizer state or fragmentation. An ordered checklist with GB math and code.
Low GPU utilization in PyTorch usually means the GPU is waiting on the CPU. How to measure it, what each symptom means, and what idle time costs.
Use DDP when the model fits on one GPU, FSDP when it doesn't, and launch with torchrun. Code, memory math and a cost check for going multi-node.
Save model, optimizer and step atomically, reload on start, and save again on the reclaim notice. Nodus restores the state on a new machine for you.