-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][fix] Add FP4 all2all unitest and fix a bug for module WideEPMoE #6784
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
[None][fix] Add FP4 all2all unitest and fix a bug for module WideEPMoE #6784
Conversation
📝 WalkthroughWalkthroughAdds two new FP4 all-to-all fused MoE tests to the DGX B200 integration list and introduces a new parameterized FP4 all-to-all validation test in the unittest suite, targeting multiple all-to-all method variants and running per-rank verifications across token lengths. Changes
Sequence Diagram(s)sequenceDiagram
participant PyTest as PyTest
participant Test as test_fused_moe_alltoall_fp4
participant Pool as MPIPoolExecutor
participant Rank as Per-Rank Worker
participant Wide as WideEPMoE
participant Ref as CutlassFusedMoE
PyTest->>Test: invoke with alltoall_method_type
Test->>Pool: map per-rank verifications
loop for each rank
Pool->>Rank: run rank verification
Rank->>Wide: forward(inputs, FP4 weights, method)
Rank->>Ref: forward(inputs, FP4 weights)
Rank->>Rank: compare outputs (assert_close)
end
Pool-->>Test: results aggregated
Test-->>PyTest: pass/fail
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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
|
|
/bot run |
|
PR_Github #14767 [ run ] triggered by Bot |
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 (1)
tests/unittest/_torch/modules/test_fused_moe.py (1)
291-474: Comprehensive FP4 all-to-all test with good coverage.This test provides excellent coverage for FP4 quantization with all-to-all methods. The structure mirrors the existing
test_fused_moe_alltoalland properly tests all three method types (MNNVL, DeepEP, DeepEPLowLatency).Key strengths:
- Proper FP4 weight quantization setup using
torch.ops.trtllm.fp4_quantize- Correct scaling factor calculations (global and per-block)
- Proper mocking of
select_alltoall_method_typeto force specific methods- Multi-token-length validation for robustness
Note on tolerance values: The test uses higher tolerance values (
rtol=0.05, atol=0.5) compared to the non-quantized version (rtol=0.05, atol=0.003). This is expected due to quantization precision loss, but theatol=0.5seems quite high. Consider verifying this is appropriate for FP4 quantization accuracy expectations.Optional improvement: Consider extracting the FP4 weight setup logic into a helper function to reduce code duplication and improve maintainability, especially if similar patterns are needed in other tests.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py(1 hunks)tests/integration/test_lists/test-db/l0_dgx_b200.yml(1 hunks)tests/unittest/_torch/modules/test_fused_moe.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py: Python code 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 Python file, prefer docstrings over comments.
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 class docstring.
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_wide_ep.pytests/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_wide_ep.pytests/unittest/_torch/modules/test_fused_moe.py
🧠 Learnings (1)
📚 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/integration/test_lists/test-db/l0_dgx_b200.yml
🧬 Code Graph Analysis (1)
tests/unittest/_torch/modules/test_fused_moe.py (7)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (2)
AlltoallMethodType(26-34)load_weights(1044-1049)tensorrt_llm/_torch/modules/fused_moe/routing.py (1)
DefaultMoeRoutingMethod(184-200)tensorrt_llm/mapping.py (1)
Mapping(20-453)tensorrt_llm/models/modeling_utils.py (2)
QuantConfig(128-268)quant_algo(547-548)tensorrt_llm/quantization/mode.py (1)
QuantAlgo(23-46)tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py (3)
load_weights(569-574)CutlassFusedMoE(25-574)forward(458-567)tensorrt_llm/_torch/models/modeling_utils.py (3)
load_weights(535-553)forward(242-271)forward(507-533)
🔇 Additional comments (2)
tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py (1)
536-536: LGTM! Keyword argument renamed for better clarity.The change from
swizzedLayout=FalsetoisSfSwizzledLayout=Falseimproves readability by making the boolean parameter's meaning clearer. The new name better conveys what a True/False value represents.tests/integration/test_lists/test-db/l0_dgx_b200.yml (1)
18-19: LGTM! New FP4 all-to-all tests added appropriately.The new test entries are properly formatted and logically placed in the test suite. The selection of only DeepEP and DeepEPLowLatency variants (excluding MNNVL) appears intentional for the B200 test configuration.
|
PR_Github #14767 [ run ] completed with state |
|
/bot run |
|
PR_Github #14783 [ run ] triggered by Bot |
|
PR_Github #14783 [ run ] completed with state |
|
/bot run |
|
PR_Github #14843 [ run ] triggered by Bot |
|
PR_Github #14843 [ run ] completed with state |
|
/bot run |
|
PR_Github #14908 [ run ] triggered by Bot |
|
PR_Github #14908 [ run ] completed with state |
|
/bot run |
|
PR_Github #14928 [ run ] triggered by Bot |
|
PR_Github #14928 [ run ] completed with state |
|
/bot run |
|
PR_Github #14951 [ run ] triggered by Bot |
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: 2
🧹 Nitpick comments (1)
tests/unittest/_torch/modules/test_fused_moe.py (1)
291-298: Consider extracting the duplicate parameter setup into a shared fixture or helper functionThe test function
test_fused_moe_alltoall_fp4has nearly identical parameterization, GPU requirements, and configuration constants (Lines 291-306) astest_fused_moe_alltoall(Lines 184-198). This duplication could be reduced by extracting common setup into a shared fixture or helper function.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unittest/_torch/modules/test_fused_moe.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py: Python code 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 Python file, prefer docstrings over comments.
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 class docstring.
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,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:
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 (6)
tests/unittest/_torch/modules/test_fused_moe.py (6)
322-323: Potential precision loss in FP4 scaling factor calculationThe global scaling factor calculation (Line 323) uses hardcoded magic numbers (448 * 6) that appear to be FP4-specific constants. However, the division by
x_abs_maxcould result in precision issues ifx_abs_maxis very small or zero.Consider adding a small epsilon to prevent division by zero and document the meaning of the magic numbers:
- x_abs_max = torch.cat([x.flatten() for x in x_list]).abs().max().float() - x_sf_global = (448 * 6) / x_abs_max + x_abs_max = torch.cat([x.flatten() for x in x_list]).abs().max().float() + # FP4 quantization range constant (448 * 6 = 2688) + # Add epsilon to prevent division by zero + x_sf_global = (448 * 6) / (x_abs_max + 1e-8)
343-345: Important constraint: w3 and w1 global scales must matchThe code enforces that w3 and w1 global scaling factors must be identical (Lines 343-345), which is a critical constraint for the FP4 quantization scheme. This constraint should be documented more prominently.
Good implementation of the FP4 constraint that w3 and w1 must share the same global scaling factor. The use of
min()ensures the smaller scale is used for both, preventing overflow.
408-421: LGTM: Proper use of QuantConfig for FP4 quantizationThe instantiation of WideEPMoE with the NVFP4 quantization configuration (Lines 408-421) is correctly implemented, passing the quant_config through the ModelConfig.
291-473: Test coverage looks comprehensive for FP4 all-to-all functionalityThe test thoroughly validates the FP4 quantization path with all-to-all communication patterns, testing multiple sequence lengths and comparing against a reference implementation. The parameterization covers different all-to-all method types (MNNVL, DeepEP, DeepEPLowLatency).
349-362: Confirm block_scale_interleave_reverse usage and view dimensionsThe
block_scale_interleave_reversecall is used consistently across tests and utils, but please double-check that the reverse-swizzle logic and subsequent.view(...)calls correctly realign the scale blocks:• tests/unittest/_torch/modules/test_fused_moe.py (L349–362)
• tests/unittest/_torch/multi_gpu/test_user_buffers.py
• tests/unittest/_torch/thop/test_fp4_linear.py
• tensorrt_llm/_torch/utils.py (post-reverse.view(-1, sf_cols))
• tensorrt_llm/_torch/custom_ops/cpp_custom_ops.py (fake reverse op)– Verify that the INTERMEDIATE_SIZE and HIDDEN_SIZE passed to
.view(...)match the original swizzle block dimensions.
– Ensure the C++ implementation ofblock_scale_interleave_reversetruly inverts the swizzle pattern used infp4_quantize.
– Confirm no off-by-one or interleaving misalignment occurs when un-swizzling on CPU vs. GPU.
378-389: Scale assignment pattern validated — no changes neededThe reciprocal assignments to
.w1.input_scale,.w2.input_scale,.w3.input_scale
and
.w1.weight_scale_2,.w2.weight_scale_2,.w3.weight_scale_2
intests/unittest/_torch/modules/test_fused_moe.pyfollow the same conventions used by the quantization loaders in
tensorrt_llm/_torch/modules/fused_moe/quantization.py
and by the FP4/FP8 custom kernels across the codebase. Existing unit tests (includingtest_fused_moe.pyitself and the broader quantization suite) exercise and pass on these keys, confirming that the forward implementations consume these reciprocal scale values correctly.
|
PR_Github #14951 [ run ] completed with state |
|
/bot run |
Signed-off-by: Jiang Shao <91270701+StudyingShao@users.noreply.github.com>
3f75790 to
c79c3dd
Compare
|
/bot run |
|
/bot run |
|
PR_Github #15144 [ run ] triggered by Bot |
|
PR_Github #15144 [ run ] completed with state |
|
/bot run --extra-stage "DGX_B200-4_GPUs-PyTorch-Post-Merge-1" |
|
PR_Github #16326 [ ] completed with state |
|
Hi @StudyingShao , |
Summary by CodeRabbit
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-listparameter 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.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip 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-pipelineReuse 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.