Skip to content

[TRTLLM-6898][feat] make fused_moe_cute_dsl work on blackwell #6616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 8, 2025

Conversation

limin2021
Copy link
Collaborator

@limin2021 limin2021 commented Aug 5, 2025

Summary by CodeRabbit

  • New Features

    • Added support for an alternative matrix multiplication method controlled by a new parameter in key modules.
    • Introduced a new quantization method with enhanced weight processing for specific hardware versions.
  • Bug Fixes

    • Updated test decorators to support newer hardware generations.
  • Tests

    • Refactored and expanded tests to separately validate distinct fused MoE implementations and new configuration flags.
    • Updated CUDA graph configuration handling in tests.
  • Chores

    • Improved import statements for clarity and maintainability in evaluation and module files.

Description

Test Coverage

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@limin2021 limin2021 requested a review from a team as a code owner August 5, 2025 04:40
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

📝 Walkthrough

Walkthrough

This update refactors the FP8 block scales fused MoE quantization logic by splitting SM100-specific resmoothing and scale transformation from the base class into a new subclass. It introduces conditional selection of FP8 GEMM implementations via a new flag, updates test coverage for both implementations, and adjusts test decorators and configuration handling.

Changes

Cohort / File(s) Change Summary
Fused MoE Quantization Refactor
tensorrt_llm/_torch/modules/fused_moe/quantization.py
Refactored DeepSeekFP8BlockScalesFusedMoEMethod.load_weights to remove SM100-specific logic; introduced subclass DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm with restored resmoothing and quant scale transformation for SM100.
Fused MoE DeepGemm Quant Method Selection
tensorrt_llm/_torch/modules/fused_moe/fused_moe_deepgemm.py
Added _get_quant_method to select quantization method based on config, supporting new subclass for FP8 block scales on SM100.
Linear Layer FP8 GEMM Selection
tensorrt_llm/_torch/modules/linear.py
Added use_cute_dsl_blockscaling_mm parameter to Linear; updated FP8 GEMM logic to select implementation based on this flag.
GatedMLP Blockscaling Flag Propagation
tensorrt_llm/_torch/modules/gated_mlp.py
Added use_cute_dsl_blockscaling_mm parameter to GatedMLP and propagated it to submodules.
Unit Test Refactor and Expansion
tests/unittest/_torch/modules/test_fused_moe.py
Split and renamed FP8 blockwise tests for Cutlass and CuteDsl implementations; updated test decorators, configuration, and reference model to support new flag.
Integration Test Decorator and Config Update
tests/integration/defs/accuracy/test_llm_api_pytorch.py
Changed test decorators to @skip_pre_blackwell; updated CUDA graph config handling in test configs.
LM Eval Import Cleanup
tensorrt_llm/evaluate/lm_eval.py
Updated import for TaskManager to direct import; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Model
    participant DeepSeekFP8BlockScalesFusedMoEMethod
    participant DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm

    User->>Model: Instantiate Fused MoE with quantization
    Model->>DeepSeekFP8BlockScalesFusedMoEMethod: load_weights(...)
    alt SM version 100 and DeepGemm
        Model->>DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm: load_weights(...)
        DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm->>DeepSeekFP8BlockScalesFusedMoEMethod: super().load_weights(...)
        DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm->>DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm: Resmooth weights, transform quant scales
    else Other cases
        DeepSeekFP8BlockScalesFusedMoEMethod->>DeepSeekFP8BlockScalesFusedMoEMethod: super().load_weights(...)
    end
Loading
sequenceDiagram
    participant Linear
    participant FP8BlockScalesLinearMethod

    Linear->>FP8BlockScalesLinearMethod: apply(...)
    alt use_cute_dsl_blockscaling_mm is True
        FP8BlockScalesLinearMethod->>FP8BlockScalesLinearMethod: Use Cute DSL FP8 GEMM
    else
        FP8BlockScalesLinearMethod->>FP8BlockScalesLinearMethod: Use Deep GEMM FP8 GEMM
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Community want to contribute

