Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism

  • Problem Transformer models with billions of parameters exceed what one GPU can hold in memory, and earlier model-parallel frameworks need rewritten models or custom compilers.
  • Method Splits the first GEMM of each MLP block by columns and the second by rows, splits self-attention by heads, and adds a few all-reduce operations in native PyTorch.
  • Results Reached 15.1 PetaFLOPs sustained across the whole application for the 8.3B model on 512 GPUs with 8-way model parallelism.

Why one GPU runs out of room

Bigger language models tend to be more useful, yet each parameter also brings optimizer memory on top of its weight. Adam, for example, keeps momentum and other state for every parameter, so the largest model one device can train becomes smaller. Model parallelism spreads weights and optimizer state over several devices, but GPipe and Mesh-TensorFlow need the model rewritten and depend on compilers and frameworks that were still in development.

Parameter sharing lowers the memory footprint but also lowers the capacity of the model.

Data parallelism and activation checkpointing both assume that the whole model fits on one worker. The authors split each layer across GPUs instead, which also raises the amount of parallelism available independently of the microbatch size. The approach runs in native PyTorch with a few inserted communication operations, needs no new compiler, and is meant to sit alongside pipeline model parallelism rather than replace it.

Splitting the MLP block

A transformer layer is a self-attention block followed by a two-layer MLP block, and the MLP first computes a GEMM followed by GeLU, written as \[ Y = \mathrm{GeLU}(XA) \] Splitting A by rows and X by columns puts a sum inside the GeLU, and GeLU of a sum is not the sum of the GeLUs, so a synchronization point would be needed before the nonlinearity.

Splitting A by columns avoids that, because each GPU applies GeLU to its own output: \[ [Y_1, Y_2] = [\mathrm{GeLU}(XA_1), \mathrm{GeLU}(XA_2)] \] The second GEMM is split by rows, so it consumes each GPU's GeLU output in place and needs no communication before it. The partial outputs are then summed by one all-reduce in the forward pass, carried out by the g operator, before the result reaches dropout.

The backward pass uses the conjugate operator f, which is an identity in the forward pass and an all-reduce in the backward pass. Each of the two operators takes only a few lines of PyTorch, and the f operator is shown as a short autograd function. Together this gives a single all-reduce in each direction for the MLP block.

Attention heads and the vocabulary layers

In the self-attention block the key, query and value projections are split by columns, so each GPU computes the attention for its own heads locally. The output linear layer is split by rows and consumes the local head outputs in place, so no GPU-to-GPU communication is needed inside the attention computation.

The output embedding has dimension H times v, and with a vocabulary of tens of thousands, GPT-2 uses 50,257 tokens, so splitting that GEMM is worthwhile. The output embedding shares its weights with the input embedding, so both layers have to change together. The input embedding E is split along the vocabulary dimension, and an all-reduce follows it because each partition holds only part of the table.

A straightforward output layer would all-gather b×s×v logits, which is large because the vocabulary is large. Fusing the parallel GEMM with the cross entropy loss reduces the transferred data to b×s scalar losses.

Figure 4 marks the communication operations in one model-parallel transformer layer, with four in total across the forward and backward passes.

Dropout, layer normalization and residual connections are computed redundantly on each GPU rather than computed once and broadcast. Layer normalization parameters are kept as copies on every GPU, so updated parameter values never need to be exchanged. Each model-parallel worker optimizes its own set of parameters.

Combining model and data groups

Model parallelism is orthogonal to data parallelism, so the two can be used at once. GPUs within one server form a model-parallel group that holds one instance of the model, and GPUs in the same position across groups form a data-parallel group that holds identical parameters. The total GPU count is the product of the number of model-parallel groups and the number of data-parallel groups.

For the 8.3 billion parameter model, each model-parallel group uses 8 GPUs and data parallelism is 64-way, giving 512 GPUs in total. During backpropagation, gradient all-reduces run in parallel inside each data-parallel group, and communication is issued from PyTorch through NCCL.

