Skip to content

[ROCm][Perf] Fuse SWA q/kv RMSNorm and q FP8 group quant for DeepSeek-V4 - #53540

Merged
AndreasKaratzas merged 2 commits into
vllm-project:mainfrom
shen-shanshan:rocm-dsv4-csa-kernel-fuse
Aug 27, 2026
Merged

AndreasKaratzas merged 2 commits into
vllm-project:mainfrom
shen-shanshan:rocm-dsv4-csa-kernel-fuse

Conversation

@shen-shanshan

@shen-shanshan shen-shanshan commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Purpose

On the ROCm path of DeepSeek-V4, every decode step's SWA token-insertion pipeline runs:

  1. vLLM's Triton fused_q_kv_rmsnorm (norms the q-lora and kv latents to bf16).
  2. aiter per-1x128 dynamic quant of the bf16 q-lora (input quant of the block-scaled FP8 wq_b GEMM).
  3. the same quant a second time in the indexer's wq_b, which shares the q-lora with the attention layer.

This PR replaces 1+2 with a single aiter HIP kernel (fused_qk_rmsnorm_group_quant): it RMSNorms both latents (fp32 accumulate) and quantizes the q latent (per-1x128, fp32 scales) in one pass, so:

  • the hot path drops from 2 kernel launches to 1.
  • the bf16 q-lora write+read round-trip disappears; quantization now reads the fp32 accumulator directly (single rounding, equivalent-or-better precision).
  • the attention wq_b and the indexer wq_b both consume the pre-quantized (qr_fp8, qr_scale) pair and skip their own input quant (removes a third quant launch on the long-context path).
  • kv stays bf16 and feeds the existing fused insert kernel (fused_deepseek_v4_qnorm_rope_kv_rope_quant_insert) unchanged.

Note

The change is scoped to the ROCm/AITER path and does not change the CUDA or XPU implementations.


Before fusing (4µs 839ns + 4µs 719ns + 4µs 719ns = 14 µs 277 ns):

before-2

After fusing (4µs 919ns, 2.90x faster):

after

Test Plan

  • Benchmark with SA InferenceX 8k1k workload.
  • Accuracy test with gsm8k dataset.

Test Result

Note

The tests below are executed on AMD MI350X GPU, so the performance could be slightly lower than the MI355X baseline, so I verified this PR with an A/B test compared with vLLM main on the same machine.

Benchmark

Concurrency Version Output token throughput (tok/s) Change Mean TTFT (ms) Change Mean TPOT (ms) Change
1 Main 56.29 418.93 17.33
1 This PR 56.70 0.73% ↑ 462.05 10.29% ↑ 17.16 0.98% ↓
4 Main 181.61 514.31 20.95
4 This PR 182.49 0.48% ↑ 517.49 0.62% ↑ 20.84 0.53% ↓
16 Main 530.80 806.76 28.30
16 This PR 535.25 0.84% ↑ 808.93 0.27% ↑ 28.05 0.88% ↓
64 Main 1062.02 1780.55 57.27
64 This PR 1067.39 0.51% ↑ 1778.38 0.12% ↓ 56.98 0.51% ↓

Accuracy Test

Full GSM8K evaluation on this change (1,319 examples):

Tasks Version Filter n-shot Metric Value Stderr
gsm8k 3 flexible-extract 5 exact_match 0.9431 ± 0.0064
strict-match 5 exact_match 0.9431 ± 0.0064

Both results exceed the required 94% threshold.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added deepseek Related to DeepSeek models quantization DSv4 rocm Related to AMD ROCm labels Aug 24, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Aug 24, 2026
@tjtanaa

tjtanaa commented Aug 24, 2026

Copy link
Copy Markdown
Member

@shen-shanshan can you attach some perf figures ? Thank you.

@@ -945,3 +982,22 @@ def wq_b_and_q_quant():
else:
q, q_scale = q_quant, None
return q, q_scale, weights

def _wq_b_proj(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to be duplicated.

@shen-shanshan shen-shanshan Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to be duplicated.

There are two _wq_b_proj methods (wq_b in SWA and wq_b in indexer). We should skip the quant process in the both linear layers when using this fused kernel.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjtanaa I have also attached the profile traces before and after this PR, which could make it easier to understand. 😊

@shen-shanshan

Copy link
Copy Markdown
Collaborator Author

@shen-shanshan can you attach some perf figures ? Thank you.

Yeah, I have updated the benchmark results just now.

@mergify

mergify Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @shen-shanshan.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Aug 27, 2026
Signed-off-by: Shanshan Shen <87969357+shen-shanshan@users.noreply.github.com>
@shen-shanshan
shen-shanshan force-pushed the rocm-dsv4-csa-kernel-fuse branch from 479de2f to ec9d705 Compare August 27, 2026 06:19
@shen-shanshan

Copy link
Copy Markdown
Collaborator Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85760 for commit ec9d70553685.

Signed-off-by: Shanshan Shen <87969357+shen-shanshan@users.noreply.github.com>
@shen-shanshan

Copy link
Copy Markdown
Collaborator Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85791 for commit 0aad5d851c40.

@mergify mergify Bot removed the needs-rebase label Aug 27, 2026
@AndreasKaratzas
AndreasKaratzas merged commit 32ad140 into vllm-project:main Aug 27, 2026
87 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Aug 27, 2026
afriedri added a commit to afriedri/vllm that referenced this pull request Aug 27, 2026
Rebased onto main after vllm-project#53540 landed the
fused_mla_dual_rms_norm_group_quant custom op. The op registration this
PR previously carried is dropped; only the accessor the pattern matcher
needs is added here.

Adds MLADualRMSGroupQuantPattern, the group-quant sibling of the
existing MLADualRMSPerTokenQuantPattern, so the MLA FP8 path picks up
the fused AITER kernel through the compile pass rather than a hand-wired
call site -- covering DeepSeek-R1 / MLA, which vllm-project#53540 does not touch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Andy Friedrich <afriedri@amd.com>
am-cohere pushed a commit to am-cohere/vllm that referenced this pull request Sep 1, 2026
…-V4 (vllm-project#53540)

Signed-off-by: Shanshan Shen <87969357+shen-shanshan@users.noreply.github.com>
mikeshawcode pushed a commit to mikeshawcode/vllm that referenced this pull request Sep 1, 2026
…-V4 (vllm-project#53540)

Signed-off-by: Shanshan Shen <87969357+shen-shanshan@users.noreply.github.com>
Signed-off-by: mikeshawcode <michaelwshaw2@gmail.com>
mylibrar pushed a commit to tanyuqian/vllm that referenced this pull request Sep 3, 2026
…-V4 (vllm-project#53540)

Signed-off-by: Shanshan Shen <87969357+shen-shanshan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek Related to DeepSeek models DSv4 quantization rocm Related to AMD ROCm

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants