Once a transformer’s weights and optimizer states exceed a single GPU’s memory, standard data parallelism stalls because every accelerator must replicate the full model. In 2019, NVIDIA researchers Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, and Bryan Catanzaro showed that training multi-billion-parameter transformers does not require custom compilers like Mesh-TensorFlow or pipeline schedules with idle bubbles like GPipe. Inserting two conjugate all_reduce primitives per transformer layer in native PyTorch lets eight GPUs split heavy matrix multiplications cleanly across NVSwitch.

Megatron-LM’s column-parallel then row-parallel tensor sharding became the standard intra-node building block for modern LLM training and serving, sitting orthogonally alongside data parallelism, ZeRO optimizer state sharding, and later sequence parallelism and selective activation recomputation. Along the way, the team also diagnosed why scaling BERT past 336M parameters previously collapsed: moving LayerNorm off the residual trunk unlocked stable scaling to 3.9B parameters.

  • 15.1 sustained petaflops on 512 V100 GPUs: an 8.3B GPT-2 model (8-way model parallel by 64-way data parallel) reaches 76% scaling efficiency against a single-GPU 1.2B baseline at 39 teraflops (30% of V100 peak), while the 32-head sweep holds 77% efficiency for 8-way model parallel alone and 74% at 512 GPUs.
  • Four all-reduces per transformer layer: pairing a column-parallel first projection with a row-parallel second projection eliminates mid-block synchronization across both self-attention and the GeLU MLP, leaving 2 all-reduces in forward and 2 in backward.
  • Fused cross-entropy cuts output traffic over 50,000x: sharding tied embeddings across a 51,200-token padded vocabulary and fusing parallel logit GEMMs with cross-entropy shrinks communicated tensors from b x s x v logits down to b x s scalar losses.
  • LayerNorm placement fixes BERT scaling and sets SOTA: moving LayerNorm onto the sublayer branch (Architecture (b)) eliminates 752M+ training divergence, carrying 8.3B GPT-2 to 10.81 WikiText103 perplexity and 66.51% LAMBADA accuracy and 3.9B BERT to 90.9% RACE ensemble accuracy (89.5% single model).
Inside one Megatron-LM transformer layer: sharded compute vs. synchronization
1. Self-Attention block
Attention heads divide cleanly across GPUs with zero mid-attention sync.
Column-parallel Q, K, V then local attention
Conjugate f passes X forward unchanged (all-reduce in backward); each GPU computes its heads, softmax, and attention dropout locally.
Row-parallel output projection + g sync
Output linear weights split by rows; conjugate g runs 1 forward all-reduce before duplicated residual dropout.
2. MLP block
Column-then-row partitioning keeps GeLU elementwise on local shards.
Column-parallel A = [A_1, A_2] + local GeLU
Each rank computes Y_k = GeLU(X A_k) independently without waiting on neighbor GPUs.
Row-parallel B = [B_1; B_2] + g sync
Second GEMM multiplies local Y_k B_k; one forward all-reduce sums partial outputs (4 all-reduces total per layer).
3. Embeddings and glue
Duplicated non-tensor ops and fused loss avoid extra broadcasts.
Vocab-split embeddings + scalar loss fusion
Input embedding E = [E_1, E_2] uses 1 all-reduce; output logits GEMM fuses with cross-entropy to communicate b x s instead of b x s x v.

Architecture from Shoeybi et al. (2019), Section 3, Figures 3 and 4.

Column-then-row sharding eliminates mid-block communication

Every transformer layer alternates between multi-head self-attention and a two-layer MLP (Y = GeLU(XA) followed by Z = Dropout(YB)). Naive tensor splitting breaks immediately on the nonlinearity: if you slice X = [X_1, X_2] by columns and A = [A_1; A_2] by rows (Equation 2), each GPU produces a partial sum X_k A_k. Because GeLU(X_1 A_1 + X_2 A_2) does not equal GeLU(X_1 A_1) + GeLU(X_2 A_2), you must run a costly all_reduce right before the activation.

Megatron-LM reverses the partition order so the nonlinearity stays strictly local. Keeping X duplicated across ranks and slicing A = [A_1, A_2] by columns (Equation 3) lets each GPU compute [Y_1, Y_2] = [GeLU(XA_1), GeLU(XA_2)] independently. Slicing the second weight matrix B = [B_1; B_2] by rows aligns each GPU’s local Y_k directly with B_k, so one all_reduce after Y_k B_k produces the full block output before dropout and the residual add.