Suggested reviewers

  • Tracin
  • hlu1
  • yilin-void
  • nv-guomingz
  • litaotju

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eddf7ea and 97ab168.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_deepgemm.py (2 hunks)
  • tensorrt_llm/_torch/modules/gated_mlp.py (3 hunks)
  • tensorrt_llm/_torch/modules/linear.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_deepgemm.py
  • tensorrt_llm/_torch/modules/linear.py
  • tensorrt_llm/_torch/modules/gated_mlp.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

1142-1142: Decorator change leaves neighbouring tests inconsistent

test_fp8_block_scales_4gpus right below still uses @skip_no_hopper.
If FP8 Block-Scales for the Cutlass backend also became Blackwell-only, consider updating that decorator for consistency; otherwise please document why the capability split differs between the plain and Cute-DSL paths.

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

433-433: Class naming could be more descriptive

The class name DeepSeekFP8BlockScalesFusedMoEMethodCuteDsl is quite long and the "CuteDsl" suffix might not clearly indicate its purpose. Consider a more descriptive name like DeepSeekFP8BlockScalesFusedMoEMethodBase or DeepSeekFP8BlockScalesFusedMoEMethodSimple to better reflect that this is the base implementation without SM-specific optimizations.

tests/unittest/_torch/modules/test_fused_moe.py (1)

956-957: Document the use_trtllmgen_mm parameter

Consider adding a docstring or inline comment to explain when and why this parameter should be set to True, based on the accuracy issues mentioned in line 657.

                 model_config: ModelConfig = ModelConfig(),
-                use_trtllmgen_mm: bool = False):
+                use_trtllmgen_mm: bool = False):  # Set True to avoid accuracy issues with deepgemm mm
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d53cc23 and 3270b8d.

📒 Files selected for processing (6)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py (2 hunks)
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py (2 hunks)
  • tensorrt_llm/_torch/modules/gated_mlp.py (3 hunks)
  • tensorrt_llm/_torch/modules/linear.py (3 hunks)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py (4 hunks)
  • tests/unittest/_torch/modules/test_fused_moe.py (6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, even if only one class or function from a module is used.
Python filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile = ...).
Python global variables should use upper snake_case and prefix G (e.g., G_MY_GLOBAL = ...).
Python constants should use upper snake_case (e.g., MY_CONSTANT = ...).
Avoid shadowing variables declared in an outer scope in Python.
Initialize all externally visible members of a Python class in the constructor.
For interfaces that may be used outside a file, prefer docstrings over comments in Python.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for classes and functions in Python, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py
  • tensorrt_llm/_torch/modules/gated_mlp.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tensorrt_llm/_torch/modules/linear.py
  • tests/unittest/_torch/modules/test_fused_moe.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py
  • tensorrt_llm/_torch/modules/gated_mlp.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tensorrt_llm/_torch/modules/linear.py
  • tests/unittest/_torch/modules/test_fused_moe.py
🧠 Learnings (1)
📚 Learning: in tensorrt-llm testing, it's common to have both cli flow tests (test_cli_flow.py) and pytorch api ...
Learnt from: moraxu
PR: NVIDIA/TensorRT-LLM#6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.

Applied to files:

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/unittest/_torch/modules/test_fused_moe.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (15)
tensorrt_llm/_torch/modules/linear.py (3)

464-464: LGTM: New parameter properly added to constructor.

The use_trtllmgen_mm parameter is correctly added with appropriate type annotation and default value.


481-481: LGTM: Parameter properly stored as instance variable.

The parameter is correctly stored as an instance variable for later use in the apply method.


575-575: Backend selection on Blackwell is correct

The if get_sm_version() == 100 and not module.use_trtllmgen_mm branch ensures:

  • On Blackwell (SM100) with use_trtllmgen_mm=False ⇒ deep_gemm.fp8_gemm_nt is used
  • In all other cases (including SM100 + use_trtllmgen_mm=True) ⇒ trtllm.fp8_block_scaling_gemm is used

This matches the PR objective to let users override deep_gemm on Blackwell via use_trtllmgen_mm.

tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py (2)

12-13: LGTM: Import statement properly updated.

