Skip to content

[AMD] Reuse KV gather indices across ASM context prefill layers - #39901

Merged
HaiShaw merged 5 commits into
sgl-project:mainfrom
zijiecode:pr/qwen35-asm-prefill-gather
Sep 22, 2026
Merged

HaiShaw merged 5 commits into
sgl-project:mainfrom
zijiecode:pr/qwen35-asm-prefill-gather

Conversation

@zijiecode

@zijiecode zijiecode commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The gfx950 ASM context-prefill path gathers paged K/V into contiguous buffers. It rebuilds the same gather indices at every full-attention layer, including four GPU synchronizations per call. In a TP2 trace, this takes about 35 ms of a 490 ms prefill chunk with 16k new tokens and 15 full-attention layers. This PR computes the indices once per batch and reuses them across layers.

Modifications

  • Reuse the token indices and cumulative lengths already available in prefill metadata for ordinary extend batches.
  • Cache the indices in ForwardMetadata. Speculative batches and unsupported metadata use the existing helper and bounds checks.
  • Add SGLANG_GFX_ASM_CTX_GATHER_CHECK=1 to compare the reused indices with the original helper during validation.

Each layer still gathers its own K/V data. The attention kernel is unchanged.

Accuracy Tests

amd/Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, TP2/C8, 5-shot GSM8K, chat-completions, 16384-token output budget, temperature 0, real MTP.

Configuration Strict-match Flexible-extract
Baseline 97.88% 97.80%
This PR, chunked prefill 512 so that gsm8k prompts get chunked 97.65% 97.65%

Benchmarking and Profiling

amd/Qwen3.5-397B-A17B-MXFP4, MI355X, TP2/C32, HiCache, and MTP. Two 1200-second AgentX runs per configuration on the same GPU pair; the table shows arithmetic means of the per-run metrics.

Metric Baseline average This PR average Change
Standard p90 interactivity (tok/s/user) 39.24 40.26 +2.60%
Throughput (tok/s/GPU) 547.10 547.50 +0.07%
TPOT mean (ms/token) 16.260 15.855 -2.49%
TPOT p50 (ms/token) 12.065 11.870 -1.62%
TPOT p90 (ms/token) 25.490 24.840 -2.55%

Checklist

  • Format your code according to the Format code with pre-commit guide.
  • Add unit tests.
  • Update documentation.
  • Provide accuracy and speed benchmark results.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ⏳ Run #35750753383
Latest PR Test (Extra): ❌ Run #35750753270
Latest PR Test (AMD ROCm 10): ⏳ Run #35750753475

@yichiche yichiche added the run-ci CI: run the baseline test suite on this PR label Sep 17, 2026

@yichiche yichiche 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.

Only affect AMD path. LGTM.

Comment thread python/sglang/srt/layers/attention/aiter_backend.py
Comment thread python/sglang/srt/layers/attention/aiter_backend.py Outdated
Comment thread python/sglang/srt/layers/attention/aiter_backend.py Outdated
@HaiShaw
HaiShaw merged commit 720617b into sgl-project:main Sep 22, 2026
138 of 168 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants