Skip to content

[ROCm][Bugfix] Kimi-K3 Fix KDA NaN on mixed batches and racy autotune config - #50649

Merged
tjtanaa merged 6 commits into
vllm-project:mainfrom
EmbeddedLLM:kimi-k3-rocm-fixes
Aug 5, 2026
Merged

tjtanaa merged 6 commits into
vllm-project:mainfrom
EmbeddedLLM:kimi-k3-rocm-fixes

Conversation

@kliuae

@kliuae kliuae commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Purpose

For Kimi-K3, there are two correctness bugs on the ROCm Kimi-K3 KDA path.

  • KimiGatedDeltaNetAttention._forward sends the decode sequences of a mixed decode+prefill non-speculative batch through the KDA chunk kernel chunk_kda_with_fused_gate. The chunk kernel treats each decode as length=1 sequence, and returns NaN for them. This PR separates the decode out of the mixed batch and pass them to fused_recurrent_kda.
  • recompute_w_u_fwd_kernel autotunes the configuration of num_stages=4. This configuration, particularly in combination with num_warps=4, is racy for this kernel, and can silently produce large (e.g. ~1e38) garbage values that corrupts the downstream. This PR addresses this by leaving the num_stages=4 out in autotuning so that it doesn't land on the erroneous configuration.

Test Plan

moonshotai/Kimi-K3 with gsm8k on MI355X

Server command

AITER_BF16_FP8_MOE_BOUND=0 \
VLLM_ROCM_USE_AITER=1 \
SAFETENSORS_FAST_GPU=1 \
AITER_SITUV2_A8W4=1 \
VLLM_USE_BREAKABLE_CUDAGRAPH=0 \
vllm serve moonshotai/Kimi-K3 \
  --trust-remote-code \
  --moe-backend auto \
  --tensor-parallel-size 8 \
  --load-format auto \
  --gpu-memory-utilization 0.95 \
  --mm-encoder-tp-mode data \
  --max-num-seqs 128 \
  --max-num-batched-tokens 4096 \
  --enable-auto-tool-choice \
  --tool-call-parser kimi_k3 \
  --reasoning-parser kimi_k3

lm_eval

lm_eval --model local-completions --model_args model=moonshotai/Kimi-K3,base_url=http://0.0.0.0:8000/v1/completions,tokenizer_backend=None,tokenized_requests=False,num_concurrent=128,max_retries=10,max_gen_toks=2048,timeout=60000 --batch_size auto --tasks gsm8k --num_fewshot $FEWSHOTS

Test Result

Before, 5-shot

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

PR, 5-shot

Tasks Version Filter n-shot Metric Value Stderr
gsm8k 3 flexible-extract 5 exact_match 0.9689 ± 0.0048
strict-match 5 exact_match 0.9697 ± 0.0047

PR, 20-shot

Tasks Version Filter n-shot Metric Value Stderr
gsm8k 3 flexible-extract 20 exact_match 0.9697 ± 0.0047
strict-match 20 exact_match 0.9704 ± 0.0047

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.

root and others added 3 commits July 31, 2026 20:55
Signed-off-by: kliuae <kuanfu.liu@embeddedllm.com>
Signed-off-by: kliuae <kuanfu.liu@embeddedllm.com>
Signed-off-by: kliuae <kuanfu.liu@embeddedllm.com>

@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 kimi k3 rocm Related to AMD ROCm bug Something isn't working labels Aug 1, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Aug 1, 2026
@ZJY0516

ZJY0516 commented Aug 3, 2026

Copy link
Copy Markdown
Member

@kliuae Could you copy vllm/model_executor/layers/mamba/gdn/kimi_gdn_linear_attn.py into kimi_k3/amd/ and then modify? like #50364

kliuae added 2 commits August 3, 2026 05:00
Signed-off-by: kliuae <kuanfu.liu@embeddedllm.com>
Signed-off-by: kliuae <kuanfu.liu@embeddedllm.com>
@tjtanaa tjtanaa added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 4, 2026
@kliuae

kliuae commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@kliuae Could you copy vllm/model_executor/layers/mamba/gdn/kimi_gdn_linear_attn.py into kimi_k3/amd/ and then modify? like #50364

Sure, copied the kimi-k3 dedicated kda to kimi_k3/amd/kda.py and applied the fix there.

@tjtanaa tjtanaa left a comment

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.

LGTM

@tjtanaa
tjtanaa enabled auto-merge (squash) August 4, 2026 04:45

@ZJY0516 ZJY0516 left a comment

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.

LGTM now

@tjtanaa
tjtanaa merged commit f5cd862 into vllm-project:main Aug 5, 2026
61 of 62 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Aug 5, 2026
djdisodo pushed a commit to djdisodo/vllm that referenced this pull request Aug 16, 2026
The FLA W/U recompute kernel pipelines loads through its u loop, then reuses LDS for the following w loop. For Qwen3.6 GDN, V/BV is 2. With num_stages=4, Triton can issue a third consumer-less async copy that races the w loop and returns non-deterministic O(1e38) values.

Upstream commit f5cd862 (vllm-project#50649) diagnosed the same loop structure in the ROCm Kimi KDA copy on gfx950, but that fix did not cover this shared FLA implementation used by Qwen. On our gfx906 TP=2 run, autotuning selected stages=2 on rank 0 and the unsafe stages=4 on rank 1 because their timings differed by less than one percent.

Exclude stages=4 from this kernel on ROCm while preserving the existing CUDA search space. Stages 2 and 3 remain available, and their observed timings were within one percent of stage 4. This is a correctness restriction tied to the kernel pipeline shape, not a gfx906-only performance tuning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working k3 kimi ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants