[TRTLLM-14352][perf] Fuse Qwen3.5/3.6 attention preprocessing (QK-nor…#16469
[TRTLLM-14352][perf] Fuse Qwen3.5/3.6 attention preprocessing (QK-nor…#16469nv-guomingz wants to merge 1 commit into
Conversation
…m + RoPE + gate) into a single Triton kernel Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
|
/bot run --disable-fail-fast |
|
PR_Github #59613 [ run ] triggered by Bot. Commit: |
📝 WalkthroughWalkthroughChangesThe attention implementation now supports an overridable gated-QKV preparation path and reusable output gating. QKNormRoPEAttention uses new Triton kernels for fused RMSNorm, RoPE, QKV packing, and sigmoid gating when runtime conditions allow it; Qwen3NextAttention enables the path. CUDA tests cover standard layouts, mRoPE, production compatibility, and fallback behavior. Fused QK-Norm RoPE Gating
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Qwen3NextAttention
participant Attention
participant QKNormRoPEAttention
participant FusedKernels
Qwen3NextAttention->>QKNormRoPEAttention: enable fused QK-norm RoPE gate
QKNormRoPEAttention->>Attention: provide prepared QKV and gate
Attention->>FusedKernels: normalize, apply RoPE, and pack QKV
FusedKernels-->>Attention: return QKV and gate
Attention->>FusedKernels: apply sigmoid gate to attention output
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tensorrt_llm/_torch/modules/qk_norm_attention.py (1)
268-298: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the missing Python annotations across the new fused path.
tensorrt_llm/_torch/modules/qk_norm_attention.py#L268-L298: annotate both override signatures with precise tensor and optional tuple types.tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py#L26-L294: annotate helper parameters/returns and add-> Noneto test functions.As per coding guidelines, “Annotate every function” and prefer built-in generics and
|.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tensorrt_llm/_torch/modules/qk_norm_attention.py` around lines 268 - 298, The fused path in QKNormAttention and its tests lacks required Python annotations. In tensorrt_llm/_torch/modules/qk_norm_attention.py lines 268-298, annotate _prepare_qkv_gate and apply_output_gate with precise tensor and optional tuple types; in tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py lines 26-294, annotate all helper parameters and return values and add -> None to every test function, using built-in generics and | for unions.Source: Coding guidelines
tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py (1)
210-285: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy liftAdd a production-path dispatch test.
Coverage is insufficient for the end-to-end objective: these tests call the kernels and base fallback directly, but never exercise
QKNormRoPEAttention._prepare_qkv_gateor Qwen3Next enablement. Addtest_qwen3_next_fused_qk_norm_rope_gate_dispatcheshere, asserting eligible inputs invoke both fused stages and an ineligible layout falls back.As per path instructions, provide a concrete test filename and state whether coverage is sufficient.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py` around lines 210 - 285, Coverage is not sufficient because the production dispatch path is untested. In tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py, add test_qwen3_next_fused_qk_norm_rope_gate_dispatches to exercise QKNormRoPEAttention._prepare_qkv_gate with Qwen3Next enabled, asserting eligible inputs invoke both fused stages and an ineligible layout uses the fallback path.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tensorrt_llm/_torch/modules/qk_norm_attention.py`:
- Around line 268-298: The fused path in QKNormAttention and its tests lacks
required Python annotations. In tensorrt_llm/_torch/modules/qk_norm_attention.py
lines 268-298, annotate _prepare_qkv_gate and apply_output_gate with precise
tensor and optional tuple types; in
tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py lines 26-294,
annotate all helper parameters and return values and add -> None to every test
function, using built-in generics and | for unions.
In `@tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py`:
- Around line 210-285: Coverage is not sufficient because the production
dispatch path is untested. In
tests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py, add
test_qwen3_next_fused_qk_norm_rope_gate_dispatches to exercise
QKNormRoPEAttention._prepare_qkv_gate with Qwen3Next enabled, asserting eligible
inputs invoke both fused stages and an ineligible layout uses the fallback path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 2da38cc4-97a7-412b-9fb9-5521c9ef493f
📒 Files selected for processing (5)
tensorrt_llm/_torch/models/modeling_qwen3_next.pytensorrt_llm/_torch/modules/attention.pytensorrt_llm/_torch/modules/fused_qk_norm_rope_gate.pytensorrt_llm/_torch/modules/qk_norm_attention.pytests/unittest/_torch/modules/test_fused_qk_norm_rope_gate.py
|
PR_Github #59613 [ run ] completed with state
|
…m + RoPE + gate) into a single Triton kernel
Summary by CodeRabbit
New Features
Bug Fixes
Tests
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)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.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
To see a list of available CI bot commands, please comment
/bot help.