Skip to content

Conversation

@bobboli
Copy link
Collaborator

@bobboli bobboli commented Oct 28, 2025

  • Enable MnnvlThroughput for TrtllmGenMoE.
  • TrtllmGenMoE supports being provided the output tensor by user. Currently only modified w4a8_mxfp4_mxfp8 for gpt-oss.
  • Decouple max_num_tokens and runtime_max_num_tokens_per_rank for MnnvlThroughput. Due to the changes, integration inside CutlassMoE is also adapted.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added new "mnnvlthroughput" backend option for MoE all-to-all operations with improved metadata-driven layout management.
    • Introduced metainfo-based initialization for workspace and offset tracking, enabling more flexible auxiliary data organization.
  • Refactor

    • Reorganized MoE dispatch and combine operation parameters to use runtime token counts and centralized metadata structures.
    • Updated internal metadata indexing and offset calculations for improved scalability and maintainability.

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.

@bobboli bobboli marked this pull request as ready for review October 31, 2025 08:23
@bobboli bobboli requested review from a team as code owners October 31, 2025 08:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

📝 Walkthrough

Walkthrough

This refactoring restructures the MoE all-to-all communication system around a unified workspace model with metadata-driven offsets. The namespace is renamed to MnnvlThroughput, parameter structs are reorganized to consolidate auxiliary data and distributed counters, and Python bindings are updated to support runtime-configurable token counts and metainfo-based initialization. A new MoeAlltoAll class manages state and workspace lifecycle, with support for backend selection via environment variables.

Changes

Cohort / File(s) Summary
C++ Kernel Interfaces
cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu, cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
Namespace renamed from tensorrt_llm::kernels::moe_a2a to tensorrt_llm::kernels::MnnvlThroughput. Structs MoeA2ADispatchParams and MoeA2ACombineParams reorganized with new fields for distributed counters, routing metadata (topk_target_ranks, topk_send_indices), CUDA streams, and unified buffer layout. Function signatures unchanged but now under new namespace.
Meta-info and Offset Management
cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
Added <array> include and nested MnnvlThroughput namespace. Enum MoeA2AMetaInfoIndex now has explicit int64_t underlying type; added TOPK_TARGET_RANKS_OFFSET_INDEX and TOPK_SEND_INDICES_OFFSET_INDEX entries; NUM_METAINFO_FIELDS increased from 7 to 9. Introduced MoeA2ADataOffsets type alias as std::array<int64_t, NUM_METAINFO_FIELDS>.
PyTorch Operation Implementation
cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
Added moeA2AInitializeOp for workspace initialization and metainfo generation. Updated calculateOffsets to return MoeA2ADataOffsets. Modified signatures of moeA2ADispatchOp, moeA2ACombineOp, moeA2ASanitizeExpertIdsOp, and moeA2AGetCombinePayloadTensorOp to accept metainfo and use runtime-derived token counts. Kernel parameter population now derives pointers from rank-specific workspace regions. Updated TORCH_LIBRARY bindings.
Python Bindings
cpp/tensorrt_llm/nanobind/thop/bindings.cpp, cpp/tensorrt_llm/pybind/thop/bindings.cpp
Updated MoE A2A constants export to call torch_ext::MnnvlThroughput::getMoeA2AMetaInfoIndexPairs() instead of torch_ext::getMoeA2AMetaInfoIndexPairs().
Python Runtime Core
tensorrt_llm/_torch/distributed/moe_alltoall.py
Introduced _A2AState container for operation state tracking. Replaced per-field offset constants with _METAINFO_INDEX dictionary populated from C++ offsets. Renamed max_num_tokens_per_rank to max_num_tokens throughout. Added MnnvlMemory.initialize() invocation and unified workspace/metainfo storage in _WORKSPACE. Updated dispatch, combine, and get_combine_payload_tensor_in_workspace signatures to accept runtime_max_tokens_per_rank and use metainfo-derived offsets.
MoE Module Integration
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
Updated max_num_token references to use per-rank max_tokens_per_rank in alltoall preparation calls and tensor sizing for result combination. Runtime path derives runtime_max_tokens_per_rank from input shape.
MoE Fused Module Configuration
tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
Added moe_alltoall_backend cached_property (reads TRTLLM_MOE_ALLTOALL_BACKEND; default "mnnvllatency"). Added MoeAlltoAll import. Constructor branches on backend: "mnnvllatency" retains existing MnnvlMemory/MnnvlMoe initialization; "mnnvlthroughput" initializes MoeAlltoAll instance with workspace size from TRTLLM_MOE_A2A_WORKSPACE_MB environment variable. Forward pass includes backend-specific dispatch/combine logic with appropriate parameter transformation for each.
MoE A2A Tests
tests/unittest/_torch/multi_gpu/test_moe_a2a.py
Replaced per-rank max token assumption with global max_num_tokens derived as max(all_num_tokens). Updated dispatch calls to accept and use runtime_max_tokens_per_rank. Changed return handling from recv_buffers to recv_tensors with metainfo-based offset lookups for counters and routing metadata. Verification logic updated to validate new tensor-based data structures and extended shape checks for metainfo-derived offsets.

