Account for every byte of the 16-byte mixed-precision training rule, eliminate Data Parallel redundancy via ZeRO-1/2/3, slice operators with Megatron-LM 3D parallelism, and reconcile Chinchilla optimality with inference-optimal over-training.
1.Why an 8-billion parameter model overflows an 80 GB GPU#
In bfloat16 inference, an parameter model (Llama-3-8B) occupies of VRAM. In mixed-precision training with AdamW, that same model requires of static parameter-state memory before a single token's activations are even allocated.
The culprit is the Mixed-Precision Training Ledger (Rajbhandari et al., ZeRO, arXiv:1910.02054[2]ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsOpen arXiv:1910.02054 ↗). For every trainable parameter :
- Working Weights (
bfloat16/float16): per parameter used in forward and backward GEMMs. - Gradients (
bfloat16/float16): per parameter accumulated during backpropagation. - Optimizer States (
float32AdamW):- Master copy of weights (), required because small update steps underflow in 16-bit precision.
- First moment momentum buffer ().
- Second moment variance buffer ().
For a model (), the static state alone requires —fourteen H100 GPUs just to hold the static buffers, before accounting for layer activations!
2.ZeRO-1, ZeRO-2, and ZeRO-3: Sharding redundant data-parallel state#
Standard Distributed Data Parallelism (DDP) replicates the entire byte state across all data-parallel GPUs. Since every rank holds identical weights and optimizer buffers, copies are pure memory redundancy. Zero Redundancy Optimizer (ZeRO) (arXiv:1910.02054[2]ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsOpen arXiv:1910.02054 ↗) partitions these three state components across the data-parallel ranks while preserving the exact mathematical semantics of synchronous mini-batch SGD:
| Sharding Mode | Per-GPU Static Memory Formula | 70B Model on GPUs | Collective Communication Pattern & Overhead |
|---|---|---|---|
| Baseline DDP | (OOM) | AllReduce gradients ( bytes per step) |
|
| ZeRO-1 () | ReduceScatter grads + AllGather updated weights ( bytes—zero extra traffic!) |
||
| ZeRO-2 () | Gradients freed immediately after ReduceScatter ( bytes—zero extra traffic!) |
||
| ZeRO-3 / FSDP () | ( reduction) | Adds AllGather weights before forward & backward ( total traffic: bytes) |
A ring or tree AllReduce of bytes of bfloat16 gradients is implemented under the hood as two phases:
- A
ReduceScatter( bytes transferred), after which each of the GPUs holds the fully summed gradient for its assigned shard of parameters. - An
AllGather( bytes transferred), which broadcasts the summed gradients to every GPU.
In ZeRO-2, each rank only updates the slice of AdamW states it owns. Therefore, after ReduceScatter finishes, each rank immediately steps its local FP32 AdamW shard and discards the rest of the gradients, then executes the AllGather on the newly updated bfloat16 weights instead of the gradients. Total network volume remains bytes per step—identical to DDP!
3.Megatron-LM: Tensor Parallelism and Pipeline Parallelism#
When a single layer's weight matrix or activation footprint is too large, or when ZeRO-3's inter-node AllGather latency exceeds interconnect bandwidth, Megatron-LM (Shoeybi et al., arXiv:1909.08053[1]Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismOpen arXiv:1909.08053 ↗) slices the transformer operators themselves across fast intra-node NVLink ( on H100) using Tensor Parallelism (TP).
The key design goal of Megatron-LM is to partition a two-layer MLP or multi-head attention block without requiring communication in the middle of the nonlinear activation function:
- Column-Parallel Linear First Layer (): Split the weight matrix column-wise across GPUs as . Because or is an element-wise nonlinearity, it applies independently to each column shard:
- Row-Parallel Linear Second Layer (): Split the down-projection matrix row-wise as . The block matrix product becomes a sum of partial matrices:
Each GPU computes locally, followed by a single AllReduce before the residual dropout and layer normalization. For Multi-Head Attention, are partitioned column-wise across heads, and is partitioned row-wise—requiring only two AllReduce operations per Transformer block in the forward pass and two in the backward pass.
When scaling across multiple nodes connected by slower InfiniBand fabric, Pipeline Parallelism (PP) assigns contiguous groups of layers (stages) to different nodes. Naive sequential pipelining leaves stages idle at any moment, creating a Pipeline Bubble fraction of for micro-batches. The 1F1B (One-Forward-One-Backward) schedule interleaves forward and backward micro-batches so that in-flight activation memory stays bounded by micro-batches rather than , while Sequence Parallelism (SP) shards the RMSNorm and Dropout activations along the sequence dimension by replacing TP's AllReduce with ReduceScatter + AllGather.
4.Chinchilla Compute-Optimal Scaling vs. Inference-Optimal Models#
How should a fixed training compute budget (where is parameters and is training tokens) be divided between model size and dataset size ?
Kaplan et al. (2020) originally suggested scaling and , leading to massive, under-trained models such as GPT-3 ( parameters trained on tokens) and Gopher (). Hoffmann et al. (Chinchilla, arXiv:2203.15556[3]Training Compute-Optimal Large Language ModelsOpen arXiv:2203.15556 ↗) discovered that Kaplan's experiments used a fixed cosine learning-rate schedule length instead of matching the decay horizon to each token budget. By fitting the parametric loss surface across over 400 training runs:
and minimizing subject to , Chinchilla proved that model parameters and training tokens must scale in equal proportion:
Trained on tokens, the Chinchilla model outperformed the Gopher model across virtually every benchmark while requiring less inference memory and compute.
4.1Why Llama-3 trains an 8B model on 15 Trillion tokens#
Notice that Chinchilla optimizes strictly for pretraining FLOPs , ignoring lifetime inference cost . Under the rule, an model is "compute-optimal" at just tokens. Yet Meta trained Llama-3-8B on tokens (—nearly beyond the Chinchilla ratio!).
Why? Because a popular open-weights or production model is trained once, then served across billions of inference requests. Spending extra pretraining compute to compress the loss of a Chinchilla-optimal model into an parameter footprint permanently slashes every downstream user's KV cache footprint and decode HBM traffic by nearly . Modern frontier training therefore follows an Inference-Adjusted Scaling Law:
5.References and next chapter#
- Shoeybi et al., Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism (2019).
- Rajbhandari et al., ZeRO: Memory Optimizations Toward Training Trillion Parameter Models (2019).
- Hoffmann et al., Training Compute-Optimal Large Language Models (2022).
- Continue to Chapter 4: Post-Training Alignment & Test-Time Reasoning: RLHF, DPO, and DeepSeek-R1's GRPO.
References
- [1]
- [2]
- [3]