Skip to content

[TRTLLM-13458][feat] Support Minimax M3 NVFP4 checkpoint - #15857

Merged
longlee0622 merged 3 commits into
NVIDIA:mainfrom
pcicotti:m3nvfp4
Jul 3, 2026
Merged

[TRTLLM-13458][feat] Support Minimax M3 NVFP4 checkpoint#15857
longlee0622 merged 3 commits into
NVIDIA:mainfrom
pcicotti:m3nvfp4

Conversation

@pcicotti

@pcicotti pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds NVFP4 quantization support for the routed MoE experts in MiniMax-M3, enabling the
mixed-precision checkpoint layout (MXFP8 base layers + NVFP4 routed experts) published as
nvidia/MiniMax-M3-NVFP4.

The NVFP4 checkpoint stores per-linear expert quant entries in hf_quant_config.json under
MIXED_PRECISION (e.g. language_model.model.layers.N.block_sparse_moe.experts.E.w1 -> NVFP4).
ModelConfig cannot resolve these fine-grained per-linear keys to a MoE backend directly, so
ModelConfig._set_minimax_m3_moe_quant_config() detects the NVFP4 expert entries and injects
coarse model.layers.N.block_sparse_moe.experts keys that MiniMaxM3MoE._get_experts_quant_config()
looks up per layer. MiniMaxM3MoE.__init__ passes the result as override_quant_config to
create_moe(), selecting the NVFP4-capable TRTLLMGenFusedMoE backend for the routed experts
while leaving the base-layer (MXFP8) quant config unchanged.

This also includes a required fix in fused_moe_trtllm_gen.py: MiniMax-M3's MoE experts use
ActivationType.SwigluBias (SwiGLU with per-expert alpha/beta/clamp-limit bias tensors), which
was not mapped to a TRTLLM-Gen activation type. SwigluBias reuses the same underlying SwiGLU
kernel path (ActType::SwiGlu == 0); the alpha/beta/clamp-limit values are passed separately as
tensors, so the fix simply extends the activation-type mapping. Without this fix, constructing the
NVFP4 experts through TRTLLMGenFusedMoE fails since SwigluBias falls through the mapping.
This fix is a hard dependency of the NVFP4 checkpoint support and is included in this PR rather
than split out, since the NVFP4 path cannot function without it.

Test coverage adds TestMiniMaxM3::test_nvfp4 (MMLU + GSM8K accuracy) for the new checkpoint,
following the existing test_mxfp8/test_auto_dtype pattern in the same test class, with
matching gsm8k.yaml / mmlu.yaml accuracy references and QA test-list registration.

Test Coverage

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestMiniMaxM3::test_nvfp4
    (MMLU + GSM8K, TP=8/EP=8, Blackwell-only) — new
  • tests/integration/defs/accuracy/references/{gsm8k,mmlu}.yaml — new reference thresholds for
    nvidia/MiniMax-M3-NVFP4
  • tests/integration/test_lists/qa/llm_function_core.txt — registers the new test

Related PRs

Summary by CodeRabbit

  • New Features

    • Added support for MiniMax M3 routed MoE quantization layouts, including mixed-precision and NVFP4 checkpoint variants.
    • Expanded MoE handling so routed experts can use per-layer quantization settings during runtime.
    • Improved activation support for SwiGLU bias variants.
  • Tests

    • Added accuracy coverage for a new MiniMax M3 NVFP4 model path.
    • Added new GSM8K and MMLU reference results and updated test timing expectations.

@pcicotti

pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds Minimax M3 NVFP4 mixed-precision MoE support by injecting per-layer routed-expert quant configs during model loading and applying them during MoE construction, fixes a SwigluBias activation mapping in the TRTLLM-Gen fused MoE kernel selector, and adds new accuracy test coverage.

Changes

Minimax M3 NVFP4 MoE quant support

