mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[GH-ISSUE #322] get_paged_mqa_logits_metadata() does not work with large batch size due to excessive static shared memory impl #160
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#160
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?
Originally created by @gau-nernst on GitHub (Apr 29, 2026).
Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/322
This is caused by static shared memory being linear with batch size
github.com/deepseek-ai/DeepGEMM@891d57b4db/deep_gemm/include/deep_gemm/scheduler/paged_mqa_logits.cuh (L19-L20)Would it possible to make it support large batch size instead? Either with dynamic shared memory or reimplement in a way that doesn't need that much shared memory.
The context is that I'm trying to use
fp8_fp4_paged_mqa_logits()for prefill case, which requires calling this metadata preparation kernel. Thank you.@toffee-desuwa commented on GitHub (May 30, 2026):
@LyricZhao — I looked into #322 and I think I found the cause. Wanted to ask your preferred direction before anyone writes a fix.
The cause: In paged_mqa_logits.cuh, the kernel smxx_paged_mqa_logits_metadata declares three static shared arrays, each sized by kAlignedBatchSize:
varlen_atom_token_start[kAlignedBatchSize] (line 19)
varlen_atom_context_len[kAlignedBatchSize] (line 20)
prefix_sum[kAlignedBatchSize] (line 57)
That is about 3 * 4 * kAlignedBatchSize bytes of static shared memory. When the batch size is large (roughly 4096+), this goes over the 48 KB static smem limit, so the kernel cannot launch. The host side in attention.hpp does not catch this: there is no batch-size check before launch, and the only smem accounting is for dynamic shared memory, which this kernel does not use. So it cannot detect a static smem overflow. This matches @gau-nernst's report: fine at small batch, breaks at large batch.
Three possible fixes (not sure which you prefer):
Option 1 — Move the three arrays to dynamic shared memory (extern shared), and pass the size through the launch config and the host check, so the existing accounting covers them.
Option 2 — Process the batch in fixed-size chunks, so static smem stays bounded no matter how large the batch is.
Option 3 — Keep it static but add a host-side DG_HOST_ASSERT on the batch-size limit. This is the smallest change: it turns a silent launch failure into a clear error, but it caps the supported batch instead of fixing it.
I'm happy to open a PR for whichever direction fits the codebase best. I just didn't want to decide the design myself on a core kernel. Thanks!