-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[https://nvbugs/5450262][fix] Fix unsupported alltoall use case #6882
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
[https://nvbugs/5450262][fix] Fix unsupported alltoall use case #6882
Conversation
Signed-off-by: Bo Li <[email protected]>
📝 WalkthroughWalkthroughAdds a divisibility check requiring Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant FusedMoe as FusedMoeCutlass
participant Runtime as forward_chunk
Caller->>FusedMoe: call enable_alltoall()
alt all checks pass (ep_size, flags, tp_size, env, memory, experts_per_token % 4 == 0)
FusedMoe-->>Caller: True (use alltoall)
else
FusedMoe-->>Caller: False (fallback)
end
Caller->>Runtime: execute forward_chunk (alltoall path)
Runtime->>Runtime: assert top_k % 4 == 0
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 💡 Knowledge Base configuration:
You can enable these settings in your CodeRabbit configuration. 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ 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)
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this 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
🧹 Nitpick comments (2)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py (2)
189-189
: Nit: Align terminology in the inline comment.The condition uses experts_per_token, but the comment says top_k. Suggest aligning the comment with the code to avoid confusion.
- 0 # alltoall without allgather only supports top_k % 4 == 0 + 0 # alltoall without allgather only supports experts_per_token % 4 == 0
1-1
: Add NVIDIA copyright header (2025).Per coding guidelines, prepend the NVIDIA header.
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. import os
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py
: Python code must target Python 3.8+
Python indentation: 4 spaces, no tabs
Maintain module namespace in imports (from package.subpackage import foo; then use foo.SomeClass())
Python file names use snake_case
Python class names use PascalCase
Python functions/methods and local variables use snake_case; variables starting with a number get k_ prefix (e.g., k_99th_percentile)
Global variables use G_ prefixed UPPER_SNAKE_CASE (e.g., G_MY_GLOBAL)
Constants use UPPER_SNAKE_CASE in Python
Avoid shadowing variables from outer scopes in Python
Initialize all externally visible members of a Python class in init
Prefer docstrings for interfaces used outside a file; comments for local code
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes/variables inline with short docstrings
Avoid reflection when simple alternatives exist (e.g., prefer explicit parameters over dict(**locals()))
In try/except, catch the narrowest exceptions possible
For duck-typing with try/except, keep try body minimal and put logic in else
Files:
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
Prepend NVIDIA copyright header (current year) to all source files
Files:
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
🧠 Learnings (1)
📚 Learning: 2025-08-08T22:03:40.707Z
Learnt from: sklevtsov-nvidia
PR: NVIDIA/TensorRT-LLM#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:
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.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 (2)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py (2)
186-194
: Alltoall enablement guard aligns with runtime constraint; good fix.Adding the experts_per_token % 4 == 0 check makes the pre-check consistent with the runtime assertion in forward_chunk and prevents entering an unsupported path. This will avoid user-facing assertion trips and make behavior predictable at config time.
396-404
: Critical: ensure token_final_scales is non-null when use_fused_finalize is Truetoken_final_scales can become None when enable_alltoall is False and apply_router_weight_on_input is True; the CUTLASS fused finalize epilogue requires non-null router scales and this can cause crashes/UB. Ensure scales are forced to ones on the non-alltoall path when fused finalize is used.
Affected locations:
- tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py — call site around lines 396-404 (final_hidden_states invocation)
- tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py — earlier assignment where token_final_scales may be set to None (around line 258)
Suggested fix (apply when use_fused_finalize is True, before calling fused_moe):
if x_sf is not None: x_sf = swizzle_sf(x_sf, x_row, x_col, self.scaling_vector_size) + # Ensure router scales are present when using fused finalize epilogue. + # The epilogue requires non-null scales by design; fall back to 1.0. + if token_final_scales is None and self.use_fused_finalize: + token_final_scales = torch.ones_like( + token_selected_experts, dtype=torch.float32 + ) + final_hidden_states = torch.ops.trtllm.fused_moe( x, token_selected_experts, token_final_scales,Please verify and apply this guard on both alltoall and non-alltoall paths so fused finalize never receives a null scale tensor.
/bot run --post-merge |
PR_Github #15220 [ run ] triggered by Bot |
PR_Github #15220 [ run ] completed with state |
Signed-off-by: Bo Li <[email protected]>
Signed-off-by: Bo Li <[email protected]>
There was a problem hiding this 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
🧹 Nitpick comments (2)
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py (2)
56-56
: Expected continuation update is correct; harden the assertion to avoid flakinessGiven the prompt already enumerates through 8999, expecting "9000, 9001" is the correct continuation. However, the SequenceMatcher-based similarity check at Line 85 can still be brittle across backends/samplers. Prefer a substring (or regex) presence check for this numeric sequence to reduce false negatives.
You can simplify the check like this to make the test more robust:
# Replace the SequenceMatcher-based check with a containment check: for output, expected in zip(outputs, expected_outputs): output_text = output.outputs[0].text assert expected in output_text, f"Expected '{expected}' to be in '{output_text}'"Optionally, also set deterministic sampling to reduce variance:
sampling_params = SamplingParams(max_tokens=10, temperature=0.0) outputs = llm.generate(prompts, sampling_params=sampling_params)Please verify in CI across both backends that the test remains stable after this change.
74-74
: Enabling Torch sampler across the full matrix may change behavior; scope or parametrize to keep coverage and stabilityTurning on
use_torch_sampler=True
exercises a different generation path for all parameter combinations (both TRTLMM and FLASHINFER backends). That’s good for coverage but can introduce behavioral drift or flakiness vs. the default path. Consider scoping or parametrizing to cover both code paths without exploding matrix runtime.Two options:
- Scope to a representative subset (e.g., the ADP case where tp=8, ep=4, pp=1), keeping the rest on the default sampler:
# Example pattern (illustrative): use_torch_sampler = (tp_size == 8 and ep_size == 4 and pp_size == 1) llm = LLM(..., use_torch_sampler=use_torch_sampler, ...)
- Parametrize the sampler choice with a constrained matrix (only for pp1/tp8 combos) to cover both paths while keeping test volume manageable:
@pytest.mark.parametrize("use_torch_sampler", [True, False], ids=["torch_sampler", "default"]) def test_llama4(..., use_torch_sampler): ... llm = LLM(..., use_torch_sampler=use_torch_sampler, ...)Please confirm both backends fully support the Torch sampler in these configurations, and that CI remains green with the chosen scoping.
📜 Review details
Configuration used: .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 settings in your CodeRabbit configuration.
📒 Files selected for processing (1)
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py
: Python code must target Python 3.8+
Python indentation: 4 spaces, no tabs
Maintain module namespace in imports (from package.subpackage import foo; then use foo.SomeClass())
Python file names use snake_case
Python class names use PascalCase
Python functions/methods and local variables use snake_case; variables starting with a number get k_ prefix (e.g., k_99th_percentile)
Global variables use G_ prefixed UPPER_SNAKE_CASE (e.g., G_MY_GLOBAL)
Constants use UPPER_SNAKE_CASE in Python
Avoid shadowing variables from outer scopes in Python
Initialize all externally visible members of a Python class in init
Prefer docstrings for interfaces used outside a file; comments for local code
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes/variables inline with short docstrings
Avoid reflection when simple alternatives exist (e.g., prefer explicit parameters over dict(**locals()))
In try/except, catch the narrowest exceptions possible
For duck-typing with try/except, keep try body minimal and put logic in else
Files:
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
Prepend NVIDIA copyright header (current year) to all source files
Files:
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
🧠 Learnings (2)
📚 Learning: 2025-07-28T17:06:08.621Z
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/unittest/_torch/multi_gpu_modeling/test_llama4.py
📚 Learning: 2025-08-06T13:58:07.506Z
Learnt from: galagam
PR: NVIDIA/TensorRT-LLM#6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.
Applied to files:
tests/unittest/_torch/multi_gpu_modeling/test_llama4.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
Signed-off-by: Bo Li <[email protected]>
Signed-off-by: Bo Li <[email protected]>
/bot run |
PR_Github #15303 [ run ] triggered by Bot |
PR_Github #15303 [ run ] completed with state |
…IA#6882) Signed-off-by: Bo Li <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]>
…IA#6882) Signed-off-by: Bo Li <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
Summary by CodeRabbit
Bug Fixes
New Features
Tests
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 thestage-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.