Skip to content

refactor(model): build Qwen2 and MiMo from builder-backed model configs - #6379

Open
kamran-nvidia wants to merge 2 commits into
mainfrom
kjafarisadeg/qwen2-mimo-model-config
Open

kamran-nvidia wants to merge 2 commits into
mainfrom
kjafarisadeg/qwen2-mimo-model-config

Conversation

@kamran-nvidia

@kamran-nvidia kamran-nvidia commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Moves Qwen2/Qwen2.5 and MiMo onto the builder-backed ModelConfig / ModelBuilder path, for recipes and checkpoint conversion, following Muse Glimmer and #6365 (Qwen3).

Builds on #6365 (merged). It reuses #6365's TransformerConfig YaRN fields, without which Qwen2.5 YaRN checkpoints could not convert through the builder. Rebased onto main after #6365's squash-merge, so the PR now contains only the Qwen2 and MiMo commits.

Changelog

  • Qwen2Bridge: provider_bridge() is replaced by hf_config_to_model_config_kwargs(), and the provider path reuses the same kwargs (hf_config_to_provider_kwargs). Provider-implied defaults are explicit (masked_softmax_fusion, rope_scaling=False, rope_scaling_factor=1.0, position_embedding_type via setdefault("rope") so YaRN is preserved). USE_MODEL_CONFIG_FOR_CONVERSION = True.
  • MimoBridge (subclasses Qwen2Bridge): extends the Qwen2 kwargs with qk_layernorm=False, add_qkv_bias=True, and MTP depth (mtp_num_layers, mtp_loss_scaling_factor=0.1) instead of overriding provider_bridge(). It inherits the conversion flag.
  • Recipes: all 30 Qwen2/2.5 H100 recipes use get_model_config().
  • Tests:
    • New test_qwen2_bridge.py; Qwen2 had no bridge unit tests. It covers the direct builder mapping, provider/builder parity (tied, fp16, YaRN), and the YaRN transformer fields plus HF export.
    • A strict recipe test runs every Qwen2/2.5 recipe against a real BridgeGPTModelConfig.
    • MiMo tests cover the builder MTP mapping and provider parity.

Verification

Each family was validated separately on tiny random-weight checkpoints (single GB200 node, NeMo 26.10 container).

Conversion paths:

  • scripts/conversion GPU import at TP2 and export.
  • AutoBridge.import_ckpt / export_ckpt.
  • Load + forward as in compare.py.
  • roundtrip_checkpoint.

Each was run on this branch and on main.

Check Qwen2 (untied, tied, YaRN) MiMo (MTP=1, MTP=0)
Provider fields, main vs this branch identical identical
get_model_config() vs provider 0 diffs (9 on main) 0 diffs (9 on main)
Imported run_config.yaml BridgeGPTModelConfig + GPTModelBuilder same, mtp_num_layers 1 / 0
Export vs source HF weights (GPU TP2, CPU, and from a main-imported checkpoint) bit-exact, 9/9 bit-exact incl. MTP, 6/6
Logits: this branch vs main, and this branch on a main-imported checkpoint bitwise-identical, 6/6 bitwise-identical, 4/4
Logits vs HF cosine 0.99999 n/a (remote-code HF model)
roundtrip_checkpoint TP2 pass pass

Unit tests:

  • 268 (Qwen2 run) and 130 (MiMo run).
  • Regression: 40 Qwen2/2.5 recipe factories and 517 tests across models/qwen, models/mimo, test_auto_bridge.py, recipes/qwen, test_qwen_recipes.py and doc_consistency.
  • After rebasing onto main (Megatron Core 8949def81): 528 passed, 1 skipped across models/qwen, models/mimo, recipes/qwen, test_qwen_recipes.py, test_auto_bridge.py, test_gpt_model_config.py and test_model_bridge.py.

ruff check / ruff format --check are clean (ruff 0.16.7; pre-commit itself not run).

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

Additional Information

🤖 Generated with Claude Code

@kamran-nvidia kamran-nvidia added feature New capabilities, enhancements, or enablement work area:model Model implementations and HF bridge logic labels Oct 9, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 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.

@kamran-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test e4e13cd

kamran-nvidia and others added 2 commits October 9, 2026 17:06
Move Qwen2/Qwen2.5 onto the ModelConfig/ModelBuilder path, following
Muse Glimmer and Qwen3:

- Qwen2Bridge maps Hugging Face configs in hf_config_to_model_config_kwargs();
  the deprecated provider path reuses the same kwargs, so provider_bridge()
  is no longer overridden.
- USE_MODEL_CONFIG_FOR_CONVERSION = True: checkpoint import, the conversion
  scripts and the compare tool build Qwen2 through its ModelBuilder.
- All 30 Qwen2/2.5 H100 recipes use get_model_config().
- Add Qwen2 bridge unit tests (none existed) and a strict builder-config
  recipe test.

Signed-off-by: Kamran Jafari <kjafarisadeg@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MimoBridge extends the Qwen2 builder kwargs with its attention settings and
MTP depth (mtp_num_layers, mtp_loss_scaling_factor) instead of overriding
provider_bridge(). It inherits the Qwen2 conversion flag, so MiMo checkpoints
convert through the ModelBuilder as well.

Signed-off-by: Kamran Jafari <kjafarisadeg@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamran-nvidia
kamran-nvidia force-pushed the kjafarisadeg/qwen2-mimo-model-config branch from e4e13cd to 4903e5c Compare October 10, 2026 02:35
@kamran-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 4903e5c

@kamran-nvidia
kamran-nvidia marked this pull request as ready for review October 13, 2026 15:54
@cuichenx cuichenx added the needs-review PR is ready for code review and waiting on a reviewer label Oct 13, 2026

This branch was successfully deployed

1 active deployment
test — 4903e5c0 Deployed Oct 10, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #22724
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model implementations and HF bridge logic feature New capabilities, enhancements, or enablement work 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