The imports are correctly expanded to include the new quantization method classes needed for the refactored quantization system.


143-153: LGTM: Quantization method selection logic is well-structured.

The _get_quant_method helper method provides clear quantization method selection with:

  • Proper check for quantization configuration existence
  • Specific handling for FP8 block scales quantization
  • Clear error message for unsupported modes
  • Fallback to unquantized method when no quantization is enabled

The logic aligns with the refactored quantization classes mentioned in the AI summary.

tensorrt_llm/_torch/modules/gated_mlp.py (3)

41-41: LGTM: Parameter properly added to GatedMLP constructor.

The use_trtllmgen_mm parameter is correctly added with appropriate type annotation and default value, maintaining consistency with the Linear class.


79-79: LGTM: Flag properly propagated to gate_up_proj Linear layer.

The use_trtllmgen_mm flag is correctly passed to the gate_up_proj Linear instance, ensuring consistent matrix multiplication behavior.


97-97: LGTM: Flag properly propagated to down_proj Linear layer.

The use_trtllmgen_mm flag is correctly passed to the down_proj Linear instance, maintaining consistency across both Linear layers in the GatedMLP.

tests/integration/defs/accuracy/test_llm_api_pytorch.py (3)

988-988: Verify gating: @skip_pre_blackwell makes the test Blackwell-only

The test used to be skipped when no Hopper was present; with @skip_pre_blackwell it will now run only on Blackwell parts, excluding Hopper/H200.
Double-check that the kernel path exercised by CuteDslFusedMoE really requires Blackwell and is not supported on Hopper, otherwise we may lose coverage.


1013-1018: Switch to cuda_graph_config looks correct – ensure legacy use_cuda_graph is removed

The new dict drops the deprecated use_cuda_graph flag in favour of the explicit cuda_graph_config.
Confirm that:

  1. No stale use_cuda_graph keyword is still passed further down the call chain (grep in the repo).
  2. cuda_graph_config=None preserves the previous “disabled” behaviour when cuda_graph is False.

If both are true, the change is good.


1177-1182: Same update for 4-GPU variant – keep the two call sites in sync

The 4-GPU test mirrors the single-GPU one; good consistency.
As above, run a quick sweep to ensure no other helper builds pytorch_config with the old flag.

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

562-598: SM version 100 specific optimizations look correct

The implementation properly handles Blackwell-specific optimizations with appropriate conditionals and expert ID filtering. The resmoothing and scale transformation logic aligns with the PR objective of enabling fused_moe_cute_dsl on Blackwell.

tests/unittest/_torch/modules/test_fused_moe.py (3)

17-17: Import cleanup looks good

The removal of skip_non_hopper_unittest and retention of skip_pre_blackwell aligns with the PR's focus on Blackwell platform support.


561-577: Test function properly updated for CuteDsl implementation

The test function renaming and decorator change correctly reflect the shift to the new CuteDsl implementation and Blackwell platform targeting.


672-697: Multi-GPU test properly updated

The multi-GPU test correctly mirrors the single-GPU test changes, maintaining consistency across the test suite.

Signed-off-by: Mindy Li <[email protected]>
@limin2021 limin2021 requested review from yuxianq and litaotju August 5, 2025 05:22
@limin2021 limin2021 changed the title make fused_moe_cute_dsl work on blackwell. [TRTLLM-6898][feat] make fused_moe_cute_dsl work on blackwell Aug 5, 2025
Signed-off-by: Mindy Li <[email protected]>
@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14109 [ run ] triggered by Bot

