Skip to content

[https://nvbugs/6166097][fix] Fix CuteDSL NVFP4 EPLB weight layout#15538

Merged
Shixiaowei02 merged 2 commits into
NVIDIA:mainfrom
nv-xtf:dev-tingfengx-fix-disagg-accuracy
Jun 25, 2026
Merged

[https://nvbugs/6166097][fix] Fix CuteDSL NVFP4 EPLB weight layout#15538
Shixiaowei02 merged 2 commits into
NVIDIA:mainfrom
nv-xtf:dev-tingfengx-fix-disagg-accuracy

Conversation

@nv-xtf

@nv-xtf nv-xtf commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Dynamic EPLB can migrate MoE experts by copying shared host weights into device expert slots. For CuteDSL NVFP4 MoE, the device w3/w1 weights and scales are transformed into the CuteDSL gate/up interleaved layout after loading, but the shared EPLB weights and scales were not prepared with the same layout before registration.

As a result, dynamically migrated expert slots could receive weights in the wrong layout, causing corrupted logits and near-zero DeepSeek-R1 FP4 wideep accuracy.

This PR applies the CuteDSL w3/w1 interleave to shared EPLB weights and scales before registration, so migrated expert slots match the device layout. It also updates EPLB test coverage and cleans up wideep accuracy/stress configs:
removing the force-accept speculative-decoding override (TLLM_SPEC_DECODE_FORCE_NUM_ACCEPTED_TOKENS) from accuracy configs (MTP itself is kept), and disabling accuracy gating in stress-only configs.

Test Coverage

  • Updated MoE EPLB unit test (test_configurable_moe_multi_gpu_eplb) to use the CuteDSL NVFP4 quant method for CUTEDSL coverage.
  • Increased EPLB update steps in the unit test so online expert migration is actually exercised (a single step passed even with the bug present).
  • Verified the affected DeepSeek-R1 FP4 wideep GSM8K accuracy case recovers (~0.01 -> 0.9568):
    • flexible-extract exact_match: 0.9568
    • strict-match exact_match: 0.9568
  • Ran Python compile check for modified Python files.

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.

Summary by CodeRabbit

  • New Features

    • Added extensible hook for transforming weight scales in quantized Mixture of Experts models, enabling backend-specific layout optimizations before expert migration.
  • Tests

    • Enhanced unit test coverage for Mixture of Experts models using CuteDSL and EPLB backends.
    • Updated test parameters and configurations to better validate online expert migration behavior.
    • Increased test iterations to ensure adequate expert migration during online load balancing.

@nv-xtf
nv-xtf requested a review from a team as a code owner June 23, 2026 08:40
@nv-xtf
nv-xtf requested a review from xxi-nv June 23, 2026 08:40
@nv-xtf

nv-xtf commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new overridable hook _prepare_shared_weight_scales_for_finalization to the NVFP4 fused MoE base class, called inside process_weights_after_loading before shared scale tensors are registered for online EPLB migration. NVFP4CuteDslFusedMoEMethod overrides this hook to interleave shared w3_w1 weight-scales for gated activations. Unit tests are updated to use NVFP4CuteDslFusedMoEMethod for the CuteDSL backend and run 8 EPLB steps instead of 1. Four perf benchmark YAML configs remove a forced spec-decode token env var and/or disable accuracy testing.

Changes

CuteDSL NVFP4 shared weight-scale finalization hook

Layer / File(s) Summary
Base hook definition and call site
tensorrt_llm/_torch/modules/fused_moe/quantization.py
Defines _prepare_shared_weight_scales_for_finalization as a documented no-op subclass hook, and updates process_weights_after_loading to invoke it before shared scale tensors are passed to register_all_parameter_slot_and_to_fix_weight_fns.
CuteDSL override: gate/up interleave for shared w3_w1 weight-scales
tensorrt_llm/_torch/modules/fused_moe/quantization.py
Overrides the new hook in NVFP4CuteDslFusedMoEMethod to apply gate/up interleave to shared w3_w1 weight-scale tensors when is_gated_activation is true; non-gated activations return early unchanged.
Unit test updates for CuteDSL EPLB with NVFP4
tests/unittest/_torch/modules/moe/test_moe_module.py
Imports NVFP4CuteDslFusedMoEMethod, maps it to QuantAlgo.NVFP4 in the CuteDSL backend method selector, and increases EPLB test iterations from 1 to 8.

Perf benchmark YAML config updates

Layer / File(s) Summary
Disaggregated perf YAML env-var and accuracy-test flag updates
tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_1k1k_...yaml, tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_gpqa_diamond_...yaml, tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_1k1k_...yaml, tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_...yaml
Removes TLLM_SPEC_DECODE_FORCE_NUM_ACCEPTED_TOKENS=3 from worker_env_var in two accuracy configs; sets accuracy.enable_accuracy_test to false in two stress configs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly identifies the main issue (CuteDSL NVFP4 EPLB weight layout fix) and references the bug ticket, matching the primary changes in the code.
Description check ✅ Passed The PR description thoroughly explains the problem, solution, test coverage, and includes all required checklist items with appropriate completion.
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.

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

✨ 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 (2)
tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml (1)

49-49: 📐 Maintainability & Code Quality | 🔵 Trivial

Coverage split is sufficient for this PR layer.

Coverage is appropriate with accuracy still exercised by:

  • tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_gpqa_diamond_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml

and stress-only runs now explicitly skipping accuracy in:

  • tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml

No additional follow-up test file is needed for this config-only cohort.

As per path instructions, tests/**: "Act as a QA engineer reviewing test changes and coverage for TensorRT-LLM."

🤖 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
`@tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml`
at line 49, The review comment confirms that setting enable_accuracy_test to
false in the
gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml
configuration file is appropriate because accuracy testing coverage is already
provided by dedicated accuracy test configuration files. Ensure this setting
remains in place in the stress test file, as the test coverage strategy
intentionally separates accuracy validation (handled by dedicated accuracy test
configs) from stress and performance testing (handled by stress-only test
configs that skip accuracy).

Source: Path instructions

tensorrt_llm/_torch/modules/fused_moe/quantization.py (1)

2543-2544: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Annotate the new hooks as returning None.

These hooks only mutate module state; add explicit return annotations to keep the changed Python API aligned with the repo typing rule. As per coding guidelines, “Always annotate functions with return types (use None if no return).”

Proposed typing fix
-    def _prepare_shared_weight_scales_for_finalization(self,
-                                                       module: torch.nn.Module):
+    def _prepare_shared_weight_scales_for_finalization(
+            self, module: torch.nn.Module) -> None:
@@
-    def _prepare_shared_weights_for_finalization(self, module: torch.nn.Module):
+    def _prepare_shared_weights_for_finalization(
+            self, module: torch.nn.Module) -> None:
@@
-    def _prepare_shared_weight_scales_for_finalization(self,
-                                                       module: torch.nn.Module):
+    def _prepare_shared_weight_scales_for_finalization(
+            self, module: torch.nn.Module) -> None:

Also applies to: 3073-3073, 3088-3089

🤖 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 2543 -
2544, Add explicit return type annotations to the hook methods that lack them.
The method _prepare_shared_weight_scales_for_finalization and the other hook
methods mentioned in the comment (at lines 3073 and 3088-3089) should be
annotated with -> None since they only mutate module state and do not return
values. This aligns with the repository's typing guidelines that require all
functions to have explicit return type annotations.

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/modules/fused_moe/quantization.py`:
- Around line 2543-2544: Add explicit return type annotations to the hook
methods that lack them. The method
_prepare_shared_weight_scales_for_finalization and the other hook methods
mentioned in the comment (at lines 3073 and 3088-3089) should be annotated with
-> None since they only mutate module state and do not return values. This
aligns with the repository's typing guidelines that require all functions to
have explicit return type annotations.

In
`@tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml`:
- Line 49: The review comment confirms that setting enable_accuracy_test to
false in the
gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml
configuration file is appropriate because accuracy testing coverage is already
provided by dedicated accuracy test configuration files. Ensure this setting
remains in place in the stress test file, as the test coverage strategy
intentionally separates accuracy validation (handled by dedicated accuracy test
configs) from stress and performance testing (handled by stress-only test
configs that skip accuracy).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 36f890c7-d76d-40c4-83aa-c4d5a203f3dc

📥 Commits

Reviewing files that changed from the base of the PR and between 31d4301 and 2158d4d.

📒 Files selected for processing (6)
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/scripts/perf/disaggregated/gb200_wideep_accuracy-deepseek-r1-fp4_gpqa_diamond_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_1k1k_ctx2_gen1_dep16_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/scripts/perf/disaggregated/gb200_wideep_stress-deepseek-r1-fp4_8k1k_ctx2_gen1_dep32_bs128_eplb288_mtp3_ccb-NIXL.yaml
  • tests/unittest/_torch/modules/moe/test_moe_module.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55215 [ run ] triggered by Bot. Commit: 2158d4d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55215 [ run ] completed with state FAILURE. Commit: 2158d4d

Link to invocation

@nv-xtf
nv-xtf force-pushed the dev-tingfengx-fix-disagg-accuracy branch from 2158d4d to 1807c22 Compare June 23, 2026 09:01
@nv-xtf

nv-xtf commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55219 [ run ] triggered by Bot. Commit: 1807c22 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55219 [ run ] completed with state SUCCESS. Commit: 1807c22
/LLM/main/L0_MergeRequest_PR pipeline #44179 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

@nv-xtf

nv-xtf commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55264 [ run ] triggered by Bot. Commit: 1807c22 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55264 [ run ] completed with state FAILURE. Commit: 1807c22
/LLM/main/L0_MergeRequest_PR pipeline #44219 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

@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55354 [ run ] triggered by Bot. Commit: 1807c22 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55354 [ run ] completed with state FAILURE. Commit: 1807c22
/LLM/main/L0_MergeRequest_PR pipeline #44304 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

@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55369 [ run ] triggered by Bot. Commit: 1807c22 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55369 [ run ] completed with state FAILURE. Commit: 1807c22
/LLM/main/L0_MergeRequest_PR pipeline #44318 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

@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55387 [ run ] triggered by Bot. Commit: 1807c22 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55387 [ run ] completed with state FAILURE. Commit: 1807c22
/LLM/main/L0_MergeRequest_PR pipeline #44334 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

nv-xtf added 2 commits June 24, 2026 11:47
…red EPLB weights and scales before

registration, so dynamically migrated expert slots match the device layout.

Update EPLB tests and clean up wideep accuracy/stress configs.

Signed-off-by: Tingfeng Xian <289617005+nv-xtf@users.noreply.github.com>
Signed-off-by: Tingfeng Xian <289617005+nv-xtf@users.noreply.github.com>
@nv-xtf
nv-xtf force-pushed the dev-tingfengx-fix-disagg-accuracy branch from 1807c22 to e610171 Compare June 24, 2026 03:47
@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55395 [ run ] triggered by Bot. Commit: e610171 Link to invocation

@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55395 [ run ] completed with state ABORTED. Commit: e610171
/LLM/main/L0_MergeRequest_PR pipeline #44341 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55475 [ run ] triggered by Bot. Commit: e610171 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@nv-xtf

nv-xtf commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55514 [ run ] triggered by Bot. Commit: e610171 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55514 [ run ] completed with state SUCCESS. Commit: e610171
/LLM/main/L0_MergeRequest_PR pipeline #44438 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Shixiaowei02
Shixiaowei02 merged commit a51931a into NVIDIA:main Jun 25, 2026
7 checks passed
BrianLi23 pushed a commit to BrianLi23/TensorRT-LLM that referenced this pull request Jul 9, 2026
…VIDIA#15538)

Signed-off-by: Tingfeng Xian <289617005+nv-xtf@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.

4 participants