feat: add qwen3 tts rope operator - #67
Open
l-wave wants to merge 2 commits into
Open
Conversation
l-wave
force-pushed
the
qwen3-tts-rope
branch
2 times, most recently
from
July 17, 2026 03:41
9baa8dd to
ce4b7a0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Qwen3-TTS oriented NeoX RoPE operator,
qwen3_tts_rope, for short-sequence TTS/code-group workloads.The new op handles standalone Q/K tensors:
q:[B, num_q_heads, seq_len, head_dim]k:[B, num_kv_heads, seq_len, head_dim]cos/sin:[B, seq_len, head_dim]bfloat16head_dim=128rotate_halfIt returns contiguous rotated Q/K tensors and exposes:
hpc.qwen3_tts_ropetorch.ops.hpc.qwen3_tts_ropesrc/rope/qwen3_tts_rope.cutests/test_tts_rope.pyMotivation
Existing hpc-ops RoPE kernels are optimized for attention/KV-cache paths, especially packed QKV + KV-cache store flows such as
rope_norm_store_kvandrope_norm_store_kv_fp8.Those kernels are not a direct fit for TTS short-sequence code-predictor style workloads where Q and K are already materialized as separate tensors and the caller only needs NeoX RoPE applied to standalone Q/K tensors.
For this TTS path, the PyTorch expression:
introduces multiple elementwise ops, intermediate tensors, and launch/dispatch overhead. This overhead is especially visible for short sequence lengths such as
S=8/16/17/32.What changed
This PR adds a dedicated fused CUDA kernel for TTS NeoX RoPE:
num_q_headsandnum_kv_headsbs <= 1:64 threads/row x 4 rows/CTAbs > 1:32 threads/row x 8 rows/CTAbs > 1inputs to reduce global load/store and conversion overheadThe PR also adds explicit input validation for the supported layout:
The test/benchmark matrix covers representative TTS-like shapes:
qwen3_tts:S=16, Hq=16, Hkv=8qwen3_tts_full_groups:S=17, Hq=16, Hkv=8small_tts:S=8, Hq=8, Hkv=4gqa1:S=17, Hq=16, Hkv=1no_gqa:S=16, Hq=8, Hkv=8wide_heads:S=32, Hq=32, Hkv=8Benchmark
Environment:
Correctness:
HPC_OPS_ROPE_ONLY_LOAD=1 pytest tests/test_tts_rope.py -q # 20 passedBenchmark result summary:
Across this representative TTS short-sequence matrix, the fused CUDA op is consistently faster than both the compiled PyTorch reference and the Triton reference.
Compared with
torch.compile, the speedup ranges from about1.97xto4.90x. Compared with the Triton reference, the speedup ranges from about1.73xto3.44x.For the largest tested workload,
wide_heads B=32, the BF16x2 path improves the standalone RoPE kernel from roughly16.52usto16.46usin this run while preserving the short-shape latency around the6.8–7.0uslaunch-dominated region.Notes
This operator is intentionally narrower than a fully generic RoPE kernel. It currently targets:
rotate_halflayouthead_dim=128It does not replace the existing packed-QKV + KV-cache RoPE kernels.