Signed-off-by: Mindy Li <[email protected]>
@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14111 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14109 [ run ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14111 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10647 completed with status: 'SUCCESS'

@limin2021 limin2021 requested a review from a team as a code owner August 6, 2025 02:58
@limin2021
Copy link
Collaborator Author

/bot run

Copy link
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.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
tensorrt_llm/_torch/modules/fused_moe/quantization.py (1)

1-1: Add required NVIDIA copyright header.

The file is missing the required NVIDIA copyright header as specified in the coding guidelines for all TensorRT-LLM source files.

Add the copyright header at the beginning of the file:

+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 from abc import ABC, abstractmethod
tests/unittest/_torch/modules/test_fused_moe.py (1)

697-828: Significant code duplication between test functions.

This entire test function test_fused_moe_fp8_blockwise_cutlass is nearly identical to the CuteDsl version above, with only minor differences:

  • Uses @skip_non_hopper_unittest decorator
  • Instantiates CutlassFusedMoE instead of CuteDslFusedMoE
  • Uses use_cute_dsl_blockscaling_mm=True in reference model (Line 816)

Consider extracting the common test logic into a helper function to reduce duplication:

def _test_fused_moe_fp8_blockwise_common(moe_class, use_cute_dsl_mm, dtype, num_experts, seq_len, hidden_size, RoutingMethodCls, WeightLoadingMode, mapping=None):
    # Common test logic here
    # ...
    ref_fused_moe = RefGatedMLPFusedMoE(
        # ... other params
        use_cute_dsl_blockscaling_mm=use_cute_dsl_mm,
    )
    # ... rest of common logic

@skip_pre_blackwell
@pytest.mark.parametrize(...)
def test_fused_moe_fp8_blockwise_cute_dsl(...):
    return _test_fused_moe_fp8_blockwise_common(
        CuteDslFusedMoE, True, dtype, num_experts, seq_len, hidden_size, RoutingMethodCls, WeightLoadingMode, mapping
    )

@skip_non_hopper_unittest
@pytest.mark.parametrize(...)
def test_fused_moe_fp8_blockwise_cutlass(...):
    return _test_fused_moe_fp8_blockwise_common(
        CutlassFusedMoE, True, dtype, num_experts, seq_len, hidden_size, RoutingMethodCls, WeightLoadingMode, mapping
    )
🧹 Nitpick comments (2)
tensorrt_llm/_torch/modules/fused_moe/quantization.py (2)

569-571: Add class docstring to explain the specialized functionality.

The class lacks documentation explaining its purpose and how it differs from the base DeepSeekFP8BlockScalesFusedMoEMethod.

Add a docstring to document the class:

 class DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm(
         DeepSeekFP8BlockScalesFusedMoEMethod):
+    """
+    Specialized DeepSeek FP8 block scales quantization method for DeepGemm backend.
+    
+    This subclass adds SM version 100-specific processing including weight resmoothing
+    and scale transformation for the DeepGemm implementation.
+    """

599-609: Consider extracting scale transformation logic to reduce duplication.

The scale transformation logic for w3_w1 and w2 scales is very similar and could be extracted into a helper method to improve maintainability.

Consider extracting the transformation logic:

+    def _transform_scale_parameter(self, module, scale_tensor, weight_tensor, param_name):
+        """Transform scale tensor into required layout and create new parameter."""
+        transformed_scale = transform_sf_into_required_layout(
+            scale_tensor,
+            mn=weight_tensor.shape[1],
+            k=weight_tensor.shape[2],
+            recipe=(1, 128, 128),
+            num_groups=weight_tensor.shape[0],
+            is_sfa=False)
+        setattr(module, param_name, nn.Parameter(transformed_scale, requires_grad=False))
+
     if get_sm_version() == 100:
-        transfromed_w3_w1_scale = transform_sf_into_required_layout(
-            module.quant_scales[0],
-            mn=module.w3_w1_weight.shape[1],
-            k=module.w3_w1_weight.shape[2],
-            recipe=(1, 128, 128),
-            num_groups=module.w3_w1_weight.shape[0],
-            is_sfa=False)
-        module.w3_w1_weight_scaling_factor = nn.Parameter(
-            transfromed_w3_w1_scale, requires_grad=False)
-        transfromed_w2_scale = transform_sf_into_required_layout(
-            module.quant_scales[1],
-            mn=module.w2_weight.shape[1],
-            k=module.w2_weight.shape[2],
-            recipe=(1, 128, 128),
-            num_groups=module.w3_w1_weight.shape[0],
-            is_sfa=False)
-        module.w2_weight_scaling_factor = nn.Parameter(transfromed_w2_scale,
-                                                       requires_grad=False)
+        self._transform_scale_parameter(
+            module, module.quant_scales[0], module.w3_w1_weight, 
+            'w3_w1_weight_scaling_factor')
+        self._transform_scale_parameter(
+            module, module.quant_scales[1], module.w2_weight, 
+            'w2_weight_scaling_factor')
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d80cabe and 99b56a7.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py (1 hunks)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py (4 hunks)
  • tests/unittest/_torch/modules/test_fused_moe.py (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, even if only one class or function from a module is used.
Python filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile = ...).
Python global variables should use upper snake_case and prefix G (e.g., G_MY_GLOBAL = ...).
Python constants should use upper snake_case (e.g., MY_CONSTANT = ...).
Avoid shadowing variables declared in an outer scope in Python.
Initialize all externally visible members of a Python class in the constructor.
For interfaces that may be used outside a file, prefer docstrings over comments in Python.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tests/unittest/_torch/modules/test_fused_moe.py
**/*.{cpp,h,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tests/unittest/_torch/modules/test_fused_moe.py
🔇 Additional comments (11)
tensorrt_llm/_torch/modules/fused_moe/quantization.py (2)

574-588: LGTM! Weight resmoothing logic is correctly implemented.

The expert ID collection and weight resmoothing for SM version 100 is properly implemented. The logic correctly:

  • Collects both initial and shared expert IDs
  • Filters weights by expert membership to avoid unnecessary processing
  • Applies resmoothing to matching weight/scale pairs
  • Updates the weights dictionary in-place

591-610: Scale transformation and parameter reassignment looks correct.

The SM100-specific scale transformation logic properly:

  • Transforms both w3_w1 and w2 scales using the required layout format
  • Creates new Parameter objects with the transformed scales
  • Maintains the correct tensor shapes and device placement
  • Calls setup_quant_scales to finalize the configuration
tests/unittest/_torch/modules/test_fused_moe.py (9)

563-563: LGTM! Decorator update aligns with Blackwell platform support.

The decorator change from @skip_non_hopper_unittest to @skip_pre_blackwell correctly reflects that this test is specifically for Blackwell platform capabilities.


575-581: Function renamed to reflect CuteDsl implementation testing.

The function has been appropriately renamed from test_fused_moe_fp8_blockwise to test_fused_moe_fp8_blockwise_cute_dsl to clearly indicate it tests the CuteDsl implementation.


674-695: Reference model correctly configured for CuteDsl testing.

The reference model instantiation properly sets use_cute_dsl_blockscaling_mm=True to match the implementation being tested, ensuring accurate comparison.


831-831: LGTM! Decorator update for multi-GPU test.

The decorator change from @skip_non_hopper_unittest to @skip_pre_blackwell is consistent with the single-GPU test changes.


836-836: Function renamed to reflect CuteDsl multi-GPU testing.

The function has been appropriately renamed to test_fused_moe_fp8_blockwise_cute_dsl_multi_gpu for clarity.


840-840: Test function call updated correctly.

The call has been updated to invoke the renamed CuteDsl test function, maintaining consistency.


847-847: Weight loading mode parameter correctly specified.

The explicit specification of MoEWeightLoadingMode.VANILLA ensures consistent test behavior.


1115-1116: New parameter addition supports implementation selection.

The addition of use_cute_dsl_blockscaling_mm: bool = False parameter allows the reference model to use different matrix multiplication implementations for comparison purposes.


1133-1133: Parameter correctly passed to GatedMLP constructor.

The use_cute_dsl_blockscaling_mm parameter is properly forwarded to the GatedMLP constructor, enabling the correct implementation path.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14214 [ run ] triggered by Bot

@limin2021
Copy link
Collaborator Author

/bot run

Copy link
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unittest/_torch/modules/test_fused_moe.py (1)

575-828: Consider refactoring to reduce code duplication.

The two test functions test_fused_moe_fp8_blockwise_cute_dsl and test_fused_moe_fp8_blockwise_cutlass have nearly identical logic with only minor differences in implementation class and reference model configuration. This violates the DRY principle and increases maintenance burden.

Consider extracting common test logic into a helper function:

def _test_fused_moe_fp8_blockwise_impl(moe_class, use_cute_dsl_mm, dtype, num_experts, seq_len, hidden_size, RoutingMethodCls, WeightLoadingMode, mapping=None):
    # Common test implementation
    # ...
    
    fused_moe = moe_class(...)
    ref_fused_moe = RefGatedMLPFusedMoE(..., use_cute_dsl_blockscaling_mm=use_cute_dsl_mm)
    # ...

@skip_pre_blackwell
@pytest.mark.parametrize(...)
def test_fused_moe_fp8_blockwise_cute_dsl(...):
    return _test_fused_moe_fp8_blockwise_impl(CuteDslFusedMoE, True, ...)

@skip_non_hopper_unittest  
@pytest.mark.parametrize(...)
def test_fused_moe_fp8_blockwise_cutlass(...):
    return _test_fused_moe_fp8_blockwise_impl(CutlassFusedMoE, False, ...)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99b56a7 and b59a9ad.

📒 Files selected for processing (1)
  • tests/unittest/_torch/modules/test_fused_moe.py (8 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, even if only one class or function from a module is used.
Python filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile = ...).
Python global variables should use upper snake_case and prefix G (e.g., G_MY_GLOBAL = ...).
Python constants should use upper snake_case (e.g., MY_CONSTANT = ...).
Avoid shadowing variables declared in an outer scope in Python.
Initialize all externally visible members of a Python class in the constructor.
For interfaces that may be used outside a file, prefer docstrings over comments in Python.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the docstring for the class.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tests/unittest/_torch/modules/test_fused_moe.py
**/*.{cpp,h,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tests/unittest/_torch/modules/test_fused_moe.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (5)
tests/unittest/_torch/modules/test_fused_moe.py (5)

563-695: LGTM! Test refactoring properly separates CuteDsl implementation testing.

The function rename and decorator change align with the PR objective to enable fused_moe_cute_dsl on Blackwell. The use of CuteDslFusedMoE and the use_cute_dsl_blockscaling_mm=True parameter in the reference model ensure this test specifically validates the new implementation path.


836-894: Multi-GPU test structure looks good.

The separation of multi-GPU tests for both implementations follows a clean pattern, with appropriate decorator updates. The delegation to single-GPU test functions maintains consistency.

However, this inherits the same reference model configuration issue from test_fused_moe_fp8_blockwise_cutlass that should be addressed.


1152-1170: LGTM! Parameter addition follows good practices.

The new use_cute_dsl_blockscaling_mm parameter is properly added with a sensible default value and correctly passed through to the GatedMLP constructor. This maintains backward compatibility while enabling the new functionality.


17-17: Import usage is appropriate for platform-specific testing.

The continued import of skip_non_hopper_unittest is correct since it's still used for the Cutlass-specific tests that don't support pre-Hopper platforms, while skip_pre_blackwell is used for the new CuteDsl tests that require Blackwell or newer.


564-894: Comprehensive test coverage for both implementations.

The test suite now provides thorough coverage for both CuteDsl and Cutlass implementations, including:

  • Single-GPU and multi-GPU scenarios
  • Multiple weight loading modes
  • Consistent parameter ranges across implementations

This ensures both implementation paths are properly validated.

Signed-off-by: Mindy Li <[email protected]>
@tensorrt-cicd
Copy link
Collaborator

PR_Github #14217 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14214 [ run ] completed with state ABORTED

@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14223 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14217 [ run ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14223 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10743 completed with status: 'FAILURE'

@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14348 [ run ] triggered by Bot

@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14413 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14348 [ run ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14413 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10895 completed with status: 'FAILURE'

@limin2021
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14520 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14520 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #10968 completed with status: 'SUCCESS'

@yuxianq yuxianq merged commit d913955 into NVIDIA:main Aug 8, 2025
4 checks passed
rakib-hasan added a commit to rakib-hasan/TensorRT-LLM that referenced this pull request Aug 9, 2025
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