Megatron-LM README

The project's README from github.com/NVIDIA/Megatron-LM. As one markdown file: README.md.

Megatron-LM and Megatron Core

GPU-optimized library for training transformer models at scale

Documentation version license

About

This repository contains two components: Megatron-LM and Megatron Core.

Megatron-LM is a reference example that includes Megatron Core plus pre-configured training scripts, ideal for research teams, learning distributed training, and quick experimentation.

Megatron Core is a composable library with GPU-optimized building blocks for custom training frameworks. It provides transformer building blocks, advanced parallelism strategies (TP, PP, DP, EP, and CP), mixed precision support (FP16, BF16, FP8, and FP4), and model architectures, ideal for framework developers and ML engineers building custom training pipelines.

Megatron Bridge provides bidirectional Hugging Face ↔ Megatron checkpoint conversion with production-ready recipes.

Getting Started

Install from PyPI:

uv pip install megatron-core

Or clone and install from source:

git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
uv pip install -e .

Note: Building from source can use a lot of memory. If the build runs out of memory, limit parallel compilation jobs by setting MAX_JOBS (for example, MAX_JOBS=4 uv pip install -e .).

For NVIDIA GPU Cloud (NGC) container setup and all installation options, review the Installation Guide.

Latest News

Previous News

Project Structure

Megatron-LM/
├── megatron/
│   ├── core/                    # Megatron Core (kernels, parallelism, building blocks)
│   │   ├── models/              # Transformer models
│   │   ├── transformer/         # Transformer building blocks
│   │   ├── tensor_parallel/     # Tensor parallelism
│   │   ├── pipeline_parallel/   # Pipeline parallelism
│   │   ├── distributed/         # Distributed training (FSDP, DDP)
│   │   ├── optimizer/           # Optimizers
│   │   ├── datasets/            # Dataset loaders
│   │   ├── inference/           # Inference engines and server
│   │   └── export/              # Model export (example: TensorRT-LLM)
│   ├── training/                # Training scripts
│   ├── legacy/                  # Legacy components
│   ├── post_training/           # Post-training (quantization, distillation, pruning, etc.)
│   └── rl/                      # Reinforcement learning (including RLHF)
├── examples/                    # Ready-to-use training examples
├── tools/                       # Utility tools
├── tests/                       # Comprehensive test suite
└── docs/                        # Documentation

Performance Benchmarking

For the latest performance benchmarking results, refer to NVIDIA Megatron Bridge Performance Summary.

The codebase efficiently trains models from 2B to 462B parameters across thousands of GPUs, achieving up to 47% Model FLOP Utilization (MFU) on H100 clusters.

Model table

Benchmark Configuration:

  • Vocabulary size: 131,072 tokens
  • Sequence length: 4,096 tokens
  • Model scaling: Varied hidden size, attention heads, and layers to achieve target parameter counts
  • Communication optimizations: Fine-grained overlapping with DP (--overlap-grad-reduce, --overlap-param-gather), TP (--tp-comm-overlap), and PP (enabled by default)

Key Results:

  • 6,144 H100 GPUs: Successfully benchmarked 462B parameter model training.
  • Superlinear scaling: MFU increases from 41% to 47–48% with model size.
  • End-to-end measurement: Throughputs include all operations (data loading, optimizer steps, communication, and logging).
  • Production ready: Full training pipeline with checkpointing and fault tolerance.
  • Note: Performance results measured without training to convergence

Weak Scaling Results

The weak scaled results show superlinear scaling (MFU increases from 41% for the smallest model considered to 47–48% for the largest models); this is because larger GEMMs have higher arithmetic intensity and are consequently more efficient to execute.

Weak scaling

Strong Scaling Results

This test strong scales the standard GPT-3 model (slightly more than 175 billion parameters due to larger vocabulary size) from 96 H100 GPUs to 4,608 GPUs, using the same batch size of 1,152 sequences throughout. Communication becomes more exposed at larger scale, leading to a reduction in MFU from 47% to 42%.

