megatron-core
Megatron Core - a library for efficient and scalable training of transformer based models
What it is and what it does
Megatron Core is a composable library of GPU-optimized building blocks for training transformer models across distributed systems. It provides modular components for tensor parallelism, pipeline parallelism, data parallelism, expert parallelism, and context parallelism, along with support for mixed precision training (FP16, BF16, FP8, FP4) and model architectures including GPT, BERT, and Mamba-based models. The library is designed for framework developers and ML engineers building custom training pipelines, not as a standalone training script.
The package depends on torch, numpy, and packaging, and is actively maintained by NVIDIA with recent releases including dynamic context parallelism and multi-data center training support. Precompiled wheels are available for modern Python versions. Performance benchmarks show up to 47% Model FLOP Utilization on H100 clusters when training models from 2B to 462B parameters.
Use it for:
- Build custom distributed training frameworks that need composable parallelism strategies and transformer building blocks.
- Scale transformer model training across thousands of GPUs with optimized communication and computation overlap.
- Implement mixed-precision training (FP16, BF16, FP8, FP4) for large language models to reduce memory and compute costs.
- Train variable-length sequence models using dynamic context parallelism for adaptive efficiency gains.
- Integrate advanced model architectures (GPT, BERT, Mamba) into production training pipelines with fault tolerance.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Megatron Core provides GPU-optimized building blocks and parallelism strategies for training large transformer models at scale, including tensor parallelism, pipeline parallelism, and mixed precision support.
Yes, if you are building a custom distributed training framework or scaling transformer training across multiple GPUs. The library is production-stable, actively maintained, permissively licensed, and has no known vulnerabilities. Install friction is moderate due to GPU/CUDA requirements and torch dependency. Not recommended for simple single-GPU training or inference-only use cases.
Install
megatron-core on PyPI
pip
pip install megatron-coreuv
uv add megatron-corepoetry
poetry add megatron-coreInstalling megatron-core
Before you install
Medium friction: precompiled wheels available for Python 3.11 and 3.12 on x86_64 and aarch64, but requires torch and numpy. Package now requires Python 3.12 or later.
License in practice
Apache 2.0 permissive license allows commercial use, modification, and redistribution with minimal restrictions, making it suitable for both research and production deployments.
Quickstart
pip install megatron-core
import torch
from megatron.core.models.gpt import GPTModel
from megatron.core.tensor_parallel import ColumnParallelLinear
Requires NVIDIA GPU(s) and torch compiled with CUDA support; building from source can consume significant memory—set MAX_JOBS environment variable if build fails.
Verify before relying
- Whether the package supports inference-only workflows or is primarily designed for training pipelines.
- Compatibility and integration requirements with specific NVIDIA GPU architectures beyond H100.
- Whether checkpoint conversion with Megatron Bridge is included or requires separate installation.
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.12) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 3 — torch, numpy, packaging |
| Maintenance | actively maintained — 24 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 208,041/month — #9,536 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: megatron_core-0.18.2-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; megatron_core-0.18.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; megatron_core-0.18.2-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; megatron_core-0.18.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; megatron_core-0.18.2-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; megatron_core-0.18.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Keywords: NLP, NLU, deep, gpu, language, learning, machine, nvidia, pytorch, torch, transformer
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
megatron-fsdpMegatron-FSDP implements Fully Sharded Data…
permissive · top 15,000 on PyPI
transformer-engine-cu12Accelerates Transformer model training and…
unclear · top 15,000 on PyPI
transformer-engineTransformer Engine accelerates Transformer…
unclear · top 15,000 on PyPI
transformer-engine-cu13Accelerates Transformer model training and…
unclear · top 15,000 on PyPI
fairscaleFairScale extends PyTorch with distributed…
permissive · top 15,000 on PyPI
deepspeedDeepSpeed is a distributed deep learning…
permissive · top 5,000 on PyPI
xformersXFormers provides reusable, composable building…
permissive · top 5,000 on PyPI
torchtitantorchtitan is a PyTorch-native platform for…
permissive · top 15,000 on PyPI
spmd-typesProvides type annotations and runtime checking…
permissive · top 15,000 on PyPI
nvidia-modeloptApplies state-of-the-art model optimization…
permissive · top 15,000 on PyPI