Megatron-LM

NVIDIA活跃维护

NVIDIA 的大规模 Transformer 训练框架,支持张量并行、流水线并行等模型并行策略,用来在成百上千张 GPU 上高效预训练大语言模型。

Ongoing research training transformer models at scale

core_v0.20.0发布于 2026-10-29 21:06 UTC18,365star +17 / 7 天4,723fork同步于 2026-11-10 11:24 UTC

怎么上手

由 README 提炼,执行前请确认
uv pip install megatron-core
硬件要求按 README 说明

README 未说明具体显存要求;基准测试基于 DGX-GB300、DGX-GB200 等 NVIDIA GPU 系统,未提及 CPU 运行或非 NVIDIA 厂商支持

需要 CUDA多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

NVIDIA 的大规模 Transformer 训练库,提供 GPU 优化的并行训练组件与参考脚本

NVIDIA 的大规模 Transformer 训练框架,支持张量并行、流水线并行等模型并行策略,用来在成百上千张 GPU 上高效预训练大语言模型。

核心能力

  • 提供 TP、PP、DP、EP、CP 多种并行策略
  • 支持 FP16、BF16、FP8、FP4 混合精度训练
  • 以可组合库形式提供 Transformer 构建块与模型架构
  • 内置分布式 checkpoint 保存、加载与重分片
  • 附带预配置训练脚本与现成训练示例

容易踩的坑

需 Python 3.12+ 与 PyTorch 2.6.0+,版本不匹配会出问题;源码编译内存占用大,OOM 时需设 MAX_JOBS 限制并行编译;与 Hugging Face 权重互转需另装 Megatron Bridge

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本core_v0.20.0
  1. core_v0.20.0NVIDIA Megatron Core 0.20.0最新正式版2026-10-29 · 2026-10-29 21:06 UTC
    MoE
    • DeepEP v2 dispatcher: adds an experimental DeepEP v2 backend for the flex token dispatcher (#5153).
    • NCCL EP MXFP8 communication (experimental): adds MXFP8 dispatch-forward and combine-backward communication to the NCCL EP backend (#6524).
    • NCCL EP eager mode: now NCCL EP supports both eager mode and full-iteration graph mode (#6229).
    • ShortcutMoE: adds shortcut-connected routing in HybridStack and overlaps expert all-to-all communication with paired attention or Mamba computation; CUDA graphs are not supported (#6959).
    Model Architecture and Support
    • DeepSeek V4: fully supported by the next-gen HybridModel class (#6403, #6404, #6405, #7469).
    • Manifold-constrained hyper-connections (mHC): adds fused mHC connections to HybridModel, including pipeline and virtual-pipeline parallel support (#6401, #7336).
    • Gated Delta Product (GDP): adds GDP layers and model-building support for hybrid architectures (#6074).
    • Wide residual streams: adds streamwise residual connections, selective residual-stream recomputation, and integration with MTP and MIMO; currently requires PP=1 and CUDA graphs disabled (#6716, #6805, #6855, #7440).
    • MTP-only training: adds a mode that freezes the base model and trains only Multi-Token Prediction heads (#7021).
    Parallelism
    • Megatron-FSDP v2 integration: adds the experimental Megatron Core adapter and Megatron Bridge, with context, expert, pipeline, and hybrid data-parallel sharding support; the adapter requires TP=1 and expert TP=1 (#5865, #6450, #6486, #7220, #6873).
    • Megatron-FSDP v2 checkpointing: adds PyTorch distributed checkpoint save/load for model and optimizer state; optimizer checkpointing currently excludes expert-parallel layouts (#6024, #6215).
    • Megatron-FSDP v2 supports hybrid FSDP.
      • The user can specify different ZeRO levels for inter-nvlink domains and intra-nvlink domains.
      • The user can specify different configs for the dense section and the MoE section.
    • Generalized Tensor Parallelism (GTP): adds configurable batch/sequence partitioning, opt-in latent-projection sharding, and MTP support (#7748, #6383, #6242).
    Performance and Memory
    • Determinism: multi-release effort, please read our blog post to learn more
    • Megatron-FSDP v2 CUDA graphs: adds full-iteration graph capture and replay for supported dense-model configurations ([#7075](https://github.com/NVIDIA/Me
  2. 26.09-lambda.rc12026-10-13 · 2026-10-13 11:34 UTC

    这个版本没有写更新说明。

  3. 26.09-alpha.rc32026-10-13 · 2026-10-13 08:10 UTC

    这个版本没有写更新说明。

  4. 26.09-alpha.rc22026-10-08 · 2026-10-08 17:51 UTC

    这个版本没有写更新说明。

  5. 26.09-alpha.rc12026-10-06 · 2026-10-06 09:08 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Megatron-LM and Megatron Core

    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

    Compatibility: Python 3.12+ and PyTorch 2.6.0+ recommended. For source development, the tested NGC PyTorch base images are pinned in docker/.ngc_version.dev and docker/.ngc_version.lts.

    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, hybrid, and multimodal models
    │   │   ├── transformer/         # Transformer building blocks
    │   │   ├── tensor_parallel/     # Tensor parallelism
    │   │   ├── pipeline_parallel/   # Pipeline parallelism
    │   │   ├── context_parallel/    # Context parallelism
    │   │   ├── distributed/         # Distributed training (Megatron FSDP, DDP)
    │   │   ├── dist_checkpointing/  # Distributed checkpoint saving, loading, and resharding
    │   │   ├── optimizer/           # Optimizers
    │   │   ├── datasets/            # Dataset loaders
    │   │   ├── inference/           # Inference engines and server
    │   │   └── export/              # Model export (example: TensorRT-LLM)
    │   ├── training/                # Training scripts
    │   └── post_training/           # Post-training (quantization, distillation, pruning, etc.)
    └── examples/                    # Ready-to-use training examples
    

    Performance Benchmarking

    The NVIDIA Megatron Bridge Performance Summary publishes training throughput, system configurations, parallelism settings, and links to performance recipes and reproduction instructions. Use the container and matching code version specified by those instructions when reproducing a result.

    Selected results from the 26.08.01 NeMo container (August 2026):

    ModelSystemGPUsPrecisionSequence lengthTokens/s/GPUModel TFLOPs/s/GPU
    DeepSeek-V3DGX-GB300256MXFP84,0966,2881,636
    DeepSeek-V3DGX-GB200256MXFP84,0964,9121,277
    Qwen3-235B-A22BDGX-GB300256MXFP84,0968,8321,306
    Nemotron 3 UltraDGX-GB300256NVFP48,1923,7441,348

    See the summary for the full batch sizes and parallelism configurations. MoE benchmarks use force-balanced expert routing and do not drop tokens. These results measure performance under the published benchmark conditions; throughput depends on the model, precision, hardware, and configuration.

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