Skip to main content

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}
}

Release files for megatron-core 0.19.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for megatron-core 0.19.2
File Size Uploaded
megatron_core-0.19.2.tar.gz 2.0 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for megatron-core 0.19.2
File
megatron_core-0.19.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
megatron_core-0.19.2-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details
megatron_core-0.19.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
megatron_core-0.19.2-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
megatron_core-0.19.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
megatron_core-0.19.2-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details

Total release size: 16.2 MB

Release files / megatron_core-0.19.2.tar.gz

Download URL megatron_core-0.19.2.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
de643eee32007a7504ad52f061103fe7432503603b6321c16c861eb67dbd3353
BLAKE2b-256 checksum
How to use checksums
312999972ea43de5d22afcdda2f31f21599fbcea527dbfedfaf3638250a13163
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL megatron_core-0.19.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
10c70ab5273457f3c8232e35bc18633aa20abc6f6ac2d190914acd6323537826
BLAKE2b-256 checksum
How to use checksums
fcbcac954943dfc487ca1b5acc7db38488b9867620725d1266d164463b370e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL megatron_core-0.19.2-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 2.4 MB
Tags CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
346872950e729433c9477c59b5456b859fb7e457a1c0bb39c0c771c302a1d1ea
BLAKE2b-256 checksum
How to use checksums
594d7e167eef9b8071c725bdade337321daf5941dc11afbbb71a50a7ccd70f4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL megatron_core-0.19.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8e3e486f13f559450415b9b9dc0ff3331a0bb83dd154553f7f350a75ff9c42b5
BLAKE2b-256 checksum
How to use checksums
f57c80fa3726cef258d08b51a9ce879dbe5186e822e99863d55c7a7dd6fbdd62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL megatron_core-0.19.2-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 2.4 MB
Tags CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
e1717c0cdb7669d2112c3f3d80a2e748d2721b4798044d750cab5a3b2dffe38f
BLAKE2b-256 checksum
How to use checksums
875e3aec08bf64c83cf434794684833cde4f9af196aab2021f62e97462d433fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL megatron_core-0.19.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3be561cb9c4789e062a43147d3e8632b0750e1f9bbf7aa9f5d8d518b1205951b
BLAKE2b-256 checksum
How to use checksums
dabf850fb71d37844fd191f8e5f4620c45d93d0947c570ac421be6773d28434c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / megatron_core-0.19.2-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL megatron_core-0.19.2-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 2.4 MB
Tags CPython 3.11 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
dd5f0eae3a141889901a0e58b54e520511a8c1faee2f7c12468b83271bc68ce1
BLAKE2b-256 checksum
How to use checksums
e1e0ff960e3adb8f598c034571a5a06fb02b889a1e0c5f884d56f1a94921716d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.19.2 This release

7 release files

0.19.1

7 release files

0.19.0

7 release files

0.18.2

7 release files

0.18.1

7 release files

0.18.0

7 release files

0.17.1

7 release files

0.17.0

7 release files

0.16.1

9 release files

0.16.0

9 release files

0.15.0

9 release files

0.13.1

5 release files

0.13.0

5 release files

0.12.3

5 release files

0.12.1

5 release files

0.11.0

5 release files

0.10.0

3 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page