Skip to content

[TRTLLM-14255][fix] migrate MiniMax M3 to loader v2 for TP8 support - #16468

Merged
peihu-nv merged 4 commits into
NVIDIA:mainfrom
peihu-nv:peihengh/minimax-m3-loader-v2
Jul 22, 2026
Merged

[TRTLLM-14255][fix] migrate MiniMax M3 to loader v2 for TP8 support#16468
peihu-nv merged 4 commits into
NVIDIA:mainfrom
peihu-nv:peihengh/minimax-m3-loader-v2

Conversation

@peihu-nv

@peihu-nv peihu-nv commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added Hugging Face checkpoint support for MiniMax-M3 sparse language models.
    • Improved loading of MiniMax-M3 key/value projection weights across supported quantization formats.
    • Added support for both causal language modeling and conditional generation variants.
  • Bug Fixes

    • Corrected MiniMax-M3 gate bias parameter mapping during checkpoint loading.
    • Improved compatibility with partial and custom weight-loading configurations.

Description

MiniMax M3 defines variadic load_weights methods, so the model loader does not detect explicit weight_mapper support and silently routes M3 through the legacy weight loader. This prevents correct TP8 loading when the checkpoint has fewer K/V heads than the TP degree because the MXFP8 K/V scale tensors are not duplicated with the K/V weights.

This PR migrates MiniMax M3 models to loader v2 using a model-specific MiniMaxM3HfWeightMapper. The mapper keeps the existing routed-gate bias rename local to M3 and duplicates K/V weights plus both supported MXFP8 scale spellings (weight_scale and weight_scale_inv) when required by GQA tensor parallelism. It preserves the existing NVFP4 behavior and accepts arbitrary BaseWeightMapper implementations without assuming mapper-specific attributes.

Test Coverage

  • Added CPU unit coverage for mapper registration and MX fallback, explicit loader-v2 signatures, TP8 K/V duplication for both MXFP8 scale names, preserved NVFP4 behavior, missing quant config, TP degrees not requiring duplication, gate-bias remapping, and arbitrary base-mapper support.
  • Updated the real-checkpoint GPU smoke test to exercise _load_weights_impl_v2; full GPU execution is left to CI.
  • Prior GB200 end-to-end validation of the equivalent loader patch used the same configuration with no significant perf difference

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions).

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities.

  • CODEOWNERS updated if ownership changes.

  • Documentation updated as needed.

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
@peihu-nv
peihu-nv marked this pull request as ready for review July 16, 2026 04:27
@peihu-nv
peihu-nv requested a review from a team as a code owner July 16, 2026 04:27
@peihu-nv
peihu-nv requested a review from schetlur-nv July 16, 2026 04:27
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MiniMax-M3 gains a dedicated HF weight mapper for MoE gate renaming and KV tensor duplication across quantization modes. Text and VL loaders now accept structured mapper controls, with tests covering registration, tensor handling, parameter mapping, and v2 loading.

Changes

MiniMax-M3 weight loading

Layer / File(s) Summary
Mapper contract and KV handling
tensorrt_llm/_torch/models/checkpoints/hf/minimaxm3_weight_mapper.py
Registers the MiniMax-M3 mapper, renames MoE gate bias parameters, and duplicates KV weights, biases, and applicable quantization scales.
Model loader integration
tensorrt_llm/_torch/models/modeling_minimaxm3.py
Updates text and VL load_weights APIs to forward the mapper, merged parameter maps, and partial-loading options.
Mapper and loader validation
tests/unittest/_torch/models/checkpoints/hf/test_minimaxm3_weight_mapper.py, tests/unittest/_torch/models/test_minimax_m3.py
Tests mapper registration, KV duplication for MXFP8 and NVFP4, parameter renaming, loader signatures, and v2 loading.
Estimated code review effort: 3 (Moderate) ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant MiniMaxM3ForCausalLM
  participant MiniMaxM3HfWeightMapper
  participant DecoderModelForCausalLM
  Caller->>MiniMaxM3ForCausalLM: call load_weights
  MiniMaxM3ForCausalLM->>MiniMaxM3HfWeightMapper: initialize mapper and parameter map
  MiniMaxM3ForCausalLM->>DecoderModelForCausalLM: forward weights and loader controls
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required ticket/type format and clearly summarizes the main change: loader v2 migration for TP8 support.
Description check ✅ Passed The description includes Description, Test Coverage, and PR Checklist sections and is specific about the change and validation.
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.

