Skip to content

[https://nvbugs/6140411][fix] Fix index error of shared expert when loading weights#13856

Merged
longlee0622 merged 2 commits into
NVIDIA:mainfrom
shuyixiong:user/shuyix/fix_index_error
May 10, 2026
Merged

[https://nvbugs/6140411][fix] Fix index error of shared expert when loading weights#13856
longlee0622 merged 2 commits into
NVIDIA:mainfrom
shuyixiong:user/shuyix/fix_index_error

Conversation

@shuyixiong
Copy link
Copy Markdown
Collaborator

@shuyixiong shuyixiong commented May 7, 2026

Summary by CodeRabbit

  • New Features

    • Added conditional dynamic quantization support for NVFP4 Fused Mixture of Experts method.
  • Improvements

    • Refined weight quantization processing pipeline with enhanced alpha computation logic.

Description

Test Coverage

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)

  • 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.

@shuyixiong shuyixiong requested a review from a team as a code owner May 7, 2026 13:20
@shuyixiong shuyixiong requested a review from xxi-nv May 7, 2026 13:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds conditional dynamic quantization support to NVFP4FusedMoEMethod by making per-expert weight scale parameters optional. The refactoring generalizes alpha computation to handle optional scale destinations, introduces pre-quantization scale finalization, and applies consistent handling across regular and shared expert paths.

Changes

Dynamic Quantization Parameter and Computation Refactoring

Layer / File(s) Summary
Parameter Registration
tensorrt_llm/_torch/modules/fused_moe/quantization.py
Conditional registration of fc31_weight_scale_2 and fc2_weight_scale_2 parameters only when module.force_dynamic_quantization is enabled.
Alpha Computation Signature
tensorrt_llm/_torch/modules/fused_moe/quantization.py
_reconcile_and_compute_alphas refactored to accept optional destination tensors for fc31_weight_scale_2 and fc2_weight_scale_2.
Alpha Reconciliation Logic
tensorrt_llm/_torch/modules/fused_moe/quantization.py
Weight scale 2 tensor assignment is now conditional on whether optional destination buffers are provided.
Pre-quantization Scale Finalization
tensorrt_llm/_torch/modules/fused_moe/quantization.py
New _finalize_pre_quant_scales method validates per-expert scales, computes fc31_act_scale from max of w3/w1, and integrates into process_weights_after_loading before alpha reconciliation.
Regular and Shared Expert Integration
tensorrt_llm/_torch/modules/fused_moe/quantization.py
process_weights_after_loading and shared-expert finalization call _reconcile_and_compute_alphas with optional scale parameters only when those module parameters exist.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is completely empty with no implementation details, test coverage information, or explanations of what and why the changes are made. Fill in the Description section explaining the index error issue and how the fix addresses it. Add Test Coverage section documenting relevant test cases. Complete the PR Checklist with actual findings rather than template only.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title references fixing an index error for shared experts when loading weights, which directly aligns with the core change: refactoring weight loading logic in the quantization module to properly handle shared expert parameters.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/modules/fused_moe/quantization.py (1)

3239-3263: 💤 Low value

Consider: TRTLLMGen path may need similar handling for dynamic quantization.

The _finalize_shared_expert_alphas method calls _reconcile_and_compute_alphas without passing dst_fc31_weight_scale_2 and dst_fc2_weight_scale_2. If NVFP4TRTLLMGenFusedMoEMethod (or related classes) are used with force_dynamic_quantization=True, the weight_scale_2 tensors won't be populated for TRTLLMGen-specific shared experts.

This may be intentional if TRTLLMGen doesn't support dynamic quantization for shared experts yet, but worth noting for future work if this feature combination becomes needed.

🤖 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/modules/fused_moe/quantization.py` around lines 3239 -
3263, The _finalize_shared_expert_alphas function calls
_reconcile_and_compute_alphas for TRTLLMGen shared experts but does not pass
dst_fc31_weight_scale_2 or dst_fc2_weight_scale_2, so when
NVFP4TRTLLMGenFusedMoEMethod (or related classes) is used with
force_dynamic_quantization=True the TRTLLMGen-specific weight_scale_2 tensors
won't be populated; update _finalize_shared_expert_alphas to either supply the
appropriate dst_fc31_weight_scale_2 and dst_fc2_weight_scale_2 (e.g. from module
attributes created for TRTLLMGen path like tmp_trtllmgen_shared_weight_scale_2
variants) or call _reconcile_and_compute_alphas with explicit None/placeholder
and ensure _reconcile_and_compute_alphas handles dynamic-quantization case for
TRTLLMGen, referencing the symbols _finalize_shared_expert_alphas,
_reconcile_and_compute_alphas, tmp_trtllmgen_shared_weight_scale_2,
dst_fc31_weight_scale_2, dst_fc2_weight_scale_2, NVFP4TRTLLMGenFusedMoEMethod
and force_dynamic_quantization so shared experts get their weight_scale_2
populated or gracefully skipped.
🤖 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/modules/fused_moe/quantization.py`:
- Around line 3239-3263: The _finalize_shared_expert_alphas function calls
_reconcile_and_compute_alphas for TRTLLMGen shared experts but does not pass
dst_fc31_weight_scale_2 or dst_fc2_weight_scale_2, so when
NVFP4TRTLLMGenFusedMoEMethod (or related classes) is used with
force_dynamic_quantization=True the TRTLLMGen-specific weight_scale_2 tensors
won't be populated; update _finalize_shared_expert_alphas to either supply the
appropriate dst_fc31_weight_scale_2 and dst_fc2_weight_scale_2 (e.g. from module
attributes created for TRTLLMGen path like tmp_trtllmgen_shared_weight_scale_2
variants) or call _reconcile_and_compute_alphas with explicit None/placeholder
and ensure _reconcile_and_compute_alphas handles dynamic-quantization case for
TRTLLMGen, referencing the symbols _finalize_shared_expert_alphas,
_reconcile_and_compute_alphas, tmp_trtllmgen_shared_weight_scale_2,
dst_fc31_weight_scale_2, dst_fc2_weight_scale_2, NVFP4TRTLLMGenFusedMoEMethod
and force_dynamic_quantization so shared experts get their weight_scale_2
populated or gracefully skipped.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e71e12b5-87b7-4dbd-9c65-234fe0354127

📥 Commits

Reviewing files that changed from the base of the PR and between 47d7ecc and 7209aa9.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB300-4_GPUs-PyTorch-PerfSanity-Post-Merge-1"

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47216 [ run ] triggered by Bot. Commit: ef80c2b Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47216 [ run ] completed with state SUCCESS. Commit: ef80c2b
/LLM/main/L0_MergeRequest_PR pipeline #37172 (Partly Tested) 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-24_GPUs-6_Nodes-PyTorch-Disagg-PerfSanity-CTX2-NODE1-GPU4-GEN1-NODE4-GPU16-Post-Merge-2"

@chenfeiz0326
Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast --stage-list "GB200-24_GPUs-6_Nodes-PyTorch-Disagg-PerfSanity-CTX2-NODE1-GPU4-GEN1-NODE4-GPU16-Post-Merge-2,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-9,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-6,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-10"

@shuyixiong shuyixiong changed the title [https://nvbugs/6130334][fix] Fix index error of shared expert when loading weights [https://nvbugs/6140411][fix] Fix index error of shared expert when loading weights May 8, 2026
@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47323 [ run ] triggered by Bot. Commit: ef80c2b Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47322 [ run ] triggered by Bot. Commit: ef80c2b Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47322 [ run ] completed with state SUCCESS. Commit: ef80c2b
/LLM/main/L0_MergeRequest_PR pipeline #37265 (Partly Tested) 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --stage-list "GB200-24_GPUs-6_Nodes-PyTorch-Disagg-PerfSanity-CTX2-NODE1-GPU4-GEN1-NODE4-GPU16-Post-Merge-2,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-9,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-6,GB200-36_GPUs-9_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE8-GPU32-Post-Merge-10"

shuyixiong added 2 commits May 8, 2026 22:59
Signed-off-by: Shuyi Xiong <219646547+shuyixiong@users.noreply.github.com>
Signed-off-by: Shuyi Xiong <219646547+shuyixiong@users.noreply.github.com>
@shuyixiong shuyixiong force-pushed the user/shuyix/fix_index_error branch from ef80c2b to f54ac11 Compare May 9, 2026 06:09
@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47480 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@longlee0622 longlee0622 enabled auto-merge (squash) May 9, 2026 06:17
@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47480 [ run ] completed with state FAILURE. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37400 completed with status: 'ABORTED'

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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47485 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47485 [ run ] completed with state SUCCESS. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37405 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47530 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47530 [ run ] completed with state SUCCESS. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37447 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47546 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47546 [ run ] completed with state FAILURE. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37461 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47547 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47547 [ run ] completed with state FAILURE. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37462 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

@shuyixiong
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47581 [ run ] triggered by Bot. Commit: f54ac11 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47581 [ run ] completed with state SUCCESS. Commit: f54ac11
/LLM/main/L0_MergeRequest_PR pipeline #37491 completed with status: 'SUCCESS'

CI Report

Link to invocation

@longlee0622 longlee0622 merged commit 1f5339f into NVIDIA:main May 10, 2026
7 checks passed
yufeiwu-nv pushed a commit to yufeiwu-nv/TensorRT-LLM that referenced this pull request May 19, 2026
…oading weights (NVIDIA#13856)

Signed-off-by: Shuyi Xiong <219646547+shuyixiong@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.

5 participants