Repository navigation
[SM90] Support paged MQA next_n=4 and block_kv=32 - #7
Merged
Merged
Conversation
Extend the SM90 FP8 paged MQA logits kernel and host wrapper to cover block_kv=32 and next_n=4 on post-deepseek-ai#304 code. Kernel (deep_gemm/include/deep_gemm/impls/sm90_fp8_paged_mqa_logits.cuh): - Keep MMA tile at kComputeBlockKV=64 and let block_kv vary (32 or 64). Each WGMMA iteration covers kNumBlocksPerMMA = 64 / block_kv physical blocks with one TMA copy each. - Load block_table entries with a loop of scalar __ldg's so block_table_stride no longer has to be a multiple of kNumBlocksPerMMA. - Add kNumKVMulticast template parameter for next_n=4; compute kNextNPerCTA = kNextN / kNumKVMulticast and split Q rows across two CTAs in a cluster via cta_rank_in_cluster, keeping smem and register budgets within SM90 limits (WGMMA N=256 otherwise exceeds kNumMathRegisters=104). - Use cute::cluster_id_in_grid().x for the scheduler index. Host wrapper (csrc/jit_kernels/impls/smxx_fp8_fp4_paged_mqa_logits.hpp): - Select num_kv_multicast = 2 when SM90+next_n=4 else 1. Build Q/weights TMA descriptors with next_n_per_cta * num_heads box, size smem from next_n_per_cta, launch with cluster_dim=num_kv_multicast. - Emit the extra kNumKVMulticast template arg only for SM90; SM100 instantiation is unchanged. Other: - Add utils::shfl_sync helper in common/utils.cuh. - tests/test_attention.py: extend enumerate_paged_mqa_logits to cover block_kv=32 and next_n=4 on SM90; call get_paged_mqa_logits_metadata with num_clusters = num_sms / num_kv_multicast; initialize block_table with torch.zeros so unused slots hold a valid block id. (cherry picked from commit 12cb7c0) Signed-off-by: Yongye Zhu <[email protected]>
zyongye
force-pushed
the
codex/port-indexer-next-n-4
branch
from
September 14, 2026 20:46
f14a358 to
001ed5f
Compare
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.
Summary
12cb7c0fromnv_dev.next_n=4with two-CTA clusters while keeping the per-CTA WGMMA/register footprint atnext_n=2.Validation
MAX_JOBS=4 DG_USE_LOCAL_VERSION=0 python setup.py buildnext_n=4, block_kv=32and the existingnext_n=1, block_kv=64specializationPYTHONPATH=../build/lib.linux-aarch64-cpython-312 DG_MQA_NUM_CASES=1 python -c 'from test_attention import test_paged_mqa_logits; test_paged_mqa_logits()'(GB200/SM100 regression smoke test)SM90 runtime validation was not available on this host; the available GPUs are GB200 (SM100).
Upstream source: deepseek-ai@12cb7c0