Skip to content

Enabled stride-aware KV-cache block dim for non-contiguous layouts for fused_qk_norm_rope_cache_pts_quant_shuffle() - #3492

Merged
valarLip merged 4 commits into
mainfrom
jhu96/stride-aware
Jun 4, 2026
Merged

valarLip merged 4 commits into
mainfrom
jhu96/stride-aware

Conversation

@jhu960213

Copy link
Copy Markdown
Contributor

Motivation

The pts shuffle path (fused_qk_norm_rope_cache_pts_quant_shuffle → fused_rope_rms_set_kv
→ get_shuffle_layout_{k,v}_base) hardcoded the per-block KV-cache offset as block_idx * page_size * num_heads * head_dim, which assumes the cache is contiguous in the block dimension. This PR derives the per-block stride from k_cache.stride(0) / v_cache.stride(0) at runtime and uses it for the block base instead. Moving forward, this change will be able to support both [num_blocks, 2, block_size, num_kv_heads, head_dim] and [2, num_blocks, block_size, num_kv_heads, head_dim] conventions. After unbind(1) or unbind(0) the K/V views are either non-contiguous in the block dim (block stride 2×) or contiguous in the block dim, thus the hardcoded offset from the original contiguous logic would write into the wrong blocks.

Notes

  • Backward-compatible: for a contiguous cache stride(0) == num_heads*head_size*block_size,
    identical to the old formula. A default-0 sentinel leaves the shared mrope-3D launch path unchanged.
  • Guard: the host keeps the original full-contiguity fast path and only falls back to a
    within-block contiguity check (is_contiguous_from_dim1) for non-contiguous caches.
  • Scope: pts path only; the block-quant sibling kernel is left with a TODO.

Test

python op_tests/test_fused_qk_norm_rope_cache_quant.py

@jhu960213
jhu960213 requested a review from a team June 2, 2026 16:20
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 3492 --add-label <label>

@valarLip
valarLip merged commit 2b5b5af into main Jun 4, 2026
41 checks passed
@valarLip
valarLip deleted the jhu96/stride-aware branch June 4, 2026 15:22
sunway513 pushed a commit that referenced this pull request Jun 8, 2026
…or fused_qk_norm_rope_cache_pts_quant_shuffle() (#3492)

* Added stride-aware offsets to the block dimension for the KV cache through the pts quant dispatch path.

* Added unit test to verify block-first layout parity with original kv cache layout

* Apply black formatting to the stride-aware parity op-test

(cherry picked from commit 2b5b5af)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants