Repository navigation
[ROCm] Fuse Kimi-K3 DSpark QK RoPE with the MLA cache write - #60864
Draft
gronsti-amd wants to merge 17 commits into
Draft
gronsti-amd wants to merge 17 commits into
gronsti-amd wants to merge 17 commits into
Conversation
Keep the NVIDIA module as a re-export so the registry path is unchanged. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
NVIDIA keeps MultiHeadLatentAttention as the cache owner. A platform override can point context-KV insert and draft layer names at another module. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The defaults keep today's concat and cache write. A subclass can replace the decode query and the KV rows it writes without a new custom-op argument. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The common module is a new file, so pre-commit lints it in full. The (list, tuple) form was already on main and fails UP038 once the file moves. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The file was not listed in Buildkite, so the refactor would not be collected on either platform. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
DeepseekV32Attention already assigns a concrete RotaryEmbedding to that name. Typing the base attribute as optional made mypy reject its cache reads. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Replay reads the captured positions and slot-mapping allocations, so a replacement tensor freezes the pointer. Lock the NVIDIA binding class and the default hook returns. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
ROCm keeps the wrapper factory and points the KV cache at mla_attn. The copied decoder, context-KV insert, and weight mapper stay in the common module. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
HIP YaRN RoPE returns fp32. The query slice assignment casts q back to bf16, but k_pe stays fp32 and concat_and_cache_mla stores those bits as the KV dtype. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The fused decode launch applies a one-row identity table, so it is only valid when the wrapper has not already rotated. Document the duplicated YaRN setup and bind the construction test to the wrapper signature. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
KimiLinearConfig types the latent sizes as optional. Assert them the same way the NVIDIA K3 MLA constructor does, so the factory arithmetic typechecks. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The post-absorb hooks already split the decode epilogue from MLAAttention. Fill them from a DSpark subclass so the fp32 AITER kernel stays off the shared attention module. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
AITER MLA expects an FP8 decode query, and the prefill key must be rotated again on the tensor attention actually reads. Refuse fused RoPE when positions are missing or prefill context parallel would gather rows the local positions do not cover. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
ForwardContext stores AttentionMetadata, which has no num_decode_tokens. The layer entry is MLACommonMetadata, so cast it before reading the decode count. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
MLACommonMetadata is defined next to MLAAttention. The backends.mla.common module does not exist, so that import stopped the DSpark tests from collecting. The bare attention fixture sets pcp_shard_decode_requests, which update_kv_cache reads before the PCP gather. The prefill re-rotate test installs a forward context so the MHA hook can read the decode split. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Slicing k_pe builds a new view on each evaluation, so the test compared two equal tensors that were not the same object. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The AMD Basic Models job invoked test_dspark_mla.py without VLLM_ROCM_USE_AITER, so the cos/sin dtype test skipped. Run that test on its own with the flag set. Signed-off-by: Stig-Arne Grönroos <stig-arne.gronroos@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
6 tasks done
6 tasks
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
This branch has not been deployed
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.
Purpose
Apply AITER
fused_qk_rope_concat_and_cache_mlato the Kimi-K3 DSpark draft model.The kernel fuses the QK RoPE, the absorbed query, and the KV cache write into one launch.
This PR fills the hooks introduced in #60054.
The shared op schemas stay unchanged.
unified_mla_kv_cache_updateis on the compile path of every MLA model and is a splitting op. Positions stay on_rope_positions.What changes
KimiK3DSparkMLAWrapper. Aftersuper().__init__it stores the embedding as_epilogue_rotary_emb.positionsintoMLAAttention.forward.positions is NoneraisesRuntimeError. There is no fallback that writes unrotated KV.k_peis cloned, rotated for the cache, and the caller's tensor stays unrotated so attention can rotate it again in_prepare_mha_inputs.q_outis FP8 when the KV cache is quantized andsupports_quant_query_inputis set (ROCM_AITER_MLA). Triton MLA clears that flag and keeps bf16. The absorbed query is made contiguous before the launch.rotary_embis set, including inside_fused_qk_prep_supported.MLACommonMetadatais imported fromvllm.model_executor.layers.attention.mla_attention.Validation
do_kv_cache_update; prefillk_peis re-rotated for MHA and the caller's key stays unrotated until then;q_outmatches the backend query dtype; fusion requires positions.test_fused_qk_rope_concat_requires_fp32_cos_sinasserts the wrapper rejects a bf16 cos/sin table. The probe is false unlessVLLM_ROCM_USE_AITER=1andaiter.fused_qk_rope_concat_and_cache_mlaimports. The AMD Basic Models job runs that test in its own pytest process with the flagset, and filters it out of the broader command.
vllm bench serve/ spec-bench over output length × max concurrency, with{"method": "dspark", "model": "Inferact/Kimi-K3-DSpark", "num_speculative_tokens": 5, "attention_backend": "TRITON_MLA", "draft_sample_method": "probabilistic", "rejection_sample_method": "block"}Out of scope
DeepseekScalingRotaryEmbedding.forward_hipto AITER Triton RoPE. That would apply to every HIP user of the embedding. It can be a follow-up or alternative to this PR.Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.