Layer / File(s) Summary
Detect and inject Minimax M3 NVFP4 layer quant config
tensorrt_llm/_torch/model_config.py
Adds _MINIMAX_M3_ARCHITECTURES and _set_minimax_m3_moe_quant_config, which detects NVFP4 routed expert entries and populates per-layer quant config based on moe_layer_freq; wired into ModelConfig.from_pretrained.
Wire per-layer quant config into MoE construction
tensorrt_llm/_torch/models/modeling_minimaxm3.py
Adds _get_experts_quant_config to resolve per-layer routed expert quant settings, passed into create_moe via override_quant_config.
SwigluBias activation type mapping fix
tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
_to_trtllm_gen_activation_type now maps ActivationType.SwigluBias to the same ID as Swiglu.
NVFP4 accuracy test coverage
tests/integration/defs/accuracy/references/gsm8k.yaml, tests/integration/defs/accuracy/references/mmlu.yaml, tests/integration/defs/accuracy/test_llm_api_pytorch.py, tests/integration/test_lists/qa/llm_function_core.txt
Adds reference accuracy values, a new test_nvfp4 test for TestMiniMaxM3 validating QuantAlgo.MIXED_PRECISION, and a QA timeout entry.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FromPretrained as ModelConfig.from_pretrained
  participant QuantHelper as _set_minimax_m3_moe_quant_config
  participant MoEInit as MiniMaxM3MoE.__init__
  participant ExpertsHelper as _get_experts_quant_config
  participant CreateMoE as create_moe

  FromPretrained->>QuantHelper: pretrained_config, layer_quant_config
  QuantHelper->>QuantHelper: scan for NVFP4 expert entries, derive moe_layer_freq
  QuantHelper-->>FromPretrained: updated layer_quant_config
  FromPretrained-->>MoEInit: ModelConfig with quant_config_dict

  MoEInit->>ExpertsHelper: model_config, layer_idx
  ExpertsHelper->>ExpertsHelper: lookup per-layer entry or fallback
  ExpertsHelper-->>MoEInit: experts_quant_config
  MoEInit->>CreateMoE: override_quant_config=experts_quant_config
Loading

Suggested reviewers: nv-guomingz, Superjomn, brb-nv, lancelly, jieli-matrix

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly identifies the main change: MiniMax M3 NVFP4 checkpoint support.
Description check ✅ Passed The description covers the issue, solution, test coverage, and related PR context with the expected sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tensorrt_llm/_torch/models/modeling_minimaxm3.py (1)

355-372: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a return type annotation.

_get_experts_quant_config returns a QuantConfig but is unannotated. As per coding guidelines: "Always annotate functions with return types."

♻️ Suggested annotation
-    `@staticmethod`
-    def _get_experts_quant_config(model_config: "ModelConfig", layer_idx: int):
+    `@staticmethod`
+    def _get_experts_quant_config(model_config: "ModelConfig",
+                                  layer_idx: int) -> QuantConfig:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/models/modeling_minimaxm3.py` around lines 355 - 372, The
static helper _get_experts_quant_config in modeling_minimaxm3.py is missing a
return type annotation. Update its signature to explicitly declare the returned
QuantConfig type, matching the values it already returns from
model_config.quant_config or model_config.quant_config_dict, so the method
follows the project’s function-annotation guideline.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/_torch/models/modeling_minimaxm3.py`:
- Around line 355-372: The static helper _get_experts_quant_config in
modeling_minimaxm3.py is missing a return type annotation. Update its signature
to explicitly declare the returned QuantConfig type, matching the values it
already returns from model_config.quant_config or
model_config.quant_config_dict, so the method follows the project’s
function-annotation guideline.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7563a0d1-96e6-4b1b-b28b-f92c45b7760d

📥 Commits

Reviewing files that changed from the base of the PR and between cd2f9b0 and d4add6a.

📒 Files selected for processing (7)
  • tensorrt_llm/_torch/model_config.py
  • tensorrt_llm/_torch/models/modeling_minimaxm3.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • tests/integration/defs/accuracy/references/gsm8k.yaml
  • tests/integration/defs/accuracy/references/mmlu.yaml
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/qa/llm_function_core.txt

@pcicotti

pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@pcicotti

pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

1 similar comment
@pcicotti

pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57190 [ run ] triggered by Bot. Commit: f417283 Link to invocation

Comment thread tests/integration/defs/accuracy/references/gsm8k.yaml Outdated
@WeiHaocheng

