Skip to content

Fix fused_qk_rope_concat_and_cache_mla for DCP - #4342

Merged
valarLip merged 9 commits into
ROCm:mainfrom
yitingw1:fix_for_dcp
Jul 29, 2026
Merged

valarLip merged 9 commits into
ROCm:mainfrom
yitingw1:fix_for_dcp

Conversation

@yitingw1

@yitingw1 yitingw1 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Both decode variants (..._per_head_kernel_impl, ..._kernel_opt) start with if (slot_idx < 0) return;, which also skips Q RoPE + q_out. Under DCP a non-owned token has slot_mapping = -1 but its query still needs RoPE (every rank attends all queries after the head all-gather) → q_out uninitialized → wrong accuracy. But making Q RoPE unconditional would regress non-DCP: cudagraph-padded tokens (slot = -1) would pointlessly compute Q RoPE + q_out instead of early-returning.

Fix

Add compute_all_q_rope as the last param (default false), threaded through impl → wrapper → CALL macros → host → pybind → Python stub:

  • false (default, non-DCP): if (!compute_all_q_rope && slot_idx < 0) return; — original early-return kept → no non-DCP regression; callers need no change (stub default + bound.apply_defaults()).
  • true (DCP): compute Q RoPE + q_out unconditionally; guard only KV-cache writes with slot_idx >= 0.
  • Add max_position + clamp(pos) (padded tokens may carry stale positions).
  • slot_idx >= 0 path byte-identical; only per_head + opt decode variants change (prefill untouched).

Test

  • DeepSeek-R1 TP8 gsm8k: DCP8 bf16 0.9492 / fp8 0.9553, non-DCP 0.9492 — no regression.

Submission Checklist

@yitingw1
yitingw1 requested review from a team and yzhou103 July 23, 2026 03:51
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4342 --add-label <label>

@yzhou103

Copy link
Copy Markdown
Contributor

LGTM

@yzhou103

Copy link
Copy Markdown
Contributor

General decode kernel not covered. fuse_qk_rope_concat_and_cache_mla_kernel_general_kernel still has a hard if (slot_idx < 0) return;. If compute_all_q_rope=true is passed but dispatch falls into this path (kv_lora_rank != 512 or pe_dim != 64), the flag is silently ignored. Suggest either threading the param through, or adding a host-side guard:
AITER_CHECK(!compute_all_q_rope || (kv_lora_rank == 512 && pe_dim == 64),
"compute_all_q_rope is only supported for standard DeepSeek MLA dimensions");

@yitingw1

Copy link
Copy Markdown
Contributor Author

General decode kernel not covered. fuse_qk_rope_concat_and_cache_mla_kernel_general_kernel still has a hard if (slot_idx < 0) return;. If compute_all_q_rope=true is passed but dispatch falls into this path (kv_lora_rank != 512 or pe_dim != 64), the flag is silently ignored. Suggest either threading the param through, or adding a host-side guard: AITER_CHECK(!compute_all_q_rope || (kv_lora_rank == 512 && pe_dim == 64), "compute_all_q_rope is only supported for standard DeepSeek MLA dimensions");

Done by adding a host-side guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants