Skip to content

Conversation

xxi-nv
Copy link
Collaborator

@xxi-nv xxi-nv commented Sep 1, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a pluggable MoE backend with automatic runtime selection based on hardware and quantization, improving performance and compatibility.
    • Added a public API to run MoE via the selected backend, with support for fused finalize and tuner controls (token count, top-k).
    • Enhanced FP8 block-wise quantization path with version-aware optimizations.
  • Tests

    • Added comprehensive multi-GPU tests validating FP8 block-wise MoE correctness across varying sequence lengths and all-to-all configurations, including cross-checks against a reference implementation.

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

  • 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

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

@xxi-nv xxi-nv requested a review from a team as a code owner September 1, 2025 06:11
@xxi-nv xxi-nv requested a review from mikeiovine September 1, 2025 06:11
@xxi-nv
Copy link
Collaborator Author

xxi-nv commented Sep 1, 2025

This PR depends on #7422

@xxi-nv xxi-nv force-pushed the supportFP8BlockWideEp_release branch from 2d4604d to d3074c1 Compare September 1, 2025 06:21
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Caution

Review failed

Failed to post review comments.

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e326632 and 354d27f.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (9 hunks)
  • tensorrt_llm/_torch/modules/fused_moe/moe_backend.py (1 hunks)
  • tests/unittest/_torch/modules/test_fused_moe.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{cpp,cc,cxx,cu,h,hpp,hh,hxx,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{cpp,cc,cxx,cu,h,hpp,hh,hxx,cuh,py}: Use spaces only; no tabs; indent with 4 spaces
Prepend NVIDIA copyright header (current year) to all source files (.cpp, .h, .cu, .py, etc.)

Files:

  • tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
  • tests/unittest/_torch/modules/test_fused_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+
Indent Python with 4 spaces; no tabs
Preserve module namespaces when importing: from package.subpackage import foo; then call foo.SomeClass() instead of importing the class directly
Python naming: files snake_case; classes PascalCase; functions/methods snake_case; locals snake_case (prefix k_ when starting with a number); globals UPPER_SNAKE_CASE with G_ prefix; constants UPPER_SNAKE_CASE
Avoid shadowing outer-scope variables; initialize all externally visible members in init
Prefer docstrings for interfaces used outside a file; limit comments to function-internal or file-local interfaces
Use Google-style docstrings for classes and functions; document attributes/variables inline so Sphinx can render them
Avoid reflection when simpler alternatives exist; prefer explicit parameters and return dicts over locals()/dynamic tricks
In try/except, catch the narrowest exceptions possible; keep try bodies minimal and use else for the main logic when doing duck-typing checks

Files:

  • tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
  • tests/unittest/_torch/modules/test_fused_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
🧠 Learnings (1)
📚 Learning: 2025-08-14T06:36:40.701Z
Learnt from: timlee0212
PR: NVIDIA/TensorRT-LLM#6886
File: tensorrt_llm/_torch/models/modeling_deepseekv3.py:0-0
Timestamp: 2025-08-14T06:36:40.701Z
Learning: In DeepSeek V3 model (tensorrt_llm/_torch/models/modeling_deepseekv3.py), the disagreement between AllReduce.__init__ guard and _compute_mlp_tp_size logic for MNNVL usage is expected by design. The AllReduce component and MLP TP-size computation intentionally use different criteria for MNNVL availability decisions.

Applied to files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
🧬 Code graph analysis (3)
tensorrt_llm/_torch/modules/fused_moe/moe_backend.py (4)
tensorrt_llm/_torch/modules/fused_moe/interface.py (2)
  • MoE (22-181)
  • has_deepseek_fp8_block_scales (127-130)
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (1)
  • MoERunner (27-121)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (1)
  • enable_alltoall (297-300)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_deepgemm.py (5)
  • deepgemm_fp8_group_blockwise_gemm (298-336)
  • masked_index_copy_group_quant_fp8 (88-159)
  • preprocess_after_permute (259-294)
  • set_strides (339-345)
  • triton_masked_index_gather (194-215)
tests/unittest/_torch/modules/test_fused_moe.py (7)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (1)
  • AlltoallMethodType (30-38)
tensorrt_llm/_utils.py (5)
  • dtype (935-936)
  • dtype (943-953)
  • mpi_rank (486-487)
  • shape (939-940)
  • shape (956-957)
tensorrt_llm/_torch/modules/fused_moe/routing.py (1)
  • DefaultMoeRoutingMethod (184-210)
tensorrt_llm/mapping.py (1)
  • Mapping (32-513)
tensorrt_llm/quantization/utils/fp8_utils.py (1)
  • per_block_cast_to_fp8_e8m0 (54-79)
tests/unittest/_torch/helpers.py (1)
  • per_block_cast_to_fp8_e8m0 (55-68)
tensorrt_llm/models/modeling_utils.py (2)
  • QuantConfig (128-268)
  • quant_algo (547-548)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (2)
tensorrt_llm/_torch/modules/fused_moe/moe_backend.py (5)
  • MoEBackend (17-179)
  • MoEBackendSelection (748-791)
  • select_backend (760-791)
  • run_moe (111-179)
  • run_moe (375-457)
tensorrt_llm/_torch/modules/fused_moe/quantization.py (2)
  • DeepSeekFP8BlockScalesFusedMoEMethod (604-737)
  • DeepSeekFP8BlockScalesFusedMoEMethodDeepGemm (740-781)
⏰ 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
📝 Walkthrough

Walkthrough

Adds a pluggable MoE backend abstraction with Cutlass and DeepGemm implementations, integrates lazy backend selection and invocation into WideEPMoE, updates quantization method gating by SM version, and introduces a multi-GPU FP8 blockwise Wide MoE unit test comparing outputs against a DeepGemm reference.

Changes

Cohort / File(s) Summary
MoE backend abstraction
tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
New module defining MoEBackend interface, concrete MoECutlassBackend and MoEDeepGemmBackend, and MoEBackendSelection.select_backend(module) with SM-version and flag-based routing; provides finalize_tactic, compute_moe, and run_moe APIs.
WideEPMoE integration and API
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
Replaces direct fused kernel call with self.moe_backend_impl.run_moe(...); introduces lazy moe_backend_impl property and _moe_backend_impl field; imports backend types and SM/version-gated DeepSeek FP8 method (DeepGemm on SM100); adjusts logging imports; tracks unpadded_hidden_size.
Tests for FP8 blockwise Wide MoE
tests/unittest/_torch/modules/test_fused_moe.py
Adds multi-GPU test test_fused_moe_fp8_blockwise_wide_ep validating WideEPMoE FP8 blockwise outputs against a DeepGemm reference across token lengths and alltoall variants, with MPI-based per-rank execution and FP8 weight generation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Caller
  participant W as WideEPMoE
  participant S as MoEBackendSelection
  participant C as MoECutlassBackend
  participant D as MoEDeepGemmBackend

  U->>W: forward(...)

  alt Backend not initialized
    W->>S: select_backend(self)
    alt SM==100 and has_deepseek_fp8_block_scales
      S-->>W: MoEDeepGemmBackend
      W->>D: cache instance as moe_backend_impl
    else
      S-->>W: MoECutlassBackend
      W->>C: cache instance as moe_backend_impl
    end
  end

  W->>W: prepare inputs/weights/quant_scales
  opt Tuning/finalize
    W->>+moe_backend_impl: finalize_tactic(tuner_input, ...)
    moe_backend_impl-->>-W: tactics ready / no-op
  end
  W->>+moe_backend_impl: run_moe(input, tokens, weights, scales, ...)
  moe_backend_impl-->>-W: final_hidden_states
  W-->>U: output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • hyukn
  • hlu1
  • yuxianq
  • litaotju
  • QiJune
✨ 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.
    • 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.
  • 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 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/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@xxi-nv
Copy link
Collaborator Author

xxi-nv commented Sep 1, 2025

/bot run

@xxi-nv xxi-nv requested review from kaiyux and QiJune and removed request for mikeiovine September 1, 2025 06:28
@QiJune QiJune requested a review from yuxianq September 1, 2025 13:39
@kaiyux kaiyux force-pushed the supportFP8BlockWideEp_release branch from abfad92 to 17b76e3 Compare September 1, 2025 22:40
@kaiyux
Copy link
Member

kaiyux commented Sep 1, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17258 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17258 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #7 completed with status: 'FAILURE'

@yuxianq yuxianq requested a review from litaotju September 2, 2025 03:59
@xxi-nv xxi-nv force-pushed the supportFP8BlockWideEp_release branch from 17b76e3 to 029204e Compare September 3, 2025 03:12
@ziyixiong-nv
Copy link
Collaborator

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17475 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17475 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #40 completed with status: 'FAILURE'

@ziyixiong-nv
Copy link
Collaborator

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17513 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17513 [ run ] completed with state FAILURE
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #44 completed with status: 'FAILURE'

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17576 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #51 completed with status: 'FAILURE'

@kaiyux kaiyux force-pushed the supportFP8BlockWideEp_release branch from 029204e to 29ebc85 Compare September 4, 2025 16:59
@kaiyux
Copy link
Member

kaiyux commented Sep 4, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17698 [ run ] triggered by Bot

@kaiyux kaiyux enabled auto-merge (squash) September 4, 2025 23:31
@ziyixiong-nv
Copy link
Collaborator

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17722 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17722 [ run ] completed with state DISABLED
L0 testing is limited to prioritized users. User ziyixiong-nv is not in the prioritized list. L0 testing cannot be triggered.

@litaotju
Copy link
Collaborator

litaotju commented Sep 5, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17729 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17698 [ run ] completed with state ABORTED

@litaotju
Copy link
Collaborator

litaotju commented Sep 5, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17751 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17729 [ run ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17751 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #76 completed with status: 'FAILURE'

Signed-off-by: xxi <[email protected]>

	modified:   tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
	modified:   tests/unittest/_torch/modules/test_fused_moe.py

	modified:   tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
	modified:   tests/unittest/_torch/modules/test_fused_moe.py
Signed-off-by: xxi <[email protected]>

	modified:   tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
	deleted:    tensorrt_llm/_torch/modules/fused_moe/moe_backend.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/ops/__init__.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/ops/moe_op.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/ops/moe_op_cutlass.py
	new file:   tensorrt_llm/_torch/modules/fused_moe/ops/moe_op_deepgemm.py
auto-merge was automatically disabled September 7, 2025 14:47

Head branch was pushed to by a user without write access

@xxi-nv xxi-nv force-pushed the supportFP8BlockWideEp_release branch from ad0f413 to d41f571 Compare September 7, 2025 14:47
@kaiyux
Copy link
Member

kaiyux commented Sep 7, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17945 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17945 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #89 completed with status: 'FAILURE'

@xxi-nv
Copy link
Collaborator Author

xxi-nv commented Sep 7, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@kaiyux
Copy link
Member

kaiyux commented Sep 8, 2025

bot run --disable-fail-fast --add-multi-gpu-test

@kaiyux
Copy link
Member

kaiyux commented Sep 8, 2025

/bot run --disable-fail-fast --add-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17961 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #17961 [ run ] completed with state SUCCESS
/LLM/release-1.1.0rc2/L0_MergeRequest_PR pipeline #90 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@kaiyux kaiyux merged commit 3299435 into NVIDIA:release/1.1.0rc2 Sep 8, 2025
5 checks passed
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.

7 participants