Copy link
Copy Markdown
Collaborator

LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57190 [ run ] completed with state SUCCESS. Commit: f417283
/LLM/main/L0_MergeRequest_PR pipeline #45963 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@brb-nv brb-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread tests/integration/defs/accuracy/references/gsm8k.yaml Outdated
Comment thread tests/integration/defs/accuracy/test_llm_api_pytorch.py
Comment thread tests/integration/defs/accuracy/test_llm_api_pytorch.py Outdated
@pcicotti

pcicotti commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57271 [ run ] triggered by Bot. Commit: f417283 Link to invocation

@longlee0622 longlee0622 self-assigned this Jul 3, 2026
Add NVFP4 quantization support for the routed MoE experts in
Minimax M3, enabling mixed-precision checkpoints (MXFP8 base layers
+ NVFP4 experts).

The NVFP4 checkpoint stores per-linear expert entries in
hf_quant_config.json under MIXED_PRECISION.  ModelConfig cannot
resolve these fine-grained keys to a backend, so
_set_minimax_m3_moe_quant_config() detects them and injects coarse
"model.layers.N.block_sparse_moe.experts" entries that
MiniMaxM3MoE._get_experts_quant_config() can look up per layer.
MiniMaxM3MoE.__init__ then passes the result as override_quant_config
to create_moe(), selecting the NVFP4 backend for experts while leaving
the base-layer quant config unchanged.

Signed-off-by: Pietro Cicotti <5833013+pcicotti@users.noreply.github.com>
…mapping

SwigluBias reuses the SwiGlu kernel path (ActType::SwiGlu == 0); the
per-expert alpha/beta/clamp_limit are passed as separate tensors.

Signed-off-by: Pietro Cicotti <5833013+pcicotti@users.noreply.github.com>
@pcicotti

pcicotti commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57317 [ run ] triggered by Bot. Commit: bf4d5b3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57271 [ run ] completed with state ABORTED. Commit: f417283
LLM/main/L0_MergeRequest_PR #46033 (Blue Ocean) completed with status: ABORTED

Link to invocation

Add TestMiniMaxM3::test_nvfp4 (MMLU + GSM8K) for the
nvidia/MiniMax-M3-NVFP4 checkpoint (MXFP8 base layers with NVFP4
routed experts), with matching gsm8k/mmlu accuracy references and QA
test-list registration.

Signed-off-by: Pietro Cicotti <5833013+pcicotti@users.noreply.github.com>
@pcicotti

pcicotti commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57343 [ run ] triggered by Bot. Commit: b141174 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57317 [ run ] completed with state ABORTED. Commit: bf4d5b3

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57343 [ run ] completed with state ABORTED. Commit: b141174
LLM/main/L0_MergeRequest_PR #46098 (Blue Ocean) completed with status: ABORTED

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57369 [ run ] triggered by Bot. Commit: b141174 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57369 [ run ] completed with state SUCCESS. Commit: b141174
/LLM/main/L0_MergeRequest_PR pipeline #46120 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disabke-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57470 Bot args parsing error: usage: /bot [-h]
{run,kill,skip,submit,reviewers,reuse-pipeline,reuse-review} ...
/bot: error: unrecognized arguments: --disabke-fail-fast

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57500 [ run ] triggered by Bot. Commit: b141174 Link to invocation

@longlee0622
longlee0622 enabled auto-merge (squash) July 3, 2026 18:20
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57500 [ run ] completed with state SUCCESS. Commit: b141174
/LLM/main/L0_MergeRequest_PR pipeline #46233 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57506 [ run ] triggered by Bot. Commit: b141174 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57506 [ run ] completed with state SUCCESS. Commit: b141174
/LLM/main/L0_MergeRequest_PR pipeline #46238 completed with status: 'SUCCESS'

CI Report

Link to invocation

@longlee0622
longlee0622 merged commit a0e65c6 into NVIDIA:main Jul 3, 2026
8 checks passed
BrianLi23 pushed a commit to BrianLi23/TensorRT-LLM that referenced this pull request Jul 9, 2026
Signed-off-by: Pietro Cicotti <5833013+pcicotti@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants