[#10780][feat] AutoDeploy: Support per-expert scales in FP8 and NVFP4 MoE#11322
Conversation
📝 WalkthroughWalkthroughThe changes refactor FP8 and NVFP4 MoE quantization to handle per-expert input scales flexibly through a new Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
tensorrt_llm/_torch/auto_deploy/custom_ops/fused_moe/triton_moe.py (1)
1-3:⚠️ Potential issue | 🟠 MajorAdd NVIDIA copyright header.
This .py source file is missing the required NVIDIA copyright header with the latest modification year.
As per coding guidelines: "All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification".📝 Suggested header
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """ Triton implementation of the Fused MOE ops. Inspired by vLLM's triton MOE implementation. """tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_trtllm_moe.py (1)
1-4:⚠️ Potential issue | 🟠 MajorAdd NVIDIA copyright header.
This .py source file is missing the required NVIDIA copyright header with the latest modification year.
As per coding guidelines: "All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification".📝 Suggested header
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """ This file contains test functions copied from: https://github.com/flashinfer-ai/flashinfer/blob/main/tests/moe/test_trtllm_cutlass_fused_moe.py """tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/triton_kernels/test_triton_moe.py (1)
1-4:⚠️ Potential issue | 🟠 MajorAdd NVIDIA copyright header.
This .py source file is missing the required NVIDIA copyright header with the latest modification year.
As per coding guidelines: "All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification".📝 Suggested header
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + import pytest import torch from utils.util import skip_pre_hoppertensorrt_llm/_torch/auto_deploy/transform/library/fused_moe.py (1)
1-18:⚠️ Potential issue | 🟠 MajorAdd NVIDIA copyright header.
This .py source file is missing the required NVIDIA copyright header with the latest modification year.
As per coding guidelines: "All TensorRT-LLM source files (.cpp, .h, .cu, .py, and other source files) should contain an NVIDIA copyright header with the year of latest meaningful modification".📝 Suggested header
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + import math from collections import defaultdict from functools import partial
🤖 Fix all issues with AI agents
In `@tensorrt_llm/_torch/auto_deploy/transform/library/fused_moe.py`:
- Around line 1742-1799: Replace the two "assert False, (message)" checks inside
the FC1 input-scale branches with explicit exceptions: where the code tests "if
not allow_different_input_scales:" (the branches that follow the w1/w3 and the
w1-only checks using w1_input_scale_stacked and w3_input_scale_stacked), raise a
descriptive exception (e.g., raise ValueError("FC1 input scales differ across
experts ... Set allow_different_input_scales=True to allow different scales
(uses min).")) instead of using assert so the validation cannot be bypassed
under -O; keep the original message text and leave the surrounding logic
(ad_logger.warning_once, fc1_act_scale, fc1_alpha_stacked computation)
unchanged.
In
`@tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_moe_fusion.py`:
- Line 11: The import of tensorrt_llm._torch.auto_deploy.custom_ops is intended
for side effects but the trailing comment marker `# noqa: F401` is unnecessary;
remove the `# noqa: F401` suffix from the import statement (the import line
referencing tensorrt_llm._torch.auto_deploy.custom_ops in test_moe_fusion.py) so
the import remains for side effects without the unused noqa marker.
- Around line 978-981: The NVFP4 alpha calculation is inverted: instead of
multiplying inp_scale by w1_scale_2/w2_scale_2, compute the reciprocal per the
comment; replace the assignments that append (inp_scale *
w1_scale_2).to(torch.float32) and (inp_scale * w2_scale_2).to(torch.float32)
with the reciprocal form 1.0 / (inp_scale * w1_scale_2) and 1.0 / (inp_scale *
w2_scale_2) respectively (cast to torch.float32) so w1_alpha and w2_alpha match
the documented 1/(input_scale*weight_scale) formula.
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_moe_fusion.py
Show resolved
Hide resolved
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_moe_fusion.py
Show resolved
Hide resolved
|
/bot run |
|
PR_Github #35003 [ run ] triggered by Bot. Commit: |
|
/bot kill |
|
PR_Github #35005 [ kill ] triggered by Bot. Commit: |
|
PR_Github #35005 [ kill ] completed with state |
|
/bot run --extra-stage "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1" |
|
PR_Github #35011 [ run ] triggered by Bot. Commit: |
|
PR_Github #35011 [ run ] completed with state
|
|
/bot run --extra-stage "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1" --disable-fail-fast |
|
PR_Github #35059 [ run ] triggered by Bot. Commit: |
|
PR_Github #35059 [ run ] completed with state
|
|
I am wondering if we want to delete this - |
bmarimuthu-nv
left a comment
There was a problem hiding this comment.
LGTM, Thanks @galagam!
It can degrade accuracy, and ModelOpt-generated models are always same-scale, which is why I went with the more conservative path of opt-in. |
…n FP8 MoE FP8 MoE kernel requires a scalar input scales, but models may have different input scales per expert. Previously, the autodeploy code used the first expert's scale (input_scale[0]), which could cause accuracy issues when scales differ significantly. Changes: - Use max(input_scale) for FC1 and FC2 input quantization, matching TRT-LLM manual backend - Precompute max input scales at transform time for both trtllm and triton backends - Add config option to FuseFP8MoeConfig: - False (default): Assert all experts have identical scales, fail if not - True: Allow different scales with a warning, use max() for quantization - Update kernel signatures to take precomputed scalar scales instead of tensor scales - Add unit test for the new config option Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
239af72 to
4c74806
Compare
|
/bot run --extra-stage "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1" --disable-fail-fast |
|
/bot run --extra-stage "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1" --disable-fail-fast |
|
/bot run |
Signed-off-by: Gal Hubara-Agam <96368689+galagam@users.noreply.github.com>
|
/bot run --extra-stage "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1" --disable-fail-fast |
|
PR_Github #35229 [ run ] triggered by Bot. Commit: |
|
PR_Github #35229 [ run ] completed with state
|
|
/bot run |
|
PR_Github #35245 [ run ] triggered by Bot. Commit: |
|
PR_Github #35245 [ run ] completed with state |
|
/bot run |
|
PR_Github #35281 [ run ] triggered by Bot. Commit: |
|
PR_Github #35281 [ run ] completed with state
|
|
/bot run |
|
PR_Github #35345 [ run ] triggered by Bot. Commit: |
|
PR_Github #35345 [ run ] completed with state |
… NVFP4 MoE (NVIDIA#11322) Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com> Signed-off-by: Gal Hubara-Agam <96368689+galagam@users.noreply.github.com> Signed-off-by: Ahmet Inci <ainci@nvidia.com>
Description
FP8 and NVFP4 MoE kernels require scalar input scales, but models may have
different input scales per expert. Previously, the autodeploy code used
the first expert's scale (input_scale[0]), which could cause accuracy
issues when scales differ significantly.
Changes:
(min is used because NVFP4 scale format is inverted: scale = 2688/amax)
This PR is replacing #10814 , adding nvfp4 support and removing superv3-specific configurations.
Test Coverage
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_moe_fusion.py::test_fp8_moe_different_input_scales
tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_moe_fusion.py::test_nvfp4_moe_different_input_scales -v
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
Update tava architecture diagram if there is a significant design change in PR.
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.
Details
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.
Summary by CodeRabbit
Release Notes
New Features
allow_different_input_scalesconfiguration option for FP8 and FP4 MoE fusion, enabling flexible per-expert input scale handling during quantization.Bug Fixes
Tests