Skip to content

Relax the paged sparse MQA page-stride guard from 512 to 256 bytes - #33

Merged
zyongye merged 1 commit into
devfrom
relax-paged-sparse-page-stride
Oct 12, 2026
Merged

zyongye merged 1 commit into
devfrom
relax-paged-sparse-page-stride

Conversation

@zyongye

@zyongye zyongye commented Oct 12, 2026

Copy link
Copy Markdown
Member

fp8_fp4_paged_sparse_mqa_logits requires 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 * 132 for MXFP8, page_kv * 68 for MXFP4. Both are page_kv * 4 * odd, so the packed stride is 256-aligned iff page_kv % 64 == 0 and 512-aligned iff page_kv % 128 == 0:

page_kv MXFP8 MXFP4 natural alignment
32 4224 2176 128 needs padding, before and after
64 8448 4352 256 rejected today, accepted after
128 16896 8704 512 accepted today
192 25344 13056 256 rejected today, accepted after

So a page_kv = 64 indexer cache — the page size test_sparse_mqa_logits itself 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 via bench_kineto, 6 repeats (spread within a run <= 0.3%).

Padded (512) vs packed (256):

fmt KV len padded packed delta
MXFP8 16384 72.1 us 71.9 us -0.3%
MXFP8 65536 91.5 us 91.2 us -0.3%
MXFP8 262144 93.8 us 93.4 us -0.4%
MXFP4 16384 43.1 us 42.9 us -0.5%
MXFP4 65536 58.0 us 57.7 us -0.5%
MXFP4 262144 59.9 us 60.0 us +0.2%

Nsight counters for the same pair (MXFP8, KV 65536) are unchanged, i.e. the coalescing pattern does not move:

l1tex__t_requests_pipe_lsu_mem_global_op_ld.sum    1,409,831 ->  1,409,831   +0.00%
l1tex__t_sectors_pipe_lsu_mem_global_op_ld.sum    22,392,251 -> 22,392,251   +0.00%
lts__t_sectors_srcunit_tex_op_read.sum            24,569,647 -> 24,470,064   -0.41%
dram__bytes_read.sum                             443,415,040 -> 443,610,368   +0.04%

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_logits passes 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:

stride alignment MXFP8 delta MXFP4 delta
512 89.9 us — 57.4 us —
256 90.4 us +0.6% 58.0 us +1.0%
128 93.2 us +3.7% 59.8 us +4.2%
64 96.1 us +6.9% 62.3 us +8.5%
32 98.3 us +9.3% 63.7 us +11.0%
16 105.2 us +17.0% 67.8 us +18.1%

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 = 32 still has to pad, as it does today.

🤖 Generated with Claude Code

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
zyongye merged commit 00918bc into dev Oct 12, 2026
3 of 4 checks passed
@zyongye
zyongye deleted the relax-paged-sparse-page-stride branch October 12, 2026 21:10
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]>
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.

1 participant