Dropout appears both outside model-parallel regions, before residual connections, and inside them, in the self-attention block, so the random number generation has to be handled carefully. Residual-connection dropout uses one seed set at the start of training, so the masks are identical on every model-parallel worker. Dropout inside a model-parallel region uses a separate generator that is seeded uniquely for each worker, so those masks differ across workers.

Corpus and training recipe

The corpus combines Wikipedia, CC-Stories, RealNews and OpenWebText, and BooksCorpus is added only for the BERT runs. Wikipedia articles that appear in the WikiText103 test set are removed to keep test data out of training. Documents shorter than 128 tokens are dropped, and near-duplicates are removed with locality-sensitive hashing at Jaccard similarity greater than 0.7, leaving 174 GB.

Training uses mixed precision with dynamic loss scaling to exploit the V100 Tensor Cores. Weights start from a normal distribution W ∼ N(0, 0.02), and the weights before residual layers are scaled by \(1/\sqrt{2N}\), where N is the number of transformer layers. The optimizer is Adam with weight decay λ = 0.01, global gradient norm clipping at 1.0 and dropout of 0.1, with activation checkpointing after every transformer layer.

The peak learning rate is 1.5e-4 with 3k warmup iterations, then a single cosine decay over the remaining 297k iterations down to a minimum of 1e-5.

BERT runs follow Lan et al. (2019) with the original BERT vocabulary of 30,522, sentence order prediction in place of next sentence prediction, and whole word n-gram masking.

Weak scaling from 1.2B to 8.3B parameters

Experiments use up to 32 DGX-2H servers, which is 512 Tesla V100 SXM3 32GB GPUs in total. Model parallel runs keep a batch size of 8, while model+data runs fix the global batch size at 512, which is 64-way data parallelism.

The baseline is the 1.2 billion parameter model on one GPU, which sustains 39 TeraFLOPS, or 30% of the peak FLOPS of one GPU in a DGX-2H server. Figure 1 plots model and model+data parallel FLOPS against the number of GPUs.

On 512 GPUs with model+data parallelism, the same model reaches 74% relative to linear scaling of the single-GPU baseline. The introduction quotes 76% for the 15.1 PetaFLOPs point, so the two efficiency figures for this configuration are 76% and 74%. The extra gradient communication of model+data parallelism is the reason the scaling numbers drop slightly.

Effect of attention head count on scaling

The 8.3 billion parameter configuration with 8-way model parallelism is varied from 16 to 32 attention heads. Scaling efficiency is 82% with 16 heads, 80% with 24 heads and 77% with 32 heads, as the hidden size per head falls from 192 to 128 to 96. More heads make some GEMMs in self-attention smaller and enlarge the self-attention softmax, which the authors connect to the slight decline in efficiency.

The GPT-2 8.3B model used in the language modeling results has 24 heads instead of 32.

Speedup for the 1.2B model at fixed batch size

For the 1.2 billion parameter model, the batch size is kept fixed at 8 samples per iteration while the number of GPUs grows through model parallelism. The speedup is 1.0, 1.64, 2.34 and 2.98 on 1, 2, 4 and 8 GPUs. Two GPUs make training 64% faster.

GPT-2 results at 355M, 2.5B and 8.3B

Three GPT-2 sizes are trained: 355M with 24 layers and hidden size 1024 on 64 GPUs, 2.5B with 54 layers and hidden size 1920 on 128 GPUs, and 8.3B with 72 layers and hidden size 3072 on 512 GPUs. The 355M configuration has the same size as BERT-Large. Training takes 0.86, 2.27 and 2.10 days per epoch, where one epoch is 68,507 iterations.

Zero-shot WikiText103 perplexity is 19.31, 12.76 and 10.81 for 355M, 2.5B and 8.3B, against a previous state of the art of 15.79. Zero-shot LAMBADA accuracy is 45.18%, 61.73% and 66.51%, against a previous state of the art of 63.24%. Perplexity falls and accuracy rises with model size across these three points, and the 8.3B model reaches a validation perplexity of 9.27.

The authors state that the 8.3B model surpasses the previous results on both datasets, with those earlier values taken from prior work. They also cite Turing-NLG, a 17 billion parameter GPT-2 model trained with Megatron by Microsoft in collaboration with NVIDIA, as another case where accuracy keeps improving with scale.

