mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[PR #311] [CLOSED] fix: correct fused KV cache stride in paged MQA logits #358
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#358
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/311
Author: @JasonOA888
Created: 4/19/2026
Status: ❌ Closed
Base:
main← Head:fix/paged-mqa-kv-cache-stride📝 Commits (1)
510c226fix: correct fused KV cache stride in paged MQA logits📊 Changes
2 files changed (+18 additions, -14 deletions)
View changed files
📝
csrc/apis/attention.hpp(+6 -6)📝
tests/test_attention.py(+12 -8)📄 Description
Bug
fp8_fp4_paged_mqa_logitsdecomposes the fused KV cache into separatekv_cacheandkv_cache_sftensors viatorch::from_blob. The strides passed tofrom_blobassume a flat layout (all values then all SF), but the API assertion enforces an interleaved layout ([values | SF]per row):What was wrong
kv_cache stride(1):
head_dim/2(64), should befp4_with_sf_bytes(68)head_dim(128), should behead_dim_with_sf(132)kv_cache_sf offset:
block_kv * head_dim, pointing past all data rows into undefined territoryhead_dim(orhead_dim/2for FP4), pointing to the SF of the first rowkv_cache_sf stride(1):
1(contiguous), but SF values are interleaved everyfp4_with_sf_bytes/head_dim_with_sfbytesImpact
TMA descriptors constructed with wrong strides cause misaligned reads for any row > 0 in the paged KV cache. This silently corrupts attention logits for multi-row blocks.
The test helper had the same flat-layout assumption, masking the bug for small block sizes where corruption fell in the last 1-2 rows.
Fix
fp4_with_sf_bytes/head_dim_with_sf) for bothkv_cacheandkv_cache_sffrom_blobkv_cache_sfoffset tohead_dim/head_dim / 2(start of first row's SF)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.