Self-attention uses the exact same structure across attention heads. Query, key, and value projections (Q, K, V) are partitioned column-wise so each GPU holds complete weights for its assigned heads (4 of 32 heads per GPU at 8-way split). Dot products, softmax, attention dropout, and value weighting stay inside local GPU memory, and a row-parallel output linear layer merges them via one all_reduce.

In PyTorch, this contract reduces to two conjugate autograd functions, f and g (Code 1). Operator f enters each parallel block as an identity in forward and runs all_reduce on gradients in backward; g exits the row-parallel GEMM with all_reduce in forward and identity in backward. One full transformer layer executes just 2 forward all-reduces and 2 backward all-reduces.

Three supporting choices keep GPUs compute-bound. First, tied input/output embeddings (H x v, padded from 50,257 to 51,200 tokens so per-GPU slices are multiples of 128 at 8-way split) are partitioned by vocabulary E = [E_1, E_2]: input embeddings use one g all-reduce, while output GEMMs [XE_1, XE_2] fuse directly with cross-entropy to communicate b x s scalar losses instead of b x s x v logits. Second, LayerNorm, residual adds, and their optimizer updates are simply duplicated across ranks rather than scattered and broadcast. Third, dropout uses two random generators (Appendix B.2): shared seeds across ranks for residual dropout outside parallel blocks, and distinct per-rank seeds inside local attention dropout.

Why partition order and loss fusion control communication volume
Row-then-col MLP (naive)

Produces partial sums X_1 A_1 and X_2 A_2; forces an extra all_reduce before GeLU can execute.

Col-then-row MLP (Megatron)

Runs GeLU(X A_k) and Y_k B_k locally, fusing two GEMMs behind a single all_reduce.

Fused output cross-entropy

Replaces a b x s x 51,200 logits all-gather with b x s scalar losses across ranks.

Design tradeoffs from Shoeybi et al. (2019), Section 3.

Scaling to 512 GPUs and fixing BERT’s LayerNorm trap

Experiments ran on 32 DGX-2H servers (512 Tesla V100 SXM3 32 GB GPUs) linking 8 GPUs per node over 300 GB/s NVSwitch (for model parallelism) and nodes via 100 GB/s InfiniBand (for 64-way data parallelism). Training used mixed precision, AdamW (lambda = 0.01), 1.0 global grad-norm clipping, 0.1 dropout, per-layer activation checkpointing, and a 174 GB deduplicated text corpus (Wikipedia, CC-Stories, RealNews, OpenWebText, plus BooksCorpus for BERT only, LSH Jaccard above 0.7).

Weak-scaling benchmarks (Table 1, Figure 5) measured throughput against a 1.2B single-GPU baseline (40 layers, 1536 hidden, 16 heads) sustaining 39 teraflops (30% of V100 peak). Pure model parallelism holds 96% efficiency at 2.5B (2 GPUs), 82% at 4.2B (4 GPUs), and 77% at 8.3B (8 GPUs, 32 heads). Adding 64-way data parallelism (batch size = 512) achieves 95% (128 GPUs), 83% (256 GPUs), and 74% (512 GPUs). Configuring the 8.3B GPT-2 model with 24 attention heads (128 dims/head, 72 layers, 3072 hidden) sustains 15.1 petaflops (76% efficiency), completing one 68,507-iteration epoch every 2.10 days.

Over 300k iterations (Table 3, Figure 6), larger GPT-2 models improved monotonically: WikiText103 test perplexity fell from 19.31 (355M) to 12.76 (2.5B) and 10.81 (8.3B, validation 9.27), beating the 15.79 prior SOTA, while LAMBADA cloze accuracy climbed from 45.18% (355M) to 61.73% (2.5B) and 66.51% (8.3B), surpassing the 63.24% prior SOTA. An 8-gram check confirmed at most 10.8% overlap on WikiText103 and 1.4% on LAMBADA.