Sequence Diagram(s)

sequenceDiagram
    participant Python as Python Runtime
    participant Init as Initialize Op
    participant Dispatch as Dispatch Op
    participant Combine as Combine Op
    participant Kernel as CUDA Kernels

    Python->>Init: moeA2AInitializeOp(workspace, epRank, epSize, maxNumTokens)
    Init->>Init: calculateOffsets(epSize, maxNumTokens)
    Init->>Kernel: Write offsets to metainfo tensor
    Init-->>Python: metainfo tensor

    Python->>Dispatch: dispatch(tokens, payloads, workspace, metainfo, runtime_max_tokens_per_rank, ...)
    Dispatch->>Dispatch: Parse metainfo offsets
    Dispatch->>Dispatch: Populate MoeA2ADispatchParams from workspace regions
    Dispatch->>Kernel: Launch kernel with derived pointers
    Kernel->>Kernel: Process routing & all-to-all
    Kernel-->>Dispatch: Update counters/flags in workspace
    Dispatch-->>Python: recv_tensors, combine_payload_offset

    Python->>Combine: combine(payload, runtime_max_tokens_per_rank, workspace, metainfo, ...)
    Combine->>Combine: Parse metainfo offsets
    Combine->>Combine: Populate MoeA2ACombineParams from workspace regions
    Combine->>Kernel: Launch combine kernel
    Kernel-->>Combine: Combined output
    Combine-->>Python: result tensor
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • Workspace layout and offset calculations (cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp): Verify that offset calculations are correct for all new metainfo fields and that pointer derivation for each rank matches the unified workspace layout.
  • Metainfo indexing consistency (cpp/tensorrt_llm/thop/moeAlltoAllMeta.h and usage sites): Ensure enum indices match across C++ and Python layers; audit all _METAINFO_INDEX lookups in Python.
  • Backend branching logic (tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py): Verify that parameter transformation and tensor reshaping differ correctly between "mnnvllatency" and "mnnvlthroughput" paths; check environment variable handling and fallback behavior.
  • Kernel parameter population (cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp): Confirm that all new fields (flag_val, send_counters, topk_target_ranks, etc.) are correctly extracted from workspace and passed to kernel structs.
  • Python state management (tensorrt_llm/_torch/distributed/moe_alltoall.py): Validate _A2AState transitions and that metainfo is correctly propagated across dispatch/combine phases.
  • Test verification coverage (tests/unittest/_torch/multi_gpu/test_moe_a2a.py): Check that all new tensor-based counters and routing metadata are correctly validated with correct shape expectations.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.64% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ⚠️ Warning The pull request description is largely incomplete and does not adequately follow the repository's PR template structure. While the author provided three bullet points at the beginning summarizing the changes (enabling MnnvlThroughput for TrtllmGenMoE, supporting user-provided output tensors, and decoupling max_num_tokens and runtime_max_num_tokens_per_rank), the required template sections are either missing or contain only placeholder comments. The "Description" section lacks any explanation of the issue and solution, the "Test Coverage" section is entirely empty with no list of relevant tests, and the PR title is absent in the required format of [JIRA/NVBugs/GitHub/None][type] Summary. Additionally, the PR Checklist items are not addressed or checked. The author should complete the PR description by filling out all required sections: add a proper PR title following the format [ticket_id][type] summary, provide a detailed description explaining the issue and the solution beyond the bullet points, list the relevant test cases that validate these changes (such as tests in test_moe_a2a.py based on the changes summary), and address or check off items from the PR Checklist. This will ensure reviewers have adequate context for understanding the scope and impact of these significant structural changes to the MoE all-to-all communication system.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "[feat] Integrate MnnvlThroughput into TRTLLM MoE" accurately reflects the primary objective and scope of the changes. The changeset consistently demonstrates this integration across multiple layers: namespace reorganization from moe_a2a to MnnvlThroughput, introduction of a new MoeAlltoAll Python class, addition of backend selection logic in fused_moe_trtllm_gen.py, and updates to C++ kernel parameters and function signatures. The title is clear, concise, and specific enough that a teammate scanning the commit history would immediately understand that a new throughput-focused all-to-all implementation is being integrated into the existing MoE system.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unittest/_torch/multi_gpu/test_moe_a2a.py (1)

