Abstract

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 8.03B8.03\text{B} parameter model (Llama-3-8B) occupies 8.03×109×2 Bytes≈14.96 GB8.03 \times 10^9 \times 2\text{ Bytes} \approx 14.96\text{ GB} of VRAM. In mixed-precision training with AdamW, that same model requires 119.66 GB119.66\text{ GB} of static parameter-state memory before a single token's activations are even allocated.

The culprit is the 16Ψ16\Psi Mixed-Precision Training Ledger (Rajbhandari et al., ZeRO, arXiv:1910.02054[2][2] · ZeRO · 2019ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsOpen arXiv:1910.02054 ↗). For every trainable parameter ψ∈{1,…,Ψ}\psi \in \{1, \dots, \Psi\}:

  1. Working Weights (bfloat16 / float16): 2 Bytes2\text{ Bytes} per parameter used in forward and backward GEMMs.
  2. Gradients (bfloat16 / float16): 2 Bytes2\text{ Bytes} per parameter accumulated during backpropagation.
  3. Optimizer States (float32 AdamW):
    • Master copy of weights θfp32\theta_{\text{fp32}} (4 Bytes4\text{ Bytes}), required because small update steps Δθ=−ηm^t/v^t\Delta \theta = -\eta \hat{m}_t / \sqrt{\hat{v}_t} underflow in 16-bit precision.
    • First moment momentum buffer mtm_t (4 Bytes4\text{ Bytes}).
    • Second moment variance buffer vtv_t (4 Bytes4\text{ Bytes}).
Static Training Memory=2Ψ⏟BF16 Weights+2Ψ⏟BF16 Grads+(4+4+4)Ψ⏟FP32 AdamW States=16Ψ Bytes\text{Static Training Memory} = \underbrace{2\Psi}_{\text{BF16 Weights}} + \underbrace{2\Psi}_{\text{BF16 Grads}} + \underbrace{(4 + 4 + 4)\Psi}_{\text{FP32 AdamW States}} = \mathbf{16\Psi\text{ Bytes}}
(1)

For a 70B70\text{B} model (Ψ=70×109\Psi = 70 \times 10^9), the static state alone requires 16×70 GB=1,120 GB16 \times 70\text{ GB} = \mathbf{1,120\text{ GB}}—fourteen 80 GB80\text{ GB} H100 GPUs just to hold the static buffers, before accounting for layer activations!

Figure 1: Per-GPU static memory across Baseline DDP and ZeRO Stages 1–3 for a 70B model alongside Chinchilla compute-optimal versus Llama-3 inference-optimal token budgets.
Figure 1: Per-GPU static memory across Baseline DDP and ZeRO Stages 1–3 for a 70B model alongside Chinchilla compute-optimal versus Llama-3 inference-optimal token budgets.

2.ZeRO-1, ZeRO-2, and ZeRO-3: Sharding redundant data-parallel state#

Standard Distributed Data Parallelism (DDP) replicates the entire 16Ψ16\Psi byte state across all NdN_d data-parallel GPUs. Since every rank holds identical weights and optimizer buffers, Nd−1N_d - 1 copies are pure memory redundancy. Zero Redundancy Optimizer (ZeRO) (arXiv:1910.02054[2][2] · ZeRO · 2019ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsOpen arXiv:1910.02054 ↗) partitions these three state components across the NdN_d data-parallel ranks while preserving the exact mathematical semantics of synchronous mini-batch SGD:

Sharding Mode Per-GPU Static Memory Formula 70B Model on Nd=8N_d = 8 GPUs Collective Communication Pattern & Overhead
Baseline DDP 16Ψ16\Psi 1,120.0 GB1,120.0\text{ GB} (OOM) AllReduce gradients (2×2Ψ=4Ψ2 \times 2\Psi = 4\Psi bytes per step)
ZeRO-1 (PosP_{\text{os}}) 2Ψ+2Ψ+12ΨNd2\Psi + 2\Psi + \frac{12\Psi}{N_d} 385.0 GB385.0\text{ GB} ReduceScatter grads + AllGather updated weights (4Ψ4\Psi bytes—zero extra traffic!)
ZeRO-2 (Pos+gP_{\text{os+g}}) 2Ψ+2Ψ+12ΨNd2\Psi + \frac{2\Psi + 12\Psi}{N_d} 315.0 GB315.0\text{ GB} Gradients freed immediately after ReduceScatter (4Ψ4\Psi bytes—zero extra traffic!)
ZeRO-3 / FSDP (Pos+g+pP_{\text{os+g+p}}) 16ΨNd\frac{16\Psi}{N_d} 140.0 GB\mathbf{140.0\text{ GB}} (8×8\times reduction) Adds AllGather weights before forward & backward (1.5×1.5\times total traffic: 6Ψ6\Psi bytes)

A ring or tree AllReduce of 2Ψ2\Psi bytes of bfloat16 gradients is implemented under the hood as two phases:

  1. A ReduceScatter (2Ψ2\Psi bytes transferred), after which each of the NdN_d GPUs holds the fully summed gradient for its assigned 1/Nd1/N_d shard of parameters.
  2. An AllGather (2Ψ2\Psi bytes transferred), which broadcasts the summed gradients to every GPU.