Strong scaling

Roadmaps

Resources

Getting Help

  • 📖 Documentation - Official guides and API reference
  • 🐛 Issues - Bug reports and feature requests

Contributing

Contributions are welcome. Ways to contribute:

  • 🐛 Report bugs - Help improve reliability
  • 💡 Suggest features - Shape the future of Megatron Core
  • 📝 Improve docs - Make Megatron Core more accessible
  • 🔧 Submit PRs - Contribute code improvements

→ Contributing Guide

Citation

If you use Megatron in your research or project, use the following citation:

@article{megatron-lm,
  title={Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism},
  author={Shoeybi, Mohammad and Patwary, Mostofa and Puri, Raul and LeGresley, Patrick and Casper, Jared and Catanzaro, Bryan},
  journal={arXiv preprint arXiv:1909.08053},
  year={2019}
}

Megatron-LM (NVIDIA/Megatron-LM)

Searching Database…

What is this?NVIDIA's open-source toolkit for training large transformer (LLM) models at scale. It comes as Megatron-LM, a reference setup with ready training scripts, and Megatron Core, a composable library of GPU-optimized building blocks for training models across thousands of GPUs.
Is it one library or several components?Two components in one repo: Megatron-LM is a reference example with pre-configured training scripts, while Megatron Core is a composable library meant to be built into custom training frameworks. A separate tool, Megatron Bridge, converts checkpoints between Hugging Face and Megatron formats.
How do I get it installed?Install from PyPI, or clone the repo and install from source. Source builds are memory-hungry, so if compilation runs out of memory cap the parallel jobs, e.g. MAXJOBS=4 uv pip install -e . NVIDIA's NGC containers and the Installation Guide cover the remaining options, and a Your First Training Run guide picks up from there.
Any version or compatibility gotchas I should know about?Python 3.10 support is going away: the upcoming 0.17.0 release requires Python 3.12 or newer, so downstream projects must raise their floor. Building from source can also exhaust memory on modest machines.
Who is this for — researchers or framework developers?Both, split by component: research teams learning distributed training and running quick experiments use the ready-made Megatron-LM scripts, while framework developers and ML engineers building custom training pipelines use Megatron Core's building blocks.
Do I need NVIDIA hardware to run this, or will any GPU do?It is built and benchmarked around NVIDIA GPUs only — the published results are on H100 clusters, up to 6,144 GPUs for a 462B-parameter model. The largest runs assume a multi-node cluster, not a single machine.
How large are the models it has been benchmarked with?The published benchmarks train 2B to 462B parameter models on clusters of up to 6,144 H100 GPUs, reaching 47-48% Model FLOP Utilization at the top end, with production features like checkpointing and fault tolerance included in the measured throughput.
How does it split training work across thousands of GPUs?Through five parallelism strategies: tensor, pipeline, data, expert and context parallelism (TP, PP, DP, EP, CP), combined with FP16, BF16, FP8 and FP4 mixed precision. Dynamic Context Parallelism adds up to 1.48x speedup for variable-length sequence training.
Can I bring in Hugging Face checkpoints?Yes. Megatron Bridge converts checkpoints bidirectionally between Hugging Face and Megatron formats and ships production-ready recipes for popular models, including conversion, inference and pretraining recipes for DeepSeek-V4.
Which recent models does it support?Recent releases add initial DeepSeek-V4 support, optimized MoE recipes for DeepSeek-V3, Mixtral and Qwen3, the Falcon-H1 hybrid transformer-Mamba architecture with BitNet ternary quantization, and GPT-OSS features like YaRN RoPE scaling and attention sinks.
What are similar projects?TensorRT-LLM, halo, DMI, LittleBit, verl, Meshy, Intern-Decision, airllm
Creator
NVIDIA
Size
154.9 MB
Stars
18.2K
Age
7y
Commits · 90 Days