[ROCm][Performance] Eliminate per-decode allocations and output copy … - #50566
chuanbowang2026 wants to merge 1 commit into
Conversation
…in sparse MLA decode Reduce decode latency for DeepSeek V4 sparse MLA attention on ROCm by removing redundant memory allocations and a device-to-device copy that occurred on every decode forward pass. Changes: 1. Thread the caller's output buffer through the decode call chain (rocm_sparse_attn_decode → _rocm_sparse_attn_decode_triton → _rocm_sparse_attn_decode_ragged_triton) so the Triton kernel writes directly into the final destination, eliminating one torch.empty_like allocation and one .copy_() per decode step. 2. Pre-allocate split-K partition buffers (part_m, part_l, part_acc) at maximum size on first use and slice into them per decode call, avoiding three torch.empty allocations per decode step on gfx942/gfx950. Both optimizations are backward-compatible: all new parameters are optional with None defaults, so existing callers and tests continue to work unchanged. Signed-off-by: wangchuanbo <wangchuanbo@xcoresigma.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. 🚀 |
|
Coordination note: I opened draft #52212 for the default Triton DSV4 sparse-decode long-context work (split ceiling 16→32, constexpr cache geometry, UE8M0 exponent-bit decoding, and an 8,192-row correctness case). It includes direct-output reuse as part of the integrated tested kernel and explicitly credits this PR for the overlapping idea. If #50566 lands first, I will reconcile that hunk before marking #52212 ready. One integration detail: #50566 currently sizes reusable split-K buffers with |
|
This pull request has merge conflicts that must be resolved before it can be |
Summary
Reduce decode latency for DeepSeek V4 sparse MLA attention on ROCm by removing redundant memory allocations and a device-to-device copy on every decode forward pass.
Changes
1. Eliminate output tensor allocation + copy (
vllm/v1/attention/ops/rocm_aiter_mla_sparse.py)Previously,
rocm_sparse_attn_decode()allocated a fresh bf16 output tensor inside_rocm_sparse_attn_decode_ragged_triton, then copied it back to the caller'soutputbuffer via
output.copy_(attn_out.to(output.dtype)). Since both tensors are bf16 with identical shape and the Triton kernel uses explicit stride parameters, the caller'soutput buffer is now passed directly to the kernel, removing one
torch.empty_like+ one.copy_()per decode step.2. Pre-allocate split-K partition buffers (
vllm/models/deepseek_v4/amd/rocm.py+vllm/v1/attention/ops/rocm_aiter_mla_sparse.py)On gfx942/gfx950, the split-K decode path allocates three scratch tensors (
part_m,part_l,part_acc) on every forward call. These are now lazily allocated once atmaximum size (
[max_num_batched_tokens, 16, n_local_heads, ...]) and sliced per-call, eliminating 3×torch.emptyper decode step.Backward Compatibility
All new parameters (
out,split_k_buffers) areOptionalwithNonedefaults. WhenNone, the functions allocate internally as before. Existing tests and callers areunaffected.
Testing
test_sparse_attn_decode_ragged_kernel,test_sparse_attn_decode_split_k_kernel) pass unchanged (new parameters are optional)Expected Impact
torch.emptyallocations per decode forward (1 output + 3 split-K).copy_()per decode forward