Repository navigation
Enabled stride-aware KV-cache block dim for non-contiguous layouts for fused_qk_norm_rope_cache_pts_quant_shuffle() - #3492
Merged
Merged
Conversation
…rough the pts quant dispatch path.
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
valarLip
approved these changes
Jun 4, 2026
2 of 3 tasks
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)
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.
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 asblock_idx * page_size * num_heads * head_dim, which assumes the cache is contiguous in the block dimension. This PR derives the per-block stride fromk_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. Afterunbind(1)orunbind(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
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.
within-block contiguity check (
is_contiguous_from_dim1) for non-contiguous caches.TODO.Test
python op_tests/test_fused_qk_norm_rope_cache_quant.py