Megatron-LM is NVIDIA's library for training transformer models at scale on GPU clusters. It bundles two parts: Megatron-LM, a reference example with pre-configured training scripts for research teams and quick experimentation, and Megatron Core, a composable library of GPU-optimized building blocks (transformer layers, parallelism strategies, mixed precision kernels) for engineers building custom training pipelines. It's built for ML infrastructure engineers, researchers training large language models, and teams working on mixture-of-experts or hybrid architectures who need control over distributed training internals.
megatron/core/distributed/.megatron/post_training/.megatron/rl/ for post-training alignment workflows.Megatron-LM fits teams training large transformer models (billions of parameters and up) across multi-GPU or multi-node GPU clusters, where you need fine control over parallelism and memory to hit target throughput. It's a strong fit for research groups experimenting with new architectures (MoE, hybrid transformer-Mamba) or optimizers, and for infrastructure teams building their own training stack on top of Megatron Core's building blocks.
It's not the right tool if you're fine-tuning a small model on a single GPU or a handful of GPUs, where simpler frameworks (Hugging Face Transformers, PyTorch Lightning) involve far less setup. It also assumes familiarity with distributed training concepts; teams new to multi-GPU training will face a learning curve around parallelism configuration, NCCL communication, and cluster scheduling.
Install Megatron Core from PyPI:
uv pip install megatron-core
Or clone the repository and install from source:
git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
uv pip install -e .
Building from source can consume significant memory. If the build runs out of memory, limit parallel compilation jobs:
MAX_JOBS=4 uv pip install -e .
For NVIDIA GPU Cloud (NGC) container setup and the full list of installation options, check the official Installation Guide linked from the repository's documentation site. After installing, the documentation's "Your First Training Run" guide walks through end-to-end training with data preparation, and the "Parallelism Strategies" guide covers configuring TP, PP, DP, EP, and CP for your cluster size.