[Perf][Attention] Vectorize causal-conv metadata offsets - #55469
waizuichougou wants to merge 1 commit into
Conversation
Signed-off-by: waizuichougou <2082431897@qq.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. WalkthroughThe causal convolution metadata path now computes per-row chunk offsets with vectorized NumPy operations and creates pinned tensors through ChangesCausal convolution metadata
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to The metadata construction is vectorized while retaining the pinned staging path and existing contract; supplied tests pass with no merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
Purpose
compute_causal_conv1d_metadatabuilds the per-chunk offsets used by causal-convolution prefill kernels. The current implementation creates these offsets with a Python loop that callsextend(range(...))once for every sequence. This host-side work grows with both the prefill batch size and the total number of 8-token chunks, delaying the following Triton launch.This change derives the same per-row offsets with NumPy prefix sums and repeated row starts, then keeps the result in the existing pinned
int32staging-tensor path. The metadata contract and kernel inputs are unchanged. The helper is shared by Mamba, GDN, ShortConv, and Kimi K3 attention backends.Test Plan
Existing kernel regression suite and changed-file checks:
The metadata output was also compared with the original implementation over 2,000 randomized CPU cases, including empty batches, zero-length rows, mixed chunk counts, and both
int32andint64cumulative-length inputs. The resulting metadata was exercised throughcausal_conv1d_fnon an NVIDIA A100 over four targeted variable-length batches, with kernel output and convolution-state updates bitwise identical to the inline/original metadata path.End-to-end metadata construction benchmark on an NVIDIA A100 PCIe 40GB, including device-buffer allocation, metadata H2D copies, and CUDA synchronization. Sequence lengths are equal within each row. Results are medians of 100 measured iterations after 10 warmups (30 iterations for the two largest rows):
Test Result
All 164 existing causal-convolution kernel tests passed. The 2,000-case randomized metadata comparison and targeted A100
causal_conv1d_fnintegration checks passed, and all production changed-file pre-commit checks passed.Duplicate-work check
Checked the open PR list for
causal_conv1d,causal conv, andoffsetliston 2026-09-05. No open PR was found that changescompute_causal_conv1d_metadataor its host-side offset construction. Related work is separate: #52611 addresses a JIT specialization race incausal_conv1d.py, the merged #52388 optimizes Kimi K3 state metadata, and the open #50226 adds SM103-specific GDN kernels; none changes this shared metadata helper.AI-assisted contribution
AI assistance was used for this change.