Repository navigation
Relax the paged sparse MQA page-stride guard from 512 to 256 bytes - #33
Merged
Merged
Conversation
A fused sparse KV cache packs to `page_kv * (head_dim / pack + 4)` bytes per page, that is `page_kv * 132` for MXFP8 and `page_kv * 68` for MXFP4. Both are `page_kv * 4 * odd`, so the packed stride is 512-aligned only when `page_kv` is a multiple of 128. A `page_kv = 64` cache packs to 8448 or 4352 bytes, exactly 256-aligned, and is rejected today; callers then pad every page by 256 bytes, costing 3.0% (MXFP8) or 5.9% (MXFP4) of the indexer cache. The kernel needs 16 bytes -- KV rows and SF rows are both read with 16-byte `cp.async.cg`, and inside a page the sparse KV blocks already sit at least 512 bytes apart. The stride only sets the alignment phase of those blocks across pages, and 256 bytes keeps it: each half-warp of the KV copy loop covers one 256-byte window, which stays whole as long as pages are 256-aligned. On GB300, packed pages match padded ones within 0.5% of kernel time, with identical global-load requests and sectors and DRAM bytes within 0.1%, and the logits are bitwise unchanged. Going lower is not free -- a 128-aligned stride costs 3.7% (MXFP8) and 4.2% (MXFP4) -- so the guard stays, one step lower. Signed-off-by: Yongye Zhu <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
zyongye
added a commit
to zyongye/vllm
that referenced
this pull request
Oct 13, 2026
…parse indexer Pin vllm-project/DeepGEMM dev 6ce1c5e: the upstream 26/09/30 release (vllm-project/DeepGEMM#30), the vendoring import fixes vllm-project/DeepGEMM#31 and vllm-project/DeepGEMM#32, and the paged sparse MQA page-stride relaxation vllm-project/DeepGEMM#33. Vendor the new deep_gemm/locality_domain.py. DeepGEMM#32 makes the MLOPart bridge and the epilogue module use the package's own name, so they also work when vendored as vllm.third_party.deep_gemm. DeepGEMM#33 lowers the page-stride guard from 512 to 256 bytes; the DeepSeek-V4.1 sparse-logits block stride stays 512-aligned, which still satisfies it. The MQA logits API changed: clean_logits/logits_dtype are gone, max_seqlen_k is required, prefill logits are compressed to each row's K span, and SM100 takes only MXFP8/MXFP4 with BF16 weights and returns BF16 logits. On SM100 the FP8 indexer K writers store their existing power-of-two scale as four packed UE8M0 bytes (a lossless MXFP8 encoding), FP8 Q passes unit MX scales with its scale still folded into the weights, and BF16 logits are upcast row-aware for the FP32 top-k kernels. check_wheel_deepgemm.py now imports the vendored package. build_deepgemm_C.py passes --force to setup.py build_ext: DeepGEMM's setup.py only tracks python_api.cpp, so an incremental build after a header-only pin change kept a stale extension. CMake already decides when this step reruns. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Yongye Zhu <[email protected]>
6 tasks done
6 tasks done
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.
fp8_fp4_paged_sparse_mqa_logitsrequires the fused KV cache's page stride to be a multiple of 512 bytes. This relaxes it to 256, in the host guard, the matching device assert, and the test's page padding so the test exercises a packed cache.Why
A fused page packs to
page_kv * (head_dim / pack + 4)bytes:page_kv * 132for MXFP8,page_kv * 68for MXFP4. Both arepage_kv * 4 * odd, so the packed stride is 256-aligned iffpage_kv % 64 == 0and 512-aligned iffpage_kv % 128 == 0:page_kvSo a
page_kv = 64indexer cache — the page sizetest_sparse_mqa_logitsitself uses — cannot be passed packed. Callers pad every page by 256 bytes, costing 3.0% (MXFP8) or 5.9% (MXFP4) of the cache.Why 256 is enough
The correctness floor is 16 bytes: KV rows and SF rows are both read with 16-byte
cp.async.cg, and within a page the sparse KV blocks already sit at least 512 bytes apart (token_idx_in_page * kHeadDim / pack). The stride only sets the alignment phase of those blocks across pages. In the KV copy loop each half-warp covers exactly one 256-byte window (16 lanes x 16 B), so a 256-aligned page keeps every window whole.Measurements
GB300 (SM103), idle GPU, 512 query tokens, top-2048 blocks of 8,
page_kv = 64, arms interleaved, kernel time viabench_kineto, 6 repeats (spread within a run <= 0.3%).Padded (512) vs packed (256):
Nsight counters for the same pair (MXFP8, KV 65536) are unchanged, i.e. the coalescing pattern does not move:
Correctness: logits are bitwise identical to the padded layout (~4M values per case; MXFP8 and MXFP4; KV 16384 and 65536), including with the cache base pointer shifted by 256 bytes.
test_sparse_mqa_logitspasses over all 49 paged cases x 4 head counts with the packed padding.Why not lower than 256
Same kernel and
page_kv = 64, only the stride phase varies. Every arm is bitwise correct — 16 bytes really is the floor for correctness — but the cost is real:Below 256 a 1024-byte MXFP8 block starts straddling a ninth 128-byte L2 line, whose other half belongs to a neighbouring block that a sparse kernel usually did not select; below 64 the half-warp span also splits into more L2 requests. 256 is the last step that costs nothing, so the guard stays — one notch lower, not removed.
page_kv = 32still has to pad, as it does today.🤖 Generated with Claude Code