Scaling bidirectional BERT uncovered why prior attempts degraded past BERT-large (336M). In Figure 7, the original layout (a) routes the residual trunk through LayerNorm, causing severe loss spikes and divergence at 752M parameters around 200k to 400k iterations. Moving LayerNorm inside the sublayer branch (Architecture (b)), leaving an unnormalized residual skip path (later formalized in Pre-LN transformer analysis), stabilized 752M+ training cleanly. Held-out perplexity fell across 336M (1.58), 1.3B (1.30), and 3.9B (1.16), and Megatron-3.9B set new benchmarks at half to one-third the tokens of RoBERTa and ALBERT: 91.4 / 91.4 MNLI, 92.7 QQP, 95.5 / 90.0 SQuAD 1.1 (95.8 / 90.5 ensemble), 91.2 / 88.5 SQuAD 2.0 (91.7 / 89.0 ensemble), and 89.5% single / 90.9% ensemble RACE test accuracy (beating 89.4% ALBERT ensemble).

Comparing Megatron-LM’s five design choices

Switch through the tabs below to inspect how each mechanism avoids synchronization bottlenecks alongside its measured cluster impact.

Five mechanisms inside Megatron-LM

Select a component (or use Left and Right arrow keys) to compare the naive bottleneck, Megatron-LM's design, measured scaling or accuracy numbers, and operational tradeoffs.

Column-parallel then row-parallel MLP

Intra-layer TP

Partitioning the first MLP weight matrix by columns and the second by rows keeps GeLU local to each GPU.

Why naive split breaks
Row-splitting A and column-splitting X forces an all-reduce before GeLU because GeLU(X_1 A_1 + X_2 A_2) != GeLU(X_1 A_1) + GeLU(X_2 A_2).
Megatron mechanism
Conjugate f keeps X duplicated forward (all-reduce backward); A = [A_1, A_2] produces local Y_k = GeLU(X A_k); B = [B_1; B_2] feeds one g all-reduce.
Measured impact
Cuts MLP synchronization to 1 forward and 1 backward all-reduce per layer across up to 8 NVSwitch-connected GPUs.
Operational tradeoff
Requires duplicating input activations X before f and running at fast intra-node NVSwitch speeds (300 GB/s) to stay compute-bound.

Source: Shoeybi et al. (2019), Sections 3 through 5 and Appendix B.

If you prefer the summary without clicking through the tabs, here are the five core mechanisms:

  • MLP split: column-parallel A followed by row-parallel B keeps GeLU local and trims each MLP to two all_reduce calls total.
  • Attention split: column-parallel Q, K, V keeps softmax and per-rank attention dropout local before a row-parallel output projection.
  • Fused cross-entropy: vocabulary-sharded 51,200-token embeddings fused with cross-entropy slash output communication from b x s x v to b x s.
  • BERT Pre-LN rearrangement: moving LayerNorm off the residual trunk eliminates 752M+ divergence and drives 3.9B BERT to 90.9% RACE accuracy.
  • Hybrid 2D topology: 8-way 300 GB/s NVSwitch TP plus 64-way 100 GB/s InfiniBand DP sustains 15.1 petaflops (76% efficiency) on 512 V100s.

Limits of intra-layer tensor parallelism

Three constraints define where Megatron-LM tensor parallelism tops out on its own.

First, tensor parallelism requires fast intra-node interconnects. Because f and g place 4 synchronous all_reduce calls per layer on the critical path, Section 6 notes that models exceeding 16B parameters (beyond 16 V100s in one DGX-2H box) cannot simply stretch TP across slower inter-node InfiniBand links without adding pipeline parallelism or optimizer sharding (as in 17B Turing-NLG with ZeRO).

Second, strong-scaling latency gains taper quickly. While weak scaling 1.2B to 8.3B holds 77% efficiency on 8 GPUs, Table 8 shows that fixing batch size at 8 on the 1.2B model yields only 1.64x speedup on 2 GPUs, 2.34x on 4, and 2.98x on 8 as smaller GEMMs underutilize Tensor Cores and NVSwitch latency dominates. Similarly, splitting 8.3B into 32 heads (96 dims) instead of 16 (192 dims) drops 8-way efficiency from 82% to 77% (Table 7), underscoring why kernel-level tiling later mattered in FlashAttention-2 work partitioning.

Third, duplicating LayerNorm, dropout, and residual streams replicates activations. Every TP rank still stores redundant b x s x H tensors outside the parallel GEMMs and needs per-layer activation checkpointing (Section 4.2), a bottleneck later removed by sharding along the sequence axis in sequence parallelism.

For cluster architects today, Megatron-LM’s operational boundary remains clean: keep tensor parallelism inside one node’s high-bandwidth NVLink fabric (4 to 8 GPUs), pad vocabularies to Tensor Core multiples, fuse cross-entropy across vocabulary shards, and cross node boundaries with data, ZeRO, or pipeline parallelism.