Repository navigation
[ROCm][Perf] Fuse indptr prefix sum into DSA decode pack kernel for DeepSeek-V4.1-Flash - #57860
nehaprakriya wants to merge 1 commit into
Conversation
…ndex build compute_global_topk_ragged_indices_and_indptr runs 38 times per decode step (once per sparse attention layer). Previously it called _build_indptr_from_lengths, which launched torch.zeros + torch.cumsum (a rocprim lookback scan) to prefix-sum 193 int32s -- ~305 us/step of pure kernel dispatch overhead. This change fuses the prefix sum into _pack_global_topk_ragged_kernel itself: each token program derives its own offset via a masked tl.sum over NTOK_PAD lanes in-register and writes its own indptr entry, eliminating both the zero- fill and the scan launch. The output buffer is now torch.empty (no pre-zeroing needed), 4.0 -> 2.0 graph nodes per call, 152 -> 76 kernel launches/step. CUDA never paid these launches: build_flashinfer_mixed_sparse_indices in common/ops/cache_utils.py does validity checking, invalid filtering and block-table->slot translation in a single kernel. End-to-end on MI355X, TP=4, C=32, agentic-coding benchmark (g25 iter_98): Before: 305.46 tok/s/chip After: 324.91 tok/s/chip (+6.4% cumulative; this change ~+0.2% isolated) Kernel launches/step: 152 -> 76 (-50%) Bitwise-identical output at 6 shapes including 768-row max batch and ragged/invalid rows; flat across 1->768-row sweep (dispatch-bound mechanism). Co-Authored-By: Claude <noreply@anthropic.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
This pull request has merge conflicts that must be resolved before it can be |
Purpose
Fuses the ragged indptr prefix sum into
_pack_global_topk_ragged_kernelfor the DSA decode index build on AMD gfx950 (MI355X), eliminating dispatch overhead that CUDA never incurs.compute_global_topk_ragged_indices_and_indptrruns 38× per decode step (once per sparse attention layer). On ROCm, the previous code called_build_indptr_from_lengthswhich launchedtorch.zeros+torch.cumsum(a rocprim lookback scan) to prefix-sum 193 int32s. Measured cost: ~305 µs/step of pure kernel dispatch. CUDA never pays this:build_flashinfer_mixed_sparse_indicesincommon/ops/cache_utils.pyemits its indptr inside the pack kernel's registers in a single launch.This change ports that approach to ROCm: each token program derives its own indptr offset via a masked
tl.sumoverNTOK_PADlanes in-register and stores its own entry before the early-return.topk_indptris nowtorch.empty(no pre-zeroing needed since every entry is written by the kernel). Theelse: topk_indptr.zero_()branch covers the degenerate empty case._build_indptr_from_lengthsis removed.Result: 4 → 2 graph nodes per call, 152 → 76 kernel launches/step (−50%), 1.69× on the cluster, bitwise-identical output.
This is not a duplicate of any open PR. PR #56638 ("Re-enable the fused combine_topk_swa_indices on gfx950") addresses a different function on the prefill path. AI assistance was used; every changed line has been reviewed and verified.
Test Plan
Test Results
Component (gfx950, measured on live import path via profiler):
Scaling: flat across 1→768-row sweep, confirming dispatch-bound mechanism. Output bitwise-identical at all 6 measured shapes.
End-to-end (MI355X, TP=4, C=32, agentic-coding, 600 s — this change in isolation):
Note: the throughput delta is within the measured noise band. The primary value of this change is the 50% launch reduction, which reduces CUDA-graph replay overhead and creates headroom for future kernel additions within the decode step budget.
supported_models.mdandexamplesfor a new model.