Skip to content

[Perf] [AMD] dsv41: Skip unneeded layer 20 computation under decoder-bounded-replay - #45339

Merged
HaiShaw merged 7 commits into
sgl-project:mainfrom
1am9trash:v41-skip-layer20
Oct 20, 2026
Merged

HaiShaw merged 7 commits into
sgl-project:mainfrom
1am9trash:v41-skip-layer20

Conversation

@1am9trash

@1am9trash 1am9trash commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

With --enable-decoder-swa-bounded-replay, DeepSeek-V4.1's decoder layers only process the last 128 prompt tokens of each request during prefill. Layer 20 (the first decoder layer) still has to write the KV cache for every token, but it does not need to run the indexer, attention, and MoE on all of them. Currently, The amd code path still runs all of layer 20 on every token.

Nv enabled the skip in #42901. Amd was left out because its fused layer path runs the whole layer 20 in one call, so the KV write could not be split from the rest of the layer.

This PR enables it on amd. Layer 20 writes the KV cache for every token first, then runs the rest of the layer on the last 128 tokens only.

Modifications

No change on nv. All changes are in deepseek_v4_backend_hip_radix.py or under _is_hip.

  • deepseek_v4.py
    • Set tail_writes_source_kv to True on amd, so the tail starts at layer 20 instead of layer 21.
    • Get layer 20's input for the KV write from fused_boundary_attn_input.
  • deepseek_v4_platform_stage.py
    • The fused boundary delays each layer's mHC post to the start of the next layer, so it has not run yet when layer 20 starts.
    • Add fused_boundary_attn_input, which runs that pending mHC post and builds layer 20's attention input for every token.
  • deepseek_v4_backend_hip_radix.py
    • Reuse DeepseekV4AttnBackend.write_tail_source_kv to write layer 20's KV cache for every token.
    • Layer 20 now runs its indexer on the last 128 tokens only, and writes data straight into the tail buffers.
    • Remove the code that copied these results out of the full-token buffers, since it is no longer needed.

Accuracy Tests

Server cmd:

SGLANG_USE_AITER=1 SGLANG_OPT_HIP_OPUS_SPARSE_PREFILL=true SGLANG_OPT_HIP_FLYDSL_MXFP8=1 \
SGLANG_HIP_FP4_INDEXER_ROWGROUP=1 SGLANG_HIP_DSV41_INDEX_K_PAGE8=1 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
ROCM_QUICK_REDUCE_QUANTIZATION=INT8 \
python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V4.1-Flash --trust-remote-code \
  --tp 2 --enforce-shared-experts-fusion --fp8-gemm-backend aiter --cuda-graph-max-bs-decode 64 \
  --enable-decoder-swa-bounded-replay --cuda-graph-backend-prefill disabled \
  --mem-fraction-static 0.8 --chunked-prefill-size 16384 --prefill-decode-interval 32 \
  --swa-prefix-tails 2048 --max-running-requests 64
# DSpark rows add: --speculative-algorithm DSPARK --speculative-dspark-block-size 5
# The radix-cache-off row adds: --disable-radix-cache
python3 -m sglang.test.few_shot_gsm8k --num-questions 1319 --parallel 32
GSM8K, 1319 questions main this PR
No speculative decoding 0.905 / 0.900 0.906 / 0.900
DSpark, block size 5 0.902 / 0.898 0.917 / 0.901
No speculative decoding, radix cache off 0.903 / 0.906 0.904 / 0.898

Speed Tests and Profiling

Follow SA MI355 tp2 setting:

  • DSpark block size: 5
  • Simulated accept length: 3.51.

Time spent in layer 20 for one 16K-token prefill chunk:

Prefill chunk main this PR
First chunk of the prompt 13.4 ms 3.0 ms
Last full chunk of a 200K-token prompt 34.4 ms 3.0 ms

TTFT:

Request main this PR Change
New prompt, 590 tokens 83.8 ms 82.1 ms 2.1% faster
New prompt, 6,318 tokens 152.9 ms 146.8 ms 4.0% faster
New prompt, 14,795 tokens 259.0 ms 248.0 ms 4.3% faster
New prompt, 64K tokens 1163.0 ms 1103.9 ms 5.1% faster
New prompt, 200K tokens 3811.1 ms 3540.3 ms 7.1% faster
2K new tokens after 16K cached tokens 83.9 ms 83.3 ms No change
2K new tokens after 64K cached tokens 90.7 ms 90.3 ms No change
2K new tokens after 200K cached tokens 115.3 ms 115.5 ms No change
128 new tokens after 200K cached tokens 117.1 ms 116.8 ms No change

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #39402793949
Latest PR Test (Extra): ❌ Run #39402793760
Latest PR Test (AMD ROCm 10): ⏳ Run #39402793786

@1am9trash
1am9trash marked this pull request as draft October 20, 2026 06:40
@1am9trash 1am9trash added the amd label Oct 20, 2026
@1am9trash
1am9trash marked this pull request as ready for review October 20, 2026 08:07
@1am9trash 1am9trash added the run-ci CI: run the baseline test suite on this PR label Oct 20, 2026

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

HIP specific changes.

@HaiShaw
HaiShaw merged commit 82ac83a into sgl-project:main Oct 20, 2026
152 of 168 checks passed
At1a8 added a commit to At1a8/sglang that referenced this pull request Oct 20, 2026
Resolve the conflicts with sgl-project#45339 in deepseek_v4_backend_hip_radix.py: keep
main's tail entry (the source layer runs inside the tail after
write_tail_source_kv) and add the CP metadata / DP buffer switch on top of it.
The HIP CP low-ratio sources take q_lora rows only for the indexer, since
write_tail_source_kv runs the compressor alone with q_lora=None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd deepseek run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants