Skip to content

[ckpt, build] fix: support pip-installed conversion on Megatron-Core 0.18.x - #5193

Open
yaoyu-33 wants to merge 29 commits into
mainfrom
yuya/mcore-018-compat
Open

yaoyu-33 wants to merge 29 commits into
mainfrom
yuya/mcore-018-compat

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Makes a pip-installed Megatron Bridge work against the released Megatron-Core 0.18.x line, not just the exact source pin. This is a concrete step toward #5148.

Current main pins Megatron-Core commit 24bad8e677 (0.20.0), while the public PyPI index currently ends at 0.18.2: there is no public 0.19.x or 0.20.x package to install. The supported pip range is therefore declared explicitly as >=0.18.0,<0.21 and tested against both the current source pin and the actual public 0.18.x line.

On 0.18.x, megatron.training.models.gpt does not exist. Without this change, that missing module breaks megatron.bridge.training and every checkpoint import/export path that depends on it.

How

  • megatron.bridge.compat.mcore_version declares the public compatibility floor (0.18.0), current source pin (0.20.0), and exclusive next-minor ceiling (0.21). Tests keep the source gitlink, code declaration, and package metadata aligned.
  • megatron.bridge.compat.mcore_gpt is the stable facade for GPT builder/config symbols and serialized targets. It prefers the upstream implementation when present and uses the vendored fallback only when the whole upstream module is absent; unrelated transitive import errors still propagate.
  • The fallback is refreshed from the current 0.20 GPT implementation. Its model-builder call projects the current arguments onto the callable exposed by older MCore releases, including omitting the new layerwise optimizer/layout arguments on 0.18.x.
  • All current-main consumers, including the newer GPT model-config path, import through the facade. Legacy upstream serialized targets are normalized when loading existing run configs.
  • Package metadata and user documentation now state megatron-core[dev,mlm]>=0.18.0,<0.21.

No file under 3rdparty/Megatron-LM is modified, no dependency is added, and no public conversion API signature changes.

Validation

Standard project container with uv:

Environment Result
Current source pin (0.20.0) 822 Bridge modules imported; focused compatibility/version/model load-save/conversion matrix passed (100 tests), with one separately identified workstation-driver-only NCCL mock failure
Exact public PyPI 0.18.0 822 Bridge modules imported with zero failures; 94 focused tests passed, 6 expected upstream-parity tests skipped, workstation-only NCCL case deselected
Exact public PyPI 0.18.2 822 Bridge modules imported with zero failures; 94 focused tests passed, 6 expected upstream-parity tests skipped, workstation-only NCCL case deselected
Built wheel METADATA contains megatron-core[dev,mlm]<0.21,>=0.18.0

The focused matrix covers support boundaries, facade/fallback selection, upstream API parity, old-builder argument projection, stable and legacy config targets, checkpoint load/save, CPU conversion launcher paths, and a tiny exact HF→MCore→HF tied/untied-logit roundtrip.

Authoritative Qwen3-30B-A3B verification card, on one 8-GPU node with exact public MCore 0.18.0 and model revision ad44e777bcd18fa416d9da3bd8f70d33ebb85d39:

  • TP4/PP2/EP4 HF→Megatron import completed all 3,411 mappings and wrote the distributed checkpoint.
  • The pinned HF/MCore forward comparison predicted token 12095 (" Paris") on both paths; cosine similarity was 0.999317 (card gate >0.99), with the card-recorded max/mean logit diagnostics 0.593750 / 0.130064.
  • Two independent imported-checkpoint generation runs completed exactly 32 tokens with the card's byte-identical expected text.
  • TP4/PP2/EP4 distributed Megatron→HF export completed all 3,411 mappings.
  • Strict roundtrip verification compared all 18,867 BF16 tensors: exact key, shape, dtype, and bitwise value equality. The export reloaded as Qwen3MoeForCausalLM, and norm_topk_prob remained true.

uv run pre-commit run --all-files passed before every new DCO-signed merge/conflict-resolution commit.

Main integration

Latest main was merged normally into this branch without rebasing or force-pushing. Conflicts were resolved by retaining current main's optional ModelOpt behavior and tests while routing its new GPT model-config consumer through the compatibility facade.

Refs #5148

…0.18.x

Bridge only worked against the exact Megatron-Core commit pinned in
3rdparty/Megatron-LM. On the released 0.18.x line, 64 of the 806
megatron.bridge modules failed to import because megatron.training.models.gpt
(GPTModelConfig / GPTModelBuilder / mtp_block_spec) was added upstream after
0.18.x was cut, which broke every checkpoint save/load path — including
AutoBridge.import_ckpt and export_ckpt.

Declare the supported window as a rule relative to the pin (previous minor
release N-1 through the next minor, i.e. >=0.18.0,<0.20 for the 0.19.0 pin),
bound the megatron-core dependency to it so installing Bridge no longer
replaces a compatible preinstalled Megatron-Core, and fall back to a vendored
copy of megatron/training/models/gpt.py when the upstream module is absent.

Verified on 8xH100 against megatron-core 0.18.0 installed from PyPI with the
Qwen3-30B-A3B model card flow: HF -> Megatron load and generation,
AutoBridge.import_ckpt, generation from the Megatron checkpoint with EP=8, and
export_ckpt back to HF. All 806 bridge modules import on both 0.18.0 and the
0.19.0 pin.

Refs #5148

Signed-off-by: Yu Yao <yuya@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33 yaoyu-33 added area:build Dependencies, packaging, images, and environment setup area:ckpt Checkpoint conversion, loading, export, and save paths bug Something isn't working labels Jul 30, 2026
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 84c98ed

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 4dd6ae2

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 11605ee

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 5a21fa5

Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 386a429

Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 2f4b050

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 74cb7d3

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 2510618

@github-actions

Copy link
Copy Markdown
Contributor

Automatic Claude reviews have been retired. To request a pull-request review, post a comment containing:

/review

Add model=claude to use a Claude reviewer (the default is model=codex). mode=light|strict selects the review depth; for example, /review model=claude mode=strict. Comment /review help for all options.

@yaoyu-33

yaoyu-33 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7f9e9c6

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33

yaoyu-33 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9dff99c

@yaoyu-33

yaoyu-33 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0f6afa6

Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
@yaoyu-33

yaoyu-33 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 76c54d1

@yaoyu-33

yaoyu-33 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a4ba423

@yaoyu-33

yaoyu-33 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5cee906

@yaoyu-33

yaoyu-33 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5451d2e

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>

This branch was successfully deployed

1 active (outdated) and 1 inactive (outdated) deployments
test — 5451d2ed Deployed Oct 3, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #22478
public — a2990ba4 Deployed Aug 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #5133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:build Dependencies, packaging, images, and environment setup area:ckpt Checkpoint conversion, loading, export, and save paths bug Something isn't working full-test-suite needs-more-tests Requires additional L0 and L1 test coverage before merge needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants