Repository navigation
Fix MiniMax M2.7 expert selectors and source dtype documentation - #2817
Conversation
Signed-off-by: Chad Voegele <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2817 +/- ##
==========================================
+ Coverage 69.42% 78.59% +9.16%
==========================================
Files 653 653
Lines 72453 72453
==========================================
+ Hits 50303 56945 +6642
+ Misses 22150 15508 -6642
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Changes requested: the selector fix is correct, but by the PR's own validation, merging it alone swaps today's loud guard failure for an export that succeeds with corrupted expert weights.
Needs action:
- Hold this PR (it is marked Draft) until the native
FP8Expertsinverse-scale fix lands in the fused-expert calibration/export path. Or land both together, stacked as[1/2](library fix) then[2/2](this recipe). See the inline comment on the yaml. - Add a regression test, or link one in the companion PR, showing that fused FP8 source experts are dequantized by
*_scale_invbefore NVFP4 quantization. The current test uses BF16 random weights, so it can't catch the 2,000–4,500× error reported in the PR body. - Confirm whether the published
nvidia/MiniMax-M2.7-NVFP4checkpoint is affected (bug 6917918), as the PR body says this is still unknown.
No action needed:
*mlp.experts.*doesn't matchmlp.shared_expertsor the routergate. On the legacy layout the new selectors match nothing and do no harm.- The new test covers both layouts, fused and unfused experts, exclusions, and that parameters are left unchanged. The NVIDIA header is standard and the imports are at the top. I read the tests but didn't run them.
- The doc correction (FP8 attention, FP32 router, BF16
lm_head) matches the checkpoint metadata cited in the PR body.
| cfg: {$import: nvfp4} | ||
| - quantizer_name: '*block_sparse_moe.experts.*input_quantizer' | ||
| cfg: {$import: nvfp4} | ||
| - quantizer_name: '*mlp.experts.*weight_quantizer' |
There was a problem hiding this comment.
Bot comment.
This selector is correct for the native Transformers layout (mlp.experts.gate_up_proj / down_proj). However, the PR's own GB300 run shows that with it enabled, hf_ptq.py exits 0 and writes a checkpoint whose experts approximate the raw FP8 stored values, without the *_scale_inv multiply (relative L2 error 1,989–4,474). Without this line the run fails the enabled-weight guard. With it, the run silently produces bad weights. Please don't merge this until the FP8Experts inverse-scale handling is fixed, or ship it in the same stack.
Chad's Agent ### What does this PR do? Type of change: Bug fix. Native Transformers `FP8Experts` store fused FP8 weights with inverse scales. The generic wrapper exposed raw values to weight calibration and packing, while native FP8 dispatch bypassed ModelOpt's fake quantization. Dequantize one expert projection at a time for forward, calibration, and export, keeping scale multiplication in FP32 until the output cast. Export removes consumed inverse/activation scales. Native packed FP4 inputs are rejected. Explicit `unpack_weight()` materializes floating parameters before folding, matching FP8Linear's interface. Folding is inherited from the fused wrapper. Native forward still reads scale attributes after unpacking, so export removes them. Ordinary PTQ/export keeps per-expert dequantization without unpacking entire modules. Raw FP8 folding retains FP8Linear's existing unsupported behavior; shared folding code is unchanged. Independent of recipe PR #2817; analogous to #1962. FP8Linear is unchanged. ### Usage Use a recipe matching native expert names; M2.7 validation also needs #2817. Regenerate affected exports from the original FP8 checkpoint. Call `experts.unpack_weight()` explicitly before permanent or temporary folding. ### Testing - Current revision: 99 focused fused-expert/FP8Linear plugin tests pass on both Transformers 5.5.0 and 5.18.0. Gated/non-gated temporary-fold tests verify parameter identity, dtype, exact values, quantizer state, and forward results after normal and exceptional exits. The new tests fail on the previous head without explicit unpacking. - Six real native FP8Experts GPU cases pass across gated/non-gated layouts and FP32/FP16/BF16 inputs, with NVFP4 calibration/export and independent decoding. - Fresh full MiniMax M2.7 PTQ/export passes with #2817: 512 samples, batch 8, 64/64 calibration batches, 14 shards (134.52 GB versus 230.12 GB source payload). All 47,616 expert projections have correct packed/block-scale shapes. All 191,087 tensor headers and shard extents agree with the index; no stale inverse/activation scales or declaration mismatches; reverse naming succeeds. - 27 crops (layers 0/30/61, experts 0/127/255, gate/up/down) have 9.28–9.53% relative L2 error and norm ratios 0.997–1.003 against the **scaled FP8 source**. Independent E2M1 and ModelOpt NVFP4 decoders agree within FP32 rounding. Both generation previews complete. - Controlled environment: four GB300 GPUs, aarch64, `nvcr.io/nvidia/pytorch:26.08-py3`, Transformers 5.18.0, compressed-tensors 0.19.0, kernels 0.17.0, datasets 5.0.1; original ModelOpt 0.48.0rc0 source plus backend and recipe patches. Wrapper ASTs/export code match this PR. Model revision `d494266a4affc0d2995ba1fa35c8481cbd84294b`; CNN/DailyMail revision `96df5e686bee6baa90b8bee7c28b81fa3fa6223d`, config 3.0.0. The weight-quantizer guard remained active. - Fresh calibration: 26m10s; export: 150.1s; peak memory: 62.75–65.32 GB/GPU. Tokenizer/vocabulary/merges/chat-template files are byte-identical; generation settings differ only in the recorded Transformers version. Native config normalization and the loader-generated expert-parallel scale-sharding plan are accounted for. - Changed-file pre-commit hooks and `git diff --check` pass. Current repository CI: 32 successful checks, 1 skipped, 19 GPU/example jobs queued without assigned runners; no failures. Earlier revision: full-model smoke/full512 and 54 CI checks passed; the full512 results above are from the fresh rerun. ### Before your PR is "*Ready for review*" - Backward compatible: ✅ - Copied code/new dependencies: N/A - Necessary tests: ✅ - Changelog: ✅ - Claude approval: N/A ### Additional Information Full-model PTQ uses a four-GPU device map. FSDP2, offload, serving, and benchmark accuracy are untested. Excluded attention projections export as BF16, routers as FP32, and the LM head as BF16. --------- Signed-off-by: Chad Voegele <[email protected]>
Chad's Agent Type of change: Bug fix. Native Transformers `FP8Experts` store fused FP8 weights with inverse scales. The generic wrapper exposed raw values to weight calibration and packing, while native FP8 dispatch bypassed ModelOpt's fake quantization. Dequantize one expert projection at a time for forward, calibration, and export, keeping scale multiplication in FP32 until the output cast. Export removes consumed inverse/activation scales. Native packed FP4 inputs are rejected. Explicit `unpack_weight()` materializes floating parameters before folding, matching FP8Linear's interface. Folding is inherited from the fused wrapper. Native forward still reads scale attributes after unpacking, so export removes them. Ordinary PTQ/export keeps per-expert dequantization without unpacking entire modules. Raw FP8 folding retains FP8Linear's existing unsupported behavior; shared folding code is unchanged. Independent of recipe PR #2817; analogous to #1962. FP8Linear is unchanged. Use a recipe matching native expert names; M2.7 validation also needs Call `experts.unpack_weight()` explicitly before permanent or temporary folding. - Current revision: 99 focused fused-expert/FP8Linear plugin tests pass on both Transformers 5.5.0 and 5.18.0. Gated/non-gated temporary-fold tests verify parameter identity, dtype, exact values, quantizer state, and forward results after normal and exceptional exits. The new tests fail on the previous head without explicit unpacking. - Six real native FP8Experts GPU cases pass across gated/non-gated layouts and FP32/FP16/BF16 inputs, with NVFP4 calibration/export and independent decoding. - Fresh full MiniMax M2.7 PTQ/export passes with #2817: 512 samples, batch 8, 64/64 calibration batches, 14 shards (134.52 GB versus 230.12 GB source payload). All 47,616 expert projections have correct packed/block-scale shapes. All 191,087 tensor headers and shard extents agree with the index; no stale inverse/activation scales or declaration mismatches; reverse naming succeeds. - 27 crops (layers 0/30/61, experts 0/127/255, gate/up/down) have 9.28–9.53% relative L2 error and norm ratios 0.997–1.003 against the **scaled FP8 source**. Independent E2M1 and ModelOpt NVFP4 decoders agree within FP32 rounding. Both generation previews complete. - Controlled environment: four GB300 GPUs, aarch64, `nvcr.io/nvidia/pytorch:26.08-py3`, Transformers 5.18.0, compressed-tensors 0.19.0, kernels 0.17.0, datasets 5.0.1; original ModelOpt 0.48.0rc0 source plus backend and recipe patches. Wrapper ASTs/export code match this PR. Model revision `d494266a4affc0d2995ba1fa35c8481cbd84294b`; CNN/DailyMail revision `96df5e686bee6baa90b8bee7c28b81fa3fa6223d`, config 3.0.0. The weight-quantizer guard remained active. - Fresh calibration: 26m10s; export: 150.1s; peak memory: 62.75–65.32 GB/GPU. Tokenizer/vocabulary/merges/chat-template files are byte-identical; generation settings differ only in the recorded Transformers version. Native config normalization and the loader-generated expert-parallel scale-sharding plan are accounted for. - Changed-file pre-commit hooks and `git diff --check` pass. Current repository CI: 32 successful checks, 1 skipped, 19 GPU/example jobs queued without assigned runners; no failures. Earlier revision: full-model smoke/full512 and 54 CI checks passed; the full512 results above are from the fresh rerun. - Backward compatible: ✅ - Copied code/new dependencies: N/A - Necessary tests: ✅ - Changelog: ✅ - Claude approval: N/A Full-model PTQ uses a four-GPU device map. FSDP2, offload, serving, and benchmark accuracy are untested. Excluded attention projections export as BF16, routers as FP32, and the LM head as BF16. --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]>
|
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072) ## Cherry-picked PRs - #2817 - #2671 - #2892 - #2876 - #2910 - #2911 - #2919 - #2904 - #2937 - #2928 - #2885 - #2908 - #2929 - #2950 - #2972 - #2877 - #2951 - #2816 - #3005 - #3012 - #2971 - #3015 - #3006 - #3026 - #2988 - #3028 - #1860 - #3030 - #2612 - #3033 - #2653 - #2599 - #2655 - #2618 - #2868 - #3032 - #3027 - #2869 - #2984 - #2975 - #2345 - #3020 - #2997 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Diffusion exports now offer more control over attention-quantizer metadata and preserve sparse-attention settings in a format compatible with downstream tooling. * Model loading better handles select bundled model implementations, and Docker guidance now covers writable CUDA-extension cache locations. * **Bug Fixes** * Improved reliability for model export and checkpoint saving, quantization across devices, ONNX processing, and calibration. * Temporary TensorRT and autotuning artifacts now use private directories by default. * **Documentation** * Updated installation guidance, compatibility notes, and links; corrected typos across guides and examples. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: LinCanNerd <[email protected]> Signed-off-by: Keval Morabia <[email protected]> Signed-off-by: weimingc <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Kai Xu <[email protected]> Signed-off-by: Zhehao Hu <[email protected]> Signed-off-by: noeyy-mino <[email protected]> Signed-off-by: joe-nv <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: Shengliang Xu <[email protected]> Signed-off-by: Chenjie Luo <[email protected]> Signed-off-by: anmaurya001 <[email protected]> Signed-off-by: Connor Baker <[email protected]> Signed-off-by: wiederse <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: Pratik Gandhi <[email protected]> Signed-off-by: Michael Rusu <[email protected]> Signed-off-by: Michael-Rusu <[email protected]> Signed-off-by: namgyu-youn <[email protected]> Signed-off-by: Sylvester Kaczmarek <[email protected]> Signed-off-by: Javier de Jesus <[email protected]> Signed-off-by: javierdejesusda <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Juhi Mittal <[email protected]> Signed-off-by: Dmitry Rantovov <[email protected]> Signed-off-by: h-guo18 <[email protected]> Co-authored-by: Chad Voegele <[email protected]> Co-authored-by: LinCanNerd <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Keval Morabia <[email protected]> Co-authored-by: Wei-Ming Chen <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: kaix-nv <[email protected]> Co-authored-by: Zhehao Hu <[email protected]> Co-authored-by: joe <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Shengliang Xu <[email protected]> Co-authored-by: Chenjie Luo <[email protected]> Co-authored-by: anmaurya001 <[email protected]> Co-authored-by: Connor Baker <[email protected]> Co-authored-by: Jiao Mingyang <[email protected]> Co-authored-by: Vu Dinh <[email protected]> Co-authored-by: Pratik Gandhi <[email protected]> Co-authored-by: Michael R <[email protected]> Co-authored-by: Michael-Rusu <[email protected]> Co-authored-by: namgyu-youn <[email protected]> Co-authored-by: Sylvester Kaczmarek <[email protected]> Co-authored-by: Javier De Jesus <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Juhi Mittal <[email protected]> Co-authored-by: Dmitry Rantovov <[email protected]> Co-authored-by: h-guo18 <[email protected]>
What does this PR do?
Chad's Agent
Draft: full-model export correctness is blocked by native FP8 expert scaling.
Type of change: Bug fix, documentation, tests.
The MiniMax M2.7 expert-only recipe selects
block_sparse_moe.expertsbut misses the modern Transformersmlp.expertslayout, leaving no weight quantizers enabled. Add the modern patterns while retaining legacy support. Regression tests cover linear and fused experts, expert W4A4 settings, exclusions, and unchanged parameters.Correct the source-dtype description. Safetensors headers at
MiniMaxAI/MiniMax-M2.7revisiond494266a4affc0d2995ba1fa35c8481cbd84294bshow all 248 attention projection weights stored as FP8 E4M3, all 62 router gate weights and correction biases as FP32, andlm_head.weightas BF16. The config's BF16 default is not every tensor's dtype. These are checkpoint storage dtypes; excluding modules from this recipe does not guarantee their runtime/export dtype.Root cause: legacy remote code versus native Transformers
This is not a naming change introduced by Transformers 5.18. Native MiniMax-M2 support landed on January 9, 2026 in Transformers PR #42028 (commit
7a2bf25f36) and shipped in v5.0.0, already usingmlp.expertsand fused expert tensors. The original production setup recorded Transformers 4.57.1 and the legacy remote-code implementation; this reproduction uses native Transformers 5.18.0. The environment's exact upgrade date is unknown.The vendor checkpoint stores separate expert projections:
Native Transformers renames
block_sparse_moetomlp, stacks experts, and concatenates gate/up projections:Recipe selectors match the loaded module/quantizer names, not the checkpoint keys. Therefore the legacy-only recipe misses native expert quantizers. Both selector families are retained to support both loading implementations; the nonmatching family is a no-op.
Two distinct issues are involved: the recipe's missing native selectors cause the reported guard failure; enabling them exposes a separate native
FP8Expertsinverse-scale omission in the tested ModelOpt calibration/export path. The publishednvidia/MiniMax-M2.7-NVFP4checkpoint is not affected by this issue: it was produced with an older Transformers version that did not surface it.Usage
Existing
--recipe modelopt_recipes/models/MiniMaxAI/MiniMax-M2.7/ptq/nvfp4_experts_only-kv_fp8_cast.yamlcommands need no changes.Testing
pytest tests/unit/recipe— 509 passed.pre-commit run --files <three changed files>andgit diff --checkpassed.hf_ptq.pyexited 0. All 47,616 expert projection weights have packed NVFP4 storage and FP8 block scales.gate_up_proj_scale_invprevents reverse weight conversion.Before your PR is "Ready for review"
Additional Information
Full-model validation uses PyTorch 26.08, ModelOpt 0.48.0rc0, Transformers 5.18.0, compressed-tensors 0.19.0, and kernels 0.17.0. Model and CNN/DailyMail revisions are pinned; only the recipe changes between runs. No weight-quantization check bypass is used.
The recipe selectors are necessary but insufficient for a valid export with this environment. ModelOpt's generic fused-expert wrapper handles
FP8Expertsstructurally, but its calibration/export weight path needs the native FP8 inverse scales. Completing that backend support changes library code; it cannot be demonstrated by changing only this recipe. Keep this PR in draft until that blocker is resolved. The exported checkpoint is not ready for serving or accuracy evaluation.Summary by CodeRabbit
block_sparse_moeandmlplayouts, including fused experts.