518-553: Align invalid-expert sentinel in tests with runtime contract.

The runtime now needs invalid_expert_id == num_experts (see Line 424 in the module), but the test still injects and asserts -1 (Lines 518, 553, 596, 667). Once the dispatch fix lands, these expectations will flip the tests red and mask regressions. Please derive the sentinel from the same value (ep_size * num_experts_per_rank) and update all related assertions/fixtures (e.g., Lines 466-467) so the test exercises the real contract.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae57738 and e92c05e.

📒 Files selected for processing (10)
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu (3 hunks)
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h (5 hunks)
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp (1 hunks)
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp (1 hunks)
  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h (2 hunks)
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp (9 hunks)
  • tensorrt_llm/_torch/distributed/moe_alltoall.py (5 hunks)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py (5 hunks)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py (6 hunks)
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py (16 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}: Namespace closing braces must include a trailing comment with the namespace name (e.g., '} // namespace foo').
Prefer const or constexpr variables over #define for constants.
Declare variables that are not modified after initialization as const.
Avoid magic literals in code; except for 0, nullptr, true, false. Use named constants for comparisons and logic.
Use Allman brace style for formatting.
Place the semicolon of an empty for/while loop on a new line.
Bodies of switch/while/do-while/for must be compound statements (brace-delimited), and if/else must always be followed by brace-delimited statements.
Type names (e.g., classes) must be CamelCase starting with an uppercase letter (e.g., FooBar).
Local variables, methods, and namespaces use lowerCamelCase (e.g., localFooBar).
Non-magic-number global variables that are non-static and not in an anonymous namespace must be lowerCamelCase prefixed with 'g' (e.g., gDontUseGlobalFoos).
Non-magic-number globals that are static or in an anonymous namespace use lowerCamelCase prefixed with 's' (e.g., sMutableStaticGlobal).
Locally visible static variables use lowerCamelCase with 's' prefix (e.g., static std::once_flag sFlag).
Private/protected member variables use 'm' prefix with CamelCase (e.g., mNbFooValues). Public members may omit, but 'm' is encouraged for clarity.
Constants (enums, global constants, static constants, and function-scope magic/literal constants) use uppercase SNAKE_CASE with 'k' prefix (e.g., kDIGIT_NUM).
Function-scope constants that are not magic numbers or literals are named like non-constant variables (e.g., bool const pass = a && b).
If macros are necessary, name them in UPPER_SNAKE_CASE (e.g., FOO_VERSION) and prefer constants over #define.
Use LLVM clang-format; wrap lines at a maximum of 120 columns; use '// clang-format off/on' sparingly with justification.
Use smart pointers for heap allocations; prefer unique_ptr for sole ownership, shared_ptr for shared...

