-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[https://nvbugs/5461712] [fix] Disable deep_gemm for Qwen3 due to accuracy issues #7170
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/5461712] [fix] Disable deep_gemm for Qwen3 due to accuracy issues #7170
Conversation
Signed-off-by: Dom Brown <[email protected]>
Signed-off-by: Dom Brown <[email protected]>
📝 WalkthroughWalkthroughAdds a disable_deep_gemm flag across Linear, Attention, and GatedMLP, wires it through Qwen3Attention and Qwen3DecoderLayer to disable deep_gemm for Qwen3, and updates FP8 path selection in Linear based on SM version and the flag. Adds a PyTorch test entry targeting the related bug. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Model as Qwen3 Model Init
participant Attn as Attention
participant MLP as GatedMLP
participant Lin as Linear
Model->>Attn: __init__(..., disable_deep_gemm=True)
Attn->>Lin: qkv_proj(..., disable_deep_gemm=True)
Attn->>Lin: o_proj(..., disable_deep_gemm=True)
Model->>MLP: __init__(..., disable_deep_gemm=True)
MLP->>Lin: gate_up_proj(..., disable_deep_gemm=True)
MLP->>Lin: down_proj(..., disable_deep_gemm=True)
note over Lin: Runtime matmul selection (FP8 path)
Lin->>Lin: if SM==100 and not disable_deep_gemm → deep_gemm<br/>else → FP8 block-scales GEMM
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
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. ✨ 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/models/modeling_qwen3.py (1)
122-127
: init has an invalid return annotationConstructor init must return None; annotating it as Tuple[torch.Tensor, torch.Tensor] is incorrect and harms static typing.
Apply this diff:
- def __init__( + def __init__( self, model_config: ModelConfig[Qwen3Config], layer_idx: int, - ) -> Tuple[torch.Tensor, torch.Tensor]: + ) -> None:
🧹 Nitpick comments (10)
tensorrt_llm/_torch/modules/gated_mlp.py (2)
31-33
: Expose and document the new disable_deep_gemm flag on GatedMLPGood addition. Two small improvements:
- Please document this new public parameter in a Google-style docstring for init.
- Consider storing it on the module (e.g., self.disable_deep_gemm = disable_deep_gemm) for easier introspection/debugging.
You can add the attribute right after super().init:
self.disable_deep_gemm = disable_deep_gemm
1-7
: Missing NVIDIA copyright headerPer the repository coding guidelines, all Python sources should have the NVIDIA copyright header (current year). Please add it.
Add at file top:
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License");tensorrt_llm/_torch/models/modeling_qwen3.py (3)
48-50
: Make disabling deep_gemm configurable rather than hard-codedHard-coding True limits rollout/rollback flexibility. Prefer reading from ModelConfig.extra_attrs (with True as default) so we can flip via config without code change.
Apply this diff to derive the flag from config:
- # Qwen3 has accuracy issues with deep_gemm (see: https://nvbugspro.nvidia.com/bug/5461712) - disable_deep_gemm = True + # Qwen3 has accuracy issues with deep_gemm (see: NVBUG 5461712) + # Make it configurable so it can be flipped without code changes. + disable_deep_gemm = bool(getattr(model_config, "extra_attrs", {}).get( + "disable_deep_gemm_for_qwen3", True))
135-137
: Mirror the configurability for the MLP pathSame configurability suggestion for the MLP to keep Attention and MLP behavior consistent.
- # Qwen3 has accuracy issues with deep_gemm (see: https://nvbugspro.nvidia.com/bug/5461712) - disable_deep_gemm = True + # Qwen3 deep_gemm accuracy issue (NVBUG 5461712) + disable_deep_gemm = bool(getattr(model_config, "extra_attrs", {}).get( + "disable_deep_gemm_for_qwen3", True))
1-6
: Missing NVIDIA copyright headerPlease add the standard header.
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License");tensorrt_llm/_torch/modules/attention.py (2)
117-118
: New disable_deep_gemm flag and docstring entry look good; clarify scopeThe parameter is correctly added and documented. Minor doc improvement: note that this flag currently only affects the FP8 Block-Scales linear path.
Apply this diff to augment the docstring:
- disable_deep_gemm (bool): Whether to disable deep_gemm for linear layers. + disable_deep_gemm (bool): Whether to disable deep_gemm for linear layers. + Note: This currently affects only FP8 Block-Scales Linear kernels.Also applies to: 136-137
1-8
: Missing NVIDIA copyright headerPlease add the standard header at the top.
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License");tensorrt_llm/_torch/modules/linear.py (3)
575-585
: Add robust fallback when deep_gemm extension is unavailableOn some environments, the deep_gemm extension might not be built/available for SM100. Importing it inside the hot path without a fallback risks ImportError at runtime. Recommend try/except and fallback to the fp8_block_scaling_gemm path.
Apply this diff:
- if get_sm_version() == 100 and not module.disable_deep_gemm: - from tensorrt_llm import deep_gemm - a, a_sf = fp8_utils.per_token_quant_and_transform(input) - output = torch.empty((input.shape[0], module.weight.shape[0]), - device=input.device, - dtype=torch.bfloat16) - deep_gemm.fp8_gemm_nt((a, a_sf), - (module.weight, module.weight_scale), - output, - disable_ue8m0_cast=True) + if get_sm_version() == 100 and not module.disable_deep_gemm: + try: + from tensorrt_llm import deep_gemm + a, a_sf = fp8_utils.per_token_quant_and_transform(input) + output = torch.empty((input.shape[0], module.weight.shape[0]), + device=input.device, + dtype=torch.bfloat16) + deep_gemm.fp8_gemm_nt((a, a_sf), + (module.weight, module.weight_scale), + output, + disable_ue8m0_cast=True) + except (ImportError, AttributeError): + # Fallback to the FP8 block-scales GEMM if deep_gemm is unavailable + act_input_fp8, act_input_sf = torch.ops.trtllm.fp8_quantize_1x128(input) + output = torch.ops.trtllm.fp8_block_scaling_gemm( + act_input_fp8, module.weight, act_input_sf, module.weight_scale)
1484-1485
: Expose and minimally document disable_deep_gemm on LinearAdding the flag here and storing it on the module makes sense. Consider documenting the parameter in a short init docstring (Google-style) since this is a public API used by many modules.
Also applies to: 1501-1502
1-1
: Missing NVIDIA copyright headerPlease add the standard header.
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License");
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
tensorrt_llm/_torch/models/modeling_qwen3.py
(3 hunks)tensorrt_llm/_torch/modules/attention.py
(4 hunks)tensorrt_llm/_torch/modules/gated_mlp.py
(3 hunks)tensorrt_llm/_torch/modules/linear.py
(3 hunks)tests/integration/test_lists/test-db/l0_b200.yml
(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/linear.py
tensorrt_llm/_torch/modules/gated_mlp.py
tensorrt_llm/_torch/models/modeling_qwen3.py
tensorrt_llm/_torch/modules/attention.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/linear.py
tensorrt_llm/_torch/modules/gated_mlp.py
tensorrt_llm/_torch/models/modeling_qwen3.py
tensorrt_llm/_torch/modules/attention.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_b200.yml
🧬 Code graph analysis (2)
tensorrt_llm/_torch/modules/linear.py (1)
tensorrt_llm/_utils.py (1)
get_sm_version
(681-683)
tensorrt_llm/_torch/models/modeling_qwen3.py (1)
tensorrt_llm/_torch/modules/gated_mlp.py (1)
GatedMLP
(19-176)
🔇 Additional comments (7)
tensorrt_llm/_torch/modules/gated_mlp.py (2)
69-71
: Correct propagation of disable_deep_gemm into gate_up_projPassing the flag into Linear here is correct and consistent with the intent of the PR.
88-90
: Correct propagation of disable_deep_gemm into down_projSame here—looks good, aligns the MLP path with the attention path behavior.
tests/integration/test_lists/test-db/l0_b200.yml (1)
45-45
: ✅ Duplicate Check & Test Existence Verified
- Confirmed there is only one entry for
accuracy/test_llm_api_pytorch.py::TestQwen3_8B::test_fp8_block_scales[latency]
intests/integration/test_lists/test-db/l0_b200.yml
(line 45).- Confirmed
class TestQwen3_8B
and itstest_fp8_block_scales
method are defined in
tests/integration/defs/accuracy/test_llm_api_pytorch.py
.No further action needed.
tensorrt_llm/_torch/models/modeling_qwen3.py (2)
64-65
: Correctly plumbs the flag into the Attention baseLooks good; this ensures qkv_proj/o_proj will honor the flag in the FP8 Block-Scales path.
144-145
: Correct propagation into GatedMLPPassing disable_deep_gemm into GatedMLP ensures both gate_up and down projections respect the setting.
tensorrt_llm/_torch/modules/attention.py (2)
216-218
: Correct propagation of disable_deep_gemm into qkv_projPlumbing looks correct.
233-235
: Correct propagation of disable_deep_gemm into o_projPlumbing looks correct.
/bot run |
PR_Github #16189 [ run ] triggered by Bot |
/bot run |
PR_Github #16222 [ run ] triggered by Bot |
PR_Github #16222 [ run ] completed with state |
…uracy issues (#7170) Signed-off-by: Dom Brown <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
…uracy issues (NVIDIA#7170) Signed-off-by: Dom Brown <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
Summary by CodeRabbit
New Features
Bug Fixes
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.