Project: PyTorch-native bridge between Hugging Face and Megatron-Core. Bidirectional checkpoint conversion, pretraining, SFT, and LoRA recipes with optimized NVIDIA GPU performance. Package:
megatron.bridge(Python 3.12).
The skills/ directory contains structured guides for common tasks (adding
models, running experiments, debugging multi-node jobs, performance tuning,
etc.). Always read the relevant SKILL.md before starting any task it
covers — skills are mandatory context, not optional background reading.
Workflow — mandatory order for every task:
- Pull information first. Read the commit, PR, error log, file, or whatever artifact the task is about. Do not reason about it yet.
- Select and invoke the skill. Based on what you just read, identify the relevant skill and invoke it before forming any answer or plan.
- Answer or implement. Only after the skill is loaded, use its context to reason, diagnose, or write code.
Never skip or reorder these steps. Do not wait for the user to name the right skill keyword — infer it from the artifact you read.
NEVER:
- Modify files inside
3rdparty/Megatron-LM/— changes go through the upstream repo - Run the full test suite — run only the specific tests relevant to your change
- Add required (non-optional) dependencies — use optional extras; submit dependency changes as a separate PR
- Commit secrets, tokens,
.envfiles, or environment-specific paths / account names (e.g./home/yuya/…, usernames, cluster hostnames) - Use bare
print()— uselogging.getLogger(__name__)orprint_rank_0()
ASK FIRST:
- Before adding any new dependency to
pyproject.toml - Before modifying CI workflows (
.github/workflows/) - Before changing public API signatures in
models/conversion/
ALWAYS:
- Run
uv run pre-commit run --all-filesbefore committing - Add NVIDIA copyright headers to new Python files (except under
tests/) - Sign off commits:
git commit -s -m "message" - Use
uv run python -m pytestanduv run python -m torch.distributed.run, not barepytest/torchrun - Use the current year (2026) in generated content — do not default to 2025 or any past year
| Action | Command | Config |
|---|---|---|
| Install deps | uv sync |
pyproject.toml, uv.lock |
| Install dev tools | uv sync --group dev |
|
| Lint + format | uv run pre-commit run --all-files |
ruff.toml, .pre-commit-config.yaml |
| Unit tests | uv run python -m pytest tests/unit_tests/ |
pyproject.toml [tool.pytest] |
| Distributed run | uv run python -m torch.distributed.run --nproc_per_node=2 script.py |
|
| Type check | uv run mypy --strict path/to/file.py |
|
| Regen lock file | uv lock |
|
| Init submodule | git submodule update --init |
.gitmodules |
Lint and format are enforced by pre-commit hooks (ruff). See @ruff.toml for the authoritative rules. For judgment calls not covered by tooling, see @skills/linting-and-formatting/SKILL.md. Key points the linter cannot catch:
- Type hints required on all public API functions (
X | None, notOptional[X]) - Google-style docstrings on public classes and functions
- Use
*separator for functions with multiple same-type parameters - No arbitrary defaults for config values — be explicit
- No foreign
setattron config dataclasses in tests. When a test applies overrides to a recipe config viasetattr(config_obj, key, value), always guard withif not hasattr(config_obj, key): raise ValueError(...)first. Setting an attribute that does not exist on the dataclass silently creates a phantom field — the test passes but the recipe would fail for a real user who never sets that key. This applies to all override patterns (model_overrides,checkpoint_overrides,config_overrides, etc.) intests/functional_tests/.
See @CONTRIBUTING.md for the full contributor guide, including:
- Commit and PR title format (Conventional Commits:
<type>(<scope>): <description>) - PR labeling taxonomy (type, area, state, risk labels)
- Testing conventions (unit preferred, functional max 2 GPUs, L0/L1/L2 tiers)
- Dependency management policy
- DCO sign-off requirements
- CI triggering (
/ok to test <commit-SHA>)
Each supported model family lives under src/megatron/bridge/models/<family>/ with:
| File | Role |
|---|---|
bridge.py |
HF ↔ Megatron conversion logic |
config_mapping.py |
Maps HF config → Megatron config |
param_mapping.py |
Maps parameter names between formats |
hf_pretrained/ |
HF model definition provider |
Recipes live in src/megatron/bridge/recipes/<family>/.
AutoBridge (models/conversion/auto_bridge.py) auto-selects the correct
bridge from a HF model name or path.
3rdparty/Megatron-LM/ is a git submodule pinned to a specific commit,
installed as an editable package via [tool.uv.sources] in pyproject.toml.
Use scripts/switch_mcore.sh to switch versions.
This file is the single source of agent instructions. For Claude Code
compatibility, create a symlink: ln -s AGENTS.md CLAUDE.md