Files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
**/*.{cpp,cxx,cc,cu,h,hpp,hh,hxx,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

C++ filenames should be lowerCamelCase (first letter lowercase) and must be case-insensitive unique within a compilation target.

Files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • tensorrt_llm/_torch/distributed/moe_alltoall.py
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • tensorrt_llm/_torch/distributed/moe_alltoall.py
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • tensorrt_llm/_torch/distributed/moe_alltoall.py
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
**/*.{h,hpp,hh,hxx}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Document new class interfaces and function prototypes with Doxygen; use //! for single-line and //!< for members.

Files:

  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.{h,hpp,hh,hxx,cpp,cxx,cc}: Prefer anonymous namespaces over 'static' for internal linkage of functions.
All templates (class/function/member/static) must be instantiated at least once; non-POD classes should have private data members.

Files:

  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
**/*.{h,hpp,hh,hxx,cuh}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use include guards named 'TRTLLM_<FILE_NAME_IN_CAPS_WITH_UNDERSCORES>_H' (no leading or trailing underscore; directory names excluded).

Files:

  • cpp/tensorrt_llm/thop/moeAlltoAllMeta.h
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
🧠 Learnings (19)
📚 Learning: 2025-08-19T03:35:20.866Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 6915
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:4616-4626
Timestamp: 2025-08-19T03:35:20.866Z
Learning: In the MOE profiler TMA workspace preparation (cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu), the overlapping of TMA WS regions for NONE and FINALIZE variants is deliberate design to save memory space, as confirmed by djns99. The comment "reuse the same pointers to save space" reflects this intentional behavior.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-21T02:39:12.009Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 7104
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:1475-1480
Timestamp: 2025-08-21T02:39:12.009Z
Learning: The min latency mode functionality in TensorRT-LLM MOE kernels (cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu) is deprecated and no longer being maintained/updated, as confirmed by djns99. Bug reports and optimization suggestions for the computeStridesTmaWarpSpecializedLowLatencyKernel and related min latency code paths should be deprioritized.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-09-23T15:01:00.070Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/kernels/nccl_device/config.cu:15-17
Timestamp: 2025-09-23T15:01:00.070Z
Learning: In TensorRT-LLM NCCL device kernels, the <sstream> header is not needed as an explicit include in config.cu because it's provided transitively through other headers. Local compilation testing confirms this works without the explicit include.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-09-02T13:42:44.885Z
Learnt from: pcastonguay
Repo: NVIDIA/TensorRT-LLM PR: 7455
File: tensorrt_llm/_torch/pyexecutor/py_executor.py:1852-1860
Timestamp: 2025-09-02T13:42:44.885Z
Learning: In MPI communication within TensorRT-LLM pipeline parallelism, different communication types (tokens, logits, termination sync) must use disjoint tag namespaces to avoid message routing collisions when using the same source/destination patterns.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-09T20:57:04.084Z
Learnt from: sklevtsov-nvidia
Repo: NVIDIA/TensorRT-LLM PR: 3294
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_gemm_tma_warp_specialized_input.cu:118-127
Timestamp: 2025-08-09T20:57:04.084Z
Learning: In the CUTLASS MoE finalize fusion implementation (cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_gemm_tma_warp_specialized_input.cu), when setting `fused_finalize_epilogue.stride_final_output` with shape `(hidden_size, num_output_tokens, 1)`, the `num_rows_in_final_output` should be set to `num_output_tokens` (not `hidden_size`) because of a swap+transpose operation that maps rows of the output tensor to `hidden_size` and columns to `num_output_tokens`.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
📚 Learning: 2025-08-14T23:23:27.449Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 6915
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:4010-4012
Timestamp: 2025-08-14T23:23:27.449Z
Learning: For MOE (Mixture of Experts) code reviews in TensorRT-LLM, avoid repeatedly suggesting finalize fusion validation checks and safety assertions. The user djns99 has indicated these suggestions are repetitive and unwanted across multiple MOE-related changes.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
  • cpp/tensorrt_llm/nanobind/thop/bindings.cpp
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
📚 Learning: 2025-08-20T07:43:36.447Z
Learnt from: ChristinaZ
Repo: NVIDIA/TensorRT-LLM PR: 7068
File: cpp/tensorrt_llm/kernels/moeTopKFuncs.cuh:169-172
Timestamp: 2025-08-20T07:43:36.447Z
Learning: In TensorRT-LLM MOE kernels, when processing up to 128 experts across 32 threads, each thread handles at most 4 experts (N < 5 constraint), where N represents candidates per thread rather than total system capacity.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
  • tests/unittest/_torch/multi_gpu/test_moe_a2a.py
📚 Learning: 2025-09-23T15:01:00.070Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/kernels/nccl_device/config.cu:15-17
Timestamp: 2025-09-23T15:01:00.070Z
Learning: In TensorRT-LLM NCCL device kernels (cpp/tensorrt_llm/kernels/nccl_device/config.cu), std::ostringstream is used but <sstream> doesn't need to be explicitly included because it's provided transitively through other headers like tensorrt_llm/common/cudaUtils.h or config.h. Local compilation testing confirms this works without the explicit include.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-21T02:41:10.565Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 7104
File: cpp/tensorrt_llm/kernels/cutlass_kernels/include/moe_gemm_kernels.h:141-145
Timestamp: 2025-08-21T02:41:10.565Z
Learning: In TensorRT-LLM MOE GEMM kernels (cpp/tensorrt_llm/kernels/cutlass_kernels/include/moe_gemm_kernels.h), the stride_act and stride_weight pointers in TmaWarpSpecializedGroupedGemmInput are intentionally declared as void* rather than typed pointers because the actual stride type is determined at runtime based on factors like the swap_ab flag and layout decisions. This runtime type determination makes compile-time type safety impossible, so void* is the correct approach.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-08T22:03:40.707Z
Learnt from: sklevtsov-nvidia
Repo: NVIDIA/TensorRT-LLM PR: 3294
File: cpp/tensorrt_llm/kernels/cutlass_kernels/moe_gemm/moe_kernels.cu:1198-1209
Timestamp: 2025-08-08T22:03:40.707Z
Learning: In the CUTLASS MoE kernels (cpp/tensorrt_llm/cutlass_extensions), when `layout_info.fusion` is set to `TmaWarpSpecializedGroupedGemmInput::EpilogueFusion::FINALIZE`, the `router_scales` parameter must be non-null by design. The fused finalize kernel epilogue does not perform nullptr checks and requires valid router scales to function correctly. This is an implicit contract that callers must satisfy when enabling the FINALIZE fusion mode.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-09-19T21:28:13.751Z
Learnt from: jhaotingc
Repo: NVIDIA/TensorRT-LLM PR: 7856
File: cpp/tensorrt_llm/thop/fp8BlockScaleMoe.cpp:159-166
Timestamp: 2025-09-19T21:28:13.751Z
Learning: In TensorRT-LLM blockScaleMoe routing (cpp/tensorrt_llm/kernels/trtllmGenKernels/blockScaleMoe/runner.cu), the DeepSeek routing method performs reinterpret_cast<float*>(routingLogits) at line 89, which could cause issues if routing_logits are BF16. However, Qwen3-FP8 models use RenormalizeNaive routing method and are not affected by this dtype casting issue.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-09-23T15:13:48.819Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/kernels/nccl_device/multimem.h:20-30
Timestamp: 2025-09-23T15:13:48.819Z
Learning: TRT-LLM targets modern CUDA toolkits that support FP8 datatypes, so cuda_fp8.h can be included unconditionally without version guards in TRT-LLM code.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-09-23T14:58:05.372Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/kernels/nccl_device/config.cu:42-49
Timestamp: 2025-09-23T14:58:05.372Z
Learning: In TensorRT-LLM NCCL device kernels (cpp/tensorrt_llm/kernels/nccl_device/), the token partitioning intentionally uses ceil-like distribution (same token_per_rank for all ranks) to ensure all ranks launch the same number of blocks. This is required for optimal NCCL device API barrier performance, even though it may launch extra blocks for non-existent tokens on later ranks. Runtime bounds checking in the kernel (blockID validation) handles the overshoot cases.

Applied to files:

  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-14T21:04:50.248Z
Learnt from: thorjohnsen
Repo: NVIDIA/TensorRT-LLM PR: 6910
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-14T21:04:50.248Z
Learning: In KV cache onboarding logic during prefill in cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, when calculating which blocks fall within the attention window, use getTokensPerBlock() to advance token indices rather than block->getUniqueTokens().size(), because the calculation needs to consider the post-prefill state where blocks will be filled to capacity, not their current token count.

Applied to files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
📚 Learning: 2025-08-21T21:48:35.135Z
Learnt from: djns99
Repo: NVIDIA/TensorRT-LLM PR: 7104
File: cpp/tensorrt_llm/cutlass_extensions/include/cutlass_extensions/epilogue/fusion/sm90_visitor_scatter.hpp:399-417
Timestamp: 2025-08-21T21:48:35.135Z
Learning: CUTLASS extensions in TensorRT-LLM (located under cpp/tensorrt_llm/cutlass_extensions/) are designed to integrate with and extend functionality in the external CUTLASS repository. When analyzing these extensions, their consumers and functionality wiring may exist in the CUTLASS codebase rather than within TensorRT-LLM itself.

Applied to files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
📚 Learning: 2025-08-19T12:45:11.997Z
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:0-0
Timestamp: 2025-08-19T12:45:11.997Z
Learning: In tensorrt_llm/_torch/pyexecutor/model_engine.py, DoRA (Delta Orthogonal Rank Adaptation) functionality was removed from the PyTorch flow to eliminate issues with inverted DoRA detection logic. The original is_dora condition was checking if scaling_vec_pointer == 0, which was potentially incorrect.

Applied to files:

  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
📚 Learning: 2025-08-14T06:36:40.701Z
Learnt from: timlee0212
Repo: NVIDIA/TensorRT-LLM PR: 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_trtllm_gen.py
  • tensorrt_llm/_torch/distributed/moe_alltoall.py
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
📚 Learning: 2025-08-26T06:07:02.166Z
Learnt from: shaharmor98
Repo: NVIDIA/TensorRT-LLM PR: 7231
File: tensorrt_llm/_torch/pyexecutor/_util.py:504-509
Timestamp: 2025-08-26T06:07:02.166Z
Learning: In tensorrt_llm/_torch/pyexecutor/_util.py, when calling model_engine.set_lora_model_config(), pass model_binding_config.mlp_hidden_size directly without multiplying by mapping.tp_size, as the mlp_hidden_size from get_bindings_model_config() is already the per-TP rank value needed for LoRA weight packaging.

Applied to files:

  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
📚 Learning: 2025-10-20T16:54:09.824Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:6-6
Timestamp: 2025-10-20T16:54:09.824Z
Learning: In tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py, the import `from ...modules.mamba.layernorm_gated import _layer_norm_fwd` is correct and should not be changed to modules.fla.layernorm_gated. The _layer_norm_fwd function exists in both modules/mamba/layernorm_gated.py and modules/fla/layernorm_gated.py, but the mamba version is the intended implementation for this use case.

Applied to files:

  • cpp/tensorrt_llm/pybind/thop/bindings.cpp
🧬 Code graph analysis (6)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py (1)
tensorrt_llm/_torch/distributed/moe_alltoall.py (2)
  • get_combine_payload_tensor_in_workspace (215-235)
  • combine (184-213)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py (2)
tensorrt_llm/_torch/distributed/moe_alltoall.py (3)
  • MoeAlltoAll (26-235)
  • dispatch (140-182)
  • combine (184-213)
tensorrt_llm/_mnnvl_utils.py (7)
  • MnnvlMemory (53-338)
  • MnnvlMoe (352-624)
  • get_moe_workspaces (360-376)
  • get_moe_prepare_workspace (379-390)
  • mnnvl_moe_alltoallv_prepare_without_allgather (402-446)
  • mnnvl_moe_alltoallv (531-592)
  • mnnvl_moe_alltoallv_combine (595-624)
tensorrt_llm/_torch/distributed/moe_alltoall.py (2)
tensorrt_llm/mapping.py (2)
  • Mapping (336-493)
  • moe_ep_rank (205-206)
tensorrt_llm/_mnnvl_utils.py (2)
  • MnnvlMemory (53-338)
  • as_torch_strided_tensor (84-88)
cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp (2)
cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu (6)
  • moe_a2a_dispatch_launch (500-565)
  • moe_a2a_dispatch_launch (500-500)
  • moe_a2a_combine_launch (874-927)
  • moe_a2a_combine_launch (874-874)
  • moe_a2a_sanitize_expert_ids_launch (951-959)
  • moe_a2a_sanitize_expert_ids_launch (951-952)
cpp/tensorrt_llm/common/envUtils.cpp (2)
  • getEnvMoeA2AOneBlockPerToken (459-468)
  • getEnvMoeA2AOneBlockPerToken (459-459)
cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h (1)
cpp/tensorrt_llm/thop/moeAlltoAllMeta.h (1)
  • MnnvlThroughput (26-62)
tests/unittest/_torch/multi_gpu/test_moe_a2a.py (1)
tensorrt_llm/_torch/distributed/moe_alltoall.py (3)
  • MoeAlltoAll (26-235)
  • dispatch (140-182)
  • combine (184-213)
🪛 Clang (14.0.6)
cpp/tensorrt_llm/thop/moeAlltoAllMeta.h

[error] 19-19: 'array' file not found

(clang-diagnostic-error)

🪛 Ruff (0.14.2)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py

143-145: Avoid specifying long messages outside the exception class

(TRY003)


446-448: Avoid specifying long messages outside the exception class

(TRY003)


736-738: Avoid specifying long messages outside the exception class

(TRY003)

tensorrt_llm/_torch/distributed/moe_alltoall.py

99-99: Avoid specifying long messages outside the exception class

(TRY003)


101-101: Avoid specifying long messages outside the exception class

(TRY003)


223-225: Avoid specifying long messages outside the exception class

(TRY003)

tests/unittest/_torch/multi_gpu/test_moe_a2a.py

598-600: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


624-624: Unused function argument: dtype

(ARG001)


722-722: Unused function argument: hidden_size

(ARG001)


722-722: Unused function argument: num_experts_per_rank

(ARG001)

⏰ 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

@bobboli bobboli changed the title [feat][None] Integrate MnnvlThroughput into TRTLLM MoE. [None][feat] Integrate MnnvlThroughput into TRTLLM MoE. Oct 31, 2025
@bobboli bobboli requested a review from a team as a code owner October 31, 2025 15:45
@bobboli bobboli requested a review from liji-nv October 31, 2025 15:45
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.

1 participant