[None][perf] Fuse Qwen Image QK norm RoPE prep - #16129
Conversation
Signed-off-by: Alex Steiner <asteiner@nvidia.com>
📝 WalkthroughWalkthroughAdds a utility converting Qwen complex RoPE frequencies to cos/sin format, enables a fused QK-norm+RoPE attention path in QwenJointAttention conditional on tensor-parallel size, refactors QKV preparation into dispatching methods, updates forward's attention-mask handling, and adds corresponding unit tests. ChangesFused QK-norm+RoPE attention path
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Forward as QwenJointAttention.forward
participant Prepare as _prepare_qkv
participant FusedPath as _prepare_qkv_fused
participant Convert as qwen_complex_freqs_to_cos_sin
participant PackedOp as apply_packed_qk_norm_rope
Forward->>Prepare: request joint Q/K/V
Prepare->>FusedPath: dispatch when fused eligible
FusedPath->>Convert: convert text/image RoPE freqs
Convert-->>FusedPath: cos, sin tensors
FusedPath->>PackedOp: apply packed QK-norm+RoPE
PackedOp-->>FusedPath: normalized/rotated qkv
FusedPath-->>Prepare: split per-head Q/K/V
Prepare-->>Forward: flattened joint Q/K/V
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py (1)
254-282: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAdd explicit coverage for the supported fused path.
Coverage is sufficient for CPU fallback, but insufficient for the PR’s CUDA bf16 fused path: this test uses CPU and
attention_head_dim=8, while_use_fused_qk_norm_ropeonly enables fusion for CUDA bf16 with head dims64/128/256. Please add or follow up with a GPU-gated test intests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.pythat exercises_prepare_qkv_fusedor compares fused vs. unfused outputs for a supported head dim.As per path instructions, test feedback should state whether coverage is sufficient or needs follow-up outside the PR.
🤖 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/visual_gen/test_qwen_image_pipeline_config.py` around lines 254 - 282, Coverage here only exercises the CPU fallback in QwenImageTransformer2DModel and does not validate the supported fused path. Add a GPU-gated test in test_qwen_image_pipeline_config that runs the CUDA bf16 fused configuration for a supported attention_head_dim (64, 128, or 256), and explicitly exercise _use_fused_qk_norm_rope / _prepare_qkv_fused or compare fused vs. unfused outputs. Keep the existing CPU test for fallback, but note in the test coverage that fused-path validation is handled by the new GPU-specific case.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 `@tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py`:
- Around line 254-282: Coverage here only exercises the CPU fallback in
QwenImageTransformer2DModel and does not validate the supported fused path. Add
a GPU-gated test in test_qwen_image_pipeline_config that runs the CUDA bf16
fused configuration for a supported attention_head_dim (64, 128, or 256), and
explicitly exercise _use_fused_qk_norm_rope / _prepare_qkv_fused or compare
fused vs. unfused outputs. Keep the existing CPU test for fallback, but note in
the test coverage that fused-path validation is handled by the new GPU-specific
case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: d32a5e7a-2427-435c-97f5-dfe4d0a53941
📒 Files selected for processing (2)
tensorrt_llm/_torch/visual_gen/models/qwen_image/transformer_qwen_image.pytests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py
416244f to
d2c8936
Compare
Signed-off-by: Alex Steiner <pst2154@users.noreply.github.com>
d2c8936 to
413ad91
Compare
|
Closing this in favor of the combined clean Qwen VisualGen perf PR: #16142. That PR includes this QK-norm/RoPE work plus the related mask, adaLN, and NVFP4 GELU fixes in one reviewable branch. |
Summary
Tests
Notes
Summary by CodeRabbit
New Features
Bug Fixes
Tests