Megatron-LM Contribution Recipe
This is a provisional project skill, refreshed from main at
1cb3264
on 2026-08-31. Apply the shared Skippy contribution protocol as well.
Hard gates
- Read the current upstream
AGENTS.mdand invoke the relevant upstreamskills/*/SKILL.mdbefore planning or editing. For testing, formatting, or CI, usemcore-testing,mcore-linting-and-formatting, ormcore-cicdrespectively. - Refresh the contribution guide, issue/PR templates, current issue/PR overlap, and current
mainbefore selecting work. Small bug fixes are welcome; large architecture or style changes require an issue discussion first. - Work from a personal fork. Never push to
NVIDIA/Megatron-LM; open every PR as a draft. Commits require both-sand-S. - Prefer one independently reproducible bug or narrow improvement. New features require a linked issue; a linked issue is recommended for small fixes. Do not undertake old reports until they reproduce on current
main. - In
megatron/coreproduction code, do not add direct global process-group reads fromparallel_state; pass aProcessGroupCollectionor explicit process group from the caller instead. The explicit compatibility exceptions inAGENTS.mdapply.
Repository shape and ownership
megatron/core/is the composable library: models, transformer blocks, parallelism, distributed systems, optimizers, datasets, inference, and export.megatron/training/owns reference training scripts;megatron/legacy/,megatron/post_training/, andmegatron/rl/carry respective compatibility, post-training, and RL paths.- Root
pretrain_*.py,train_rl.py, and model provider files are training/recipe entrypoints.examples/,tools/,tests/, anddocs/own examples, utilities, validation, and documentation. Trace callers and nearby tests before choosing an owner.
Toolchain and validation
- Python package
megatron-corerequires Python>=3.12; use theuv-managed environment described inpyproject.toml. Source installation isuv pip install -e .; full builds are GPU/container intensive. - Run the narrowest relevant test first. Unit tests are GPU distributed:
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q <path>. Usetests/unit_tests/run_ci_test.shfor CI-bucket parity. Functional changes need the nearest recipe undertests/test_utils/recipes/and may require golden values. - Before a PR, run
BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh; after Python import edits also runuv run isort <files>. The formatter path invokes black, isort, pylint, ruff, and mypy. - CI scopes are label-driven: default slim suite;
Run testsfor a lightweight L1 test run;Run functional testsfor numerical/training-affecting changes or new test cases. Only attachcontainer::ltson an explicit request.
Delivery and maintenance
- Use the connected GitHub app for live PR and issue inspection when local
ghauthentication is invalid; it is independently authenticated as the contributor. Do not treat a failinggh auth statusas proof that read-only GitHub access is unavailable. - Use the PR template: author line review, state purpose and linked issue, test/typing/docs checks, then leave the draft only after conflicts are resolved and CI passes.
- Reconcile every authored PR before replenishing. Read review and CI state, handle concrete action items, and do not treat stale or pending-workflow PRs as healthy. The project marks untouched PRs stale after 60 days.
- Before merge, check for PRs based on
pull-request/<PR number>and retarget them tomain.
Queue policy
The user has not set a target, so use Skippy's provisional default of five healthy open PRs. The repository/contributor maximum is currently unknown and must be checked before publishing. See references/queue-policy.md and references/bootstrap-report.md.