In ZeRO-2, each rank only updates the 1/Nd1/N_d 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 2Ψ+2Ψ=4Ψ2\Psi + 2\Psi = 4\Psi 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][1] · Megatron-LM · 2019Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismOpen arXiv:1909.08053 ↗) slices the transformer operators themselves across fast intra-node NVLink (900 GB/s900\text{ GB/s} 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:

  1. Column-Parallel Linear First Layer (W1W_1): Split the weight matrix A∈RH×dffA \in \mathbb{R}^{H \times d_{\text{ff}}} column-wise across NtpN_{\text{tp}} GPUs as A=[A1,A2,…,ANtp]A = [A_1, A_2, \dots, A_{N_{\text{tp}}}]. Because GeLU⁡\operatorname{GeLU} or SiLU⁡\operatorname{SiLU} is an element-wise nonlinearity, it applies independently to each column shard:
[Y1, Y2]=[GeLU⁡(XA1), GeLU⁡(XA2)]\big[Y_1,\, Y_2\big] = \Big[\operatorname{GeLU}(X A_1),\, \operatorname{GeLU}(X A_2)\Big]
(2)
  1. Row-Parallel Linear Second Layer (W2W_2): Split the down-projection matrix B∈Rdff×HB \in \mathbb{R}^{d_{\text{ff}} \times H} row-wise as B=[B1B2]B = \begin{bmatrix} B_1 \\ B_2 \end{bmatrix}. The block matrix product becomes a sum of partial matrices:
Z=[Y1, Y2][B1B2]=Y1B1+Y2B2Z = \big[Y_1,\, Y_2\big] \begin{bmatrix} B_1 \\ B_2 \end{bmatrix} = Y_1 B_1 + Y_2 B_2
(3)

Each GPU computes YiBi∈RB×S×HY_i B_i \in \mathbb{R}^{B \times S \times H} locally, followed by a single AllReduce before the residual dropout and layer normalization. For Multi-Head Attention, WQ,WK,WVW_Q, W_K, W_V are partitioned column-wise across heads, and WOW_O 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 Npp−1N_{\text{pp}} - 1 stages idle at any moment, creating a Pipeline Bubble fraction of Npp−1M+Npp−1\frac{N_{\text{pp}} - 1}{M + N_{\text{pp}} - 1} for MM micro-batches. The 1F1B (One-Forward-One-Backward) schedule interleaves forward and backward micro-batches so that in-flight activation memory stays bounded by NppN_{\text{pp}} micro-batches rather than MM, while Sequence Parallelism (SP) shards the RMSNorm and Dropout activations along the sequence dimension SS by replacing TP's AllReduce with ReduceScatter + AllGather.

4.Chinchilla Compute-Optimal Scaling vs. Inference-Optimal Models#

How should a fixed training compute budget C≈6NDC \approx 6 N D (where NN is parameters and DD is training tokens) be divided between model size NN and dataset size DD?

Kaplan et al. (2020) originally suggested scaling N∝C0.73N \propto C^{0.73} and D∝C0.27D \propto C^{0.27}, leading to massive, under-trained models such as GPT-3 (175B175\text{B} parameters trained on 300B300\text{B} tokens) and Gopher (280B280\text{B}). Hoffmann et al. (Chinchilla, arXiv:2203.15556[3][3] · Chinchilla · 2022Training 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:

L(N,D)=E+ANα+BDβ,α≈0.34,  β≈0.28L(N, D) = E + \frac{A}{N^\alpha} + \frac{B}{D^\beta}, \qquad \alpha \approx 0.34,\; \beta \approx 0.28
(4)

and minimizing L(N,D)L(N, D) subject to FLOPs(N,D)=6ND=C\text{FLOPs}(N, D) = 6ND = C, Chinchilla proved that model parameters NN and training tokens DD must scale in equal proportion:

Nopt∝Cβα+β≈C0.50,Dopt∝Cαα+β≈C0.50  ⟹  Dopt≈20NN_{\text{opt}} \propto C^{\frac{\beta}{\alpha + \beta}} \approx C^{0.50}, \qquad D_{\text{opt}} \propto C^{\frac{\alpha}{\alpha + \beta}} \approx C^{0.50} \implies \mathbf{D_{\text{opt}} \approx 20 N}
(5)

Trained on 1.4T1.4\text{T} tokens, the 70B70\text{B} Chinchilla model outperformed the 280B280\text{B} Gopher model across virtually every benchmark while requiring 4×4\times 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 CtrainC_{\text{train}}, ignoring lifetime inference cost CinferC_{\text{infer}}. Under the D≈20ND \approx 20N rule, an 8B8\text{B} model is "compute-optimal" at just 160B160\text{B} tokens. Yet Meta trained Llama-3-8B on 15 Trillion15\text{ Trillion} tokens (D/N≈1,875×D / N \approx 1,875\times—nearly 94×94\times 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 70B70\text{B} Chinchilla-optimal model into an 8B8\text{B} parameter footprint permanently slashes every downstream user's KV cache footprint and decode HBM traffic by nearly 9×9\times. Modern frontier training therefore follows an Inference-Adjusted Scaling Law:

min⁡N,D  L(N,D)subject to6ND+2N⋅Tlifetime_infer≤Ctotal\min_{N, D}\; L(N, D) \quad \text{subject to} \quad 6 N D + 2 N \cdot T_{\text{lifetime\_infer}} \le C_{\text{total}}
(6)

5.References and next chapter#

References

  1. [1]
  2. [2]
  3. [3]

Share