How perplexity and LAMBADA are scored

WikiText103 perplexity is the exponential of the average cross entropy, normalized by the original token count T_o rather than by the subword count T, as in \[ \mathrm{PPL} = \exp\left(-\frac{1}{T_o}\sum_{t} \log P(t \mid 0:t-1)\right) \] Normalizing by T_o keeps the scores comparable with prior work that used the pre-tokenized word counts.

For the WikiText103 test set, T_o is 245566 and T is 270329, and the detokenizers are applied after T_o is computed.

A transformer conditions on a fixed window of 1024 tokens, so each probability is conditioned on a sliding window rather than the full prefix. Windows advance by an overlap of 32 tokens, and only the losses for the last 32 tokens of each window are computed.

LAMBADA is a cloze task built from 4-5 sentences, in which the last word of the context is masked and must be predicted. Because the models use subword units, they predict every subword token of the missing word with teacher forcing, and an answer counts only when all predicted tokens are correct. The authors state that this formulation is equivalent to word token prediction.

Why the layer normalization order matters for BERT

Prior work found that BERT-style models larger than BERT-large with 336M parameters degrade, and that parameter sharing scales better. The authors instead rearrange the order of layer normalization and the residual connections, as shown in Figure 7.

Architecture (b) removes the instabilities seen with the original BERT architecture in (a) and reaches a lower training loss. The original layout trains well at 336M, so the rearrangement is what makes stable training possible at larger sizes. To the authors' knowledge, this is the first report that such a change enables training larger BERT models.

BERT-style model sizes and downstream scores

Three sizes are trained: 336M with 24 layers, hidden size 1024 and 16 heads on 128 GPUs; 1.3B with 24 layers, hidden size 2048 and 32 heads on 256 GPUs; and 3.9B with 48 layers, hidden size 2560 and 40 heads on 512 GPUs. On a 3% held-out set, validation perplexity is 1.58, 1.30 and 1.16 for 336M, 1.3B and 3.9B, a monotonic decrease with size.

Fine-tuning covers MNLI and QQP from GLUE, SQuAD 1.1 and SQuAD 2.0, and the RACE reading comprehension dataset. Batch size and learning rate are tuned first, and development-set medians over 5 random seeds are reported. For RACE test results, the checkpoint is the one at the median development score across the 5 seeds, and 5-way ensembles are reported for SQuAD development and RACE test.

The trained-token ratio column gives 1 for the Megatron rows and 2 or 3 for the other models, so the comparison is not matched on training tokens. The authors report the 3.9B model as state of the art on the development sets among the BERT-based models in the table.

Limits of the evidence

The 3.9B BERT model was still training after 1.5 million iterations when its results were taken. Model+data parallelism lowers scaling a little because of the extra gradient communication. The authors state that training beyond 16 billion parameters would need more memory than 16 GPUs of one DGX-2H server provide, and suggest hybrid intra-layer and inter-layer model parallelism with inter-node parallelism for such sizes.

The GPT-2 results are zero-shot evaluations, and no fine-tuning of those models is reported. The scaling study covers up to 512 GPUs and model-parallel sizes from 1 to 8 GPUs. Head count affects scaling slightly, with efficiency falling from 82% to 77% between 16 and 32 heads. Speedup of the 1.2B model shows diminishing returns beyond two GPUs, with 1.64 on two GPUs and 2.98 on eight.

Paper info

Authors
Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, Bryan Catanzaro
Venue
arXiv · Preprint
First published
2019-9-17
Added
2026-10-20
Updated
2020-3-13
Version
v4
arXiv
1909.08053
Category
cs.CL
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, Bryan Catanzaro (2019). Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism. arXiv:1909.08053v4. https://arxiv.org/abs/1909.08053v4

BibTeX
@misc{shoeybi2019megatron,
  title = {{Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism}},
  author = {Mohammad Shoeybi and Mostofa Patwary and Raul Puri and Patrick LeGresley and Jared Casper and Bryan Catanzaro},
  year = {2019},
  eprint = {1909.08053},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1909.08053v4}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up