Repository navigation
[ROCm][MLA][Perf] Fuse decode QK-RoPE + Q-concat + KV-concat + KV-cache write for sparse MLA (backport #47757) - #19
Merged
Conversation
…he write for sparse MLA On ROCm, the sparse-MLA decode path runs the per-layer Q/KV preparation as several back-to-back ops: main RoPE on q_pe/k_pe, the query concat (ql_nope + RoPE'd q_pe), the KV concat, and the fp8 KV-cache write. Collapse them into the single AITER kernel fused_qk_rope_concat_and_cache_mla. Three decision sites, all keyed off ROCMAiterMLASparseImpl.use_fused_qk_rope_cache: 1. Wrapper (mla.py): when fusing, skip the in-place main RoPE and pass raw q_pe/k_pe down, threading `positions` as a real argument. 2. KV write (ROCMAiterMLASparseImpl.do_kv_cache_update): no-op when fusing. 3. Decode (MLAAttention.forward_impl): after the W_UK bmm, call the fused kernel to produce the pre-fused q and write the cache. The fusion is gated (ROCm, AITER, fp8 KV cache, not fp8_ds_mla) and falls back to the existing split-kernel path otherwise. Backport of upstream vllm-project/vllm PR vllm-project#47757 to moreh/v0.28.0, squashed from its six commits. Differences from upstream: the two `assert self.rotary_emb is not None` lines in vllm/models/deepseek_v32/attention.py are dropped (their surrounding code does not exist in v0.28.0; they only served mypy), and _get_fused_rope_cos_sin is placed before MLAAttention.forward because v0.28.0 has no prepare_kv_cache_update to anchor on. GLM-5.2 (GlmMoeDsaForCausalLM via deepseek_v2.py) uses MultiHeadLatentAttentionWrapper, so it takes this path. (cherry picked from commits 756fe16dce 3748e7775b 9b7165b13e bb42395d13 c2f9c18b57 55fbb491c8) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
hgquannn
added a commit
that referenced
this pull request
Sep 21, 2026
…se branch Brings the changes tested on the tmp/v0.28.0 image series into moreh/v0.28.0. Content is exactly that of the fork PRs #16 to #22 (all against this branch or its tmp copy): #16 [ROCm][Perf] Fuse DSA indexer QK preprocessing with AITER (upstream vllm-project#53094) #17 [ROCm][Perf] Shard DSA prefill indexer rows across TP ranks (upstream vllm-project#56944) #18 [ROCm] Skip redundant sparse index remap on non-indexer layers (backport of upstream vllm-project/vllm vllm-project#51309) #19 [ROCm][MLA][Perf] Fuse decode QK-RoPE + Q-concat + KV-concat + KV-cache write for sparse MLA (backport of upstream vllm-project#47757) #20 [ROCm][Perf] Dispatch DSA prefill indexer logits to aiter's HIP kernel on gfx950 #21 [ROCm][Perf] Use AITER tuned GEMM for the MoE router gate (backport of upstream vllm-project#50535) #22 [ROCm][Bugfix] Add `positions` to unified_mla_attention_with_output_fake Verified as image vllm-forks:0.28.0-pr16-21-a4-9-260917 (this branch minus #22) built with aiter moreh/v0.1.19 + PR #4 + PR #9 on MI355X. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Context
Backport of upstream vllm-project#47757 (open, base
main) tomoreh/v0.28.0, for the GLM-5.2 DSA test images built from this fork. Upstream's six commits (756fe16dce..55fbb491c8) squashed into one.On ROCm the sparse-MLA decode path runs RoPE on
q_pe/k_pe, the Q concat, the KV concat and the fp8 KV-cache write as separate ops. This collapses them into the single AITER kernelfused_qk_rope_concat_and_cache_mla(present in aiter v0.1.19, so no aiter change is needed). Gated on ROCm + AITER + fp8 KV cache (notfp8_ds_mla); falls back to the split path otherwise.Changes
vllm/_aiter_ops.py: registerrocm_aiter_fused_qk_rope_concat_and_cache_mlaandis_fused_mla_qkprep_enabled().vllm/v1/attention/backends/mla/rocm_aiter_mla_sparse.py:use_fused_qk_rope_cacheflag,do_kv_cache_updateno-op when fusing,fused_qk_rope_concat_and_cache().vllm/model_executor/layers/attention/mla_attention.py:rotary_embctor arg,positionsthreaded throughforward/forward_impl/unified_mla_attention_with_output, fused branch after theW_UKbmm,_get_fused_rope_cos_sin().vllm/model_executor/layers/mla.py: defer the main RoPE to the fused kernel and passpositions.vllm/models/deepseek_v32/amd/rocm.py: mypy assert.tests/kernels/core/test_fused_qk_rope_concat_and_cache_mla.py: upstream test, unchanged.Backport differences: the two mypy-only
assert self.rotary_emb is not Nonelines invllm/models/deepseek_v32/attention.pyare dropped (their surrounding code does not exist in v0.28.0);_get_fused_rope_cos_sinsits beforeMLAAttention.forwardbecause v0.28.0 has noprepare_kv_cache_updateto anchor on. GLM-5.2 (GlmMoeDsaForCausalLMindeepseek_v2.py) usesMultiHeadLatentAttentionWrapper, so it takes this path.Test plan
python3 -m py_compileon every touched file: pass.vllm-forks:0.28.0-pr4-9-v47757-51309-260916(vllmtmp/v0.28.0+ this + [ROCm][Perf] Skip redundant sparse index remap on non-indexer layers vllm-project/vllm#51309 backport; aitertmp/v0.1.19-pr4-9) for GLM-5.2-MXFP4 TP8 serving on MI355X. Serving results to follow in this thread.Assisted by Claude Code; the backport conflict resolution was reviewed by hand.