Installation#

Megatron Core can be installed from PyPI, built from source, or run inside an NGC container. Choose the method that best fits your workflow. PyPI is the simplest path for most users, source installs suit active development, and the NGC container provides a fully configured environment with no manual dependency management.

System Requirements#

Hardware#

  • Recommended: NVIDIA Turing architecture or later

  • FP8 Support: Requires NVIDIA Hopper, Ada, or Blackwell GPUs

Software#

  • Python: >= 3.10 (3.12 recommended)

  • PyTorch: >= 2.6.0

  • CUDA Toolkit: Latest stable version

Prerequisites#

Install uv, a fast Python package installer:

curl -LsSf https://astral.sh/uv/install.sh | sh

Option B: Install from Source#

Use a source install to contribute changes, run unreleased features, or step through the code during debugging. This clones the repository and installs the package in editable mode.

git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
uv pip install -e .

To install with all development dependencies (includes Transformer Engine, requires pre-installed build dependencies):

uv pip install --group build
uv pip install --no-build-isolation -e ".[training,dev]"

Tip

If the build runs out of memory, limit parallel compilation jobs with MAX_JOBS=4 uv pip install --no-build-isolation -e ".[training,dev]".

Option C: NVIDIA GPU Cloud (NGC) Container#

For a pre-configured environment with all dependencies pre-installed (PyTorch, CUDA, cuDNN, NCCL, and Transformer Engine), use the PyTorch NGC Container.

Use the previous month’s NGC container rather than the latest one to ensure compatibility with the current Megatron Core release and testing matrix.

docker run --gpus all -it --rm \
  -v /path/to/dataset:/workspace/dataset \
  -v /path/to/checkpoints:/workspace/checkpoints \
  -e PIP_CONSTRAINT= \
  nvcr.io/nvidia/pytorch:26.01-py3

Note

The NGC PyTorch container constrains the Python environment globally using PIP_CONSTRAINT. The -e PIP_CONSTRAINT= flag above unsets this so that Megatron Core and its dependencies install correctly.

Then install Megatron Core inside the container (torch is already available in the NGC image):

pip install uv
uv pip install --no-build-isolation "megatron-core[training,dev]"

You are now ready to run training. Refer to Your First Training Run for next steps.