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

Metadata

Release files for megatron-core 0.20.1

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.20.1
File Size Uploaded Provenance Actions
megatron_core-0.20.1.tar.gz 2.8 MB Without provenance Details for megatron_core-0.20.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for megatron-core 0.20.1
File Actions
megatron_core-0.20.1-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 for megatron_core-0.20.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
megatron_core-0.20.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details for megatron_core-0.20.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
megatron_core-0.20.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for megatron_core-0.20.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
megatron_core-0.20.1-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 for megatron_core-0.20.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
megatron_core-0.20.1-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 for megatron_core-0.20.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
megatron_core-0.20.1-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 for megatron_core-0.20.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Total release size: 22.9 MB

Release files / megatron_core-0.20.1.tar.gz

Download URL megatron_core-0.20.1.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
21dbbe6a85eb569352663e4719f78e00f440faef8bb3e5189d903f820badac94
BLAKE2b-256 checksum
How to use checksums
a867e251f5c504c969bd39ac9fafe99d31058c5b59cd00f41ac8ec5dcbd548d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL megatron_core-0.20.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 3.3 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5deebd14740e8ee73cfb018da915db3e1fe482b3f0676778ff3c3062c86d1582
BLAKE2b-256 checksum
How to use checksums
44f1f439a037457c17d01552a23276b4d538ff9742617b434a4eee80513c4821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL megatron_core-0.20.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 3.3 MB
Tags CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
5519bf994dd236eb507aafb11cd69e0c7fc05f548918546c7fa3eabcc7e034b5
BLAKE2b-256 checksum
How to use checksums
5c97f8494ec1a155d97f27805bb7eee37e6666e0a7721971389f88b14f64d713
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL megatron_core-0.20.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 3.3 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3269c164189489dac7994a5d97e1e8163667d00d952538f1866c39bae815cd08
BLAKE2b-256 checksum
How to use checksums
e55492fc0632311b27d8aaa856ab5cd89efce3bb5c3f7c13b745f4ee14c0726d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL megatron_core-0.20.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 3.3 MB
Tags CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
dbe84d1e6702886d3fbc9a5b116128537feba034538ddf56d3a9fa9f6c940d86
BLAKE2b-256 checksum
How to use checksums
0e845c667be72533255af5f9386de11631a861a898b3d886395f63e5218bf194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL megatron_core-0.20.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 3.3 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a100291d1b1d2314f734b971481dc845f4536019e4c73b6097dc4cd353f29908
BLAKE2b-256 checksum
How to use checksums
90a3c3083dcc241bf5559adbb9ea3c4d047393a90202e6d67ae2ac3859027c85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

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

Security for megatron-core 0.20.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.1 This release

7 release files No provenance

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