Actionable comments posted: 1

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

1473-1479: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Python 3.10 built-in generic annotations consistently.

  • tensorrt_llm/_torch/models/modeling_minimaxm3.py#L1473-L1479: replace unparameterized Dict/Optional annotations with precise dict[...] and | None types.
  • tensorrt_llm/_torch/models/modeling_minimaxm3.py#L1625-L1631: apply the same public loader signature convention.

As per coding guidelines, “prefer built-in generic types and |.”

🤖 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 1473 - 1479,
Update the load_weights signature in
tensorrt_llm/_torch/models/modeling_minimaxm3.py at lines 1473-1479 to use
precise built-in dict[...] annotations and | None instead of unparameterized
Dict/Optional types. Apply the same public loader signature convention at lines
1625-1631, preserving the existing parameter value types and behavior.

Source: Coding guidelines

tensorrt_llm/_torch/models/checkpoints/hf/minimaxm3_weight_mapper.py (1)

35-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Parameterize the weight mapping types.

weights: dict and -> dict leave this callback contract unchecked; use precise dict[...] types for the tensor mapping. As per coding guidelines, “Annotate every function” and “prefer built-in generic types.”

🤖 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/checkpoints/hf/minimaxm3_weight_mapper.py` around
lines 35 - 55, Update _duplicate_kv_weights to use precise built-in generic
dict[...] annotations for both the weights parameter and return type, specifying
the key and tensor value types used by the mapping. Keep the callback behavior
and duplication logic unchanged.

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.

Inline comments:
In `@tests/unittest/_torch/models/test_minimax_m3.py`:
- Around line 883-894: Update the environment handling around
_load_weights_impl_v2 to preserve the existing
TRT_LLM_DISABLE_LOAD_WEIGHTS_IN_PARALLEL value before setting it, then restore
that value in finally; remove the variable only when it was previously unset,
ensuring later tests retain their original loader-parallelism setting.

---

Nitpick comments:
In `@tensorrt_llm/_torch/models/checkpoints/hf/minimaxm3_weight_mapper.py`:
- Around line 35-55: Update _duplicate_kv_weights to use precise built-in
generic dict[...] annotations for both the weights parameter and return type,
specifying the key and tensor value types used by the mapping. Keep the callback
behavior and duplication logic unchanged.

In `@tensorrt_llm/_torch/models/modeling_minimaxm3.py`:
- Around line 1473-1479: Update the load_weights signature in
tensorrt_llm/_torch/models/modeling_minimaxm3.py at lines 1473-1479 to use
precise built-in dict[...] annotations and | None instead of unparameterized
Dict/Optional types. Apply the same public loader signature convention at lines
1625-1631, preserving the existing parameter value types and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 72b3a08f-1250-46a5-8a75-bce316a39326

📥 Commits

Reviewing files that changed from the base of the PR and between 6013944 and db28873.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/models/checkpoints/hf/minimaxm3_weight_mapper.py
  • tensorrt_llm/_torch/models/modeling_minimaxm3.py
  • tests/unittest/_torch/models/checkpoints/hf/test_minimaxm3_weight_mapper.py
  • tests/unittest/_torch/models/test_minimax_m3.py

Comment thread tests/unittest/_torch/models/test_minimax_m3.py Outdated
Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60434 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60434 [ run ] completed with state FAILURE. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #48774 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

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60463 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60463 [ run ] completed with state SUCCESS. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #48796 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

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60723 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60723 [ run ] completed with state FAILURE. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #49011 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

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60765 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60765 [ run ] completed with state FAILURE. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #49048 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

Link to invocation

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60818 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60818 [ run ] completed with state SUCCESS. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #49099 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

@peihu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61005 [ run ] triggered by Bot. Commit: 967f135 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61005 [ run ] completed with state SUCCESS. Commit: 967f135
/LLM/main/L0_MergeRequest_PR pipeline #49262 completed with status: 'SUCCESS'

CI Report

Link to invocation

@peihu-nv
peihu-nv merged commit 9e96f8b into NVIDIA:main Jul 22, 2026
7 checks passed
yuanjingx87 pushed a commit to yuanjingx87/TensorRT-LLM that referenced this pull request Jul 26, 2026
…VIDIA#16468)

Signed-off-by: peihengh <259410613+peihu-nv@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.

3 participants