Repository navigation
Conversation
The deterministic (unified) extend-attention kernel launched every head_dim <= 128 with a 64-row query tile and 4 warps on gfx950. Each workgroup streams the whole prefix, so with long prompts a 256-row tile with 8 warps cuts the KV bytes read per query row 4x. The KV block size (BLOCK_N), and so the reduction order, is unchanged: outputs are bitwise identical, which a new kernel test checks on gfx950.
aarnetalman
marked this pull request as ready for review
October 20, 2026 11:14
aarnetalman
requested review from
BBuf,
DarkSharpness,
HaiShaw,
HydraQYH,
celve and
yuan-luo
as code owners
October 20, 2026 11:14
HaiShaw
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Deterministic inference (
--enable-deterministic-inference) runs prefill with the unified extend-attention kernel (extend_attention_fwd_unified), whose reduction order does not depend on the batch. On gfx950 it launches every head_dim <= 128 with a 64-row query tile and 4 warps. Each workgroup streams the whole prefix for its query rows, so with long prompts the kernel is bound by KV reads: at 64k-token inputs it takes 82% of deterministic mode's GPU time (Qwen3-8B on MI350X), and deterministic throughput falls to about 0.2x of normal mode.A 256-row tile with 8 warps reads each KV block once for 4x as many query rows. The KV block size (
BLOCK_N), and so the order in which each row's softmax and sums are accumulated, is unchanged, so the output is bitwise identical to today's.Modifications
extend_attention.py(extend_attention_fwd_unified): on gfx950, for head_dim <= 128 with the defaultBLOCK_Nof 64, launch withBLOCK_M = 256and 8 warps. Other GPUs, head dims, the shared block-size table and the non-deterministic extend kernels are unchanged.test_triton_attention_kernels.py: on gfx950, the unified kernel's output with the new tile equals the default tile's output bit for bit (head_dim 128 and 64, three sequences with 0-4k prefixes).A pipelined variant (128-row tile, 2 stages) was faster in isolation but aborted in ROCm Triton's compiler (LLVM
iota_rangeassertion) for the server's kernel specialisation, so it is not used.Accuracy Tests
The output is bitwise identical to the current launch, so accuracy cannot change. Checked three ways on MI350X (
rocm/sgl-dev:v0.5.22-rocm724-mi35x-20261018,SGLANG_USE_AITER=1, our open deterministic-mode fixes for MI350X applied):BLOCK_N = 64gives output equal to the current launch (torch.equal); the new one is 2.0-2.6x faster.test_extend_attention_unified_gfx950_tile_bitwisepasses on MI350X. Two existing tests in the same file fail on gfx950 with and without this change (same results on the unchanged image):test_extend_attention_block_sizes(expects the tile [ROCm] Extend the gfx950 extend-attention tile to head_dim <= 128: -43% kernel, -14% TTFT, bit-identical #34461 added, which [AMD] Optimize Kimi-K3 Triton MLA prefill on gfx950 #35770 narrowed) and the head_dim-80 case oftest_extend_attention_unified_vs_regular(max diff 0.167, tolerance 0.15/0.17). Both are pre-existing; the first is fixed by [Perf] [AMD] attention: Restore the gfx950 extend tile for head_dim <= 128 #45099, which restores that tile and is independent of this PR (the two apply together cleanly and were tested together).python3 -m sglang.test.test_deterministic --test-mode {single,prefix,radix_cache} --n-trials 50,--test-mode prefix --return-logprob, and a bitwise batch-size check (the same prompt in batches of 1 to 50, 1,275 responses, token IDs and logprobs compared exactly): all pass for Qwen3-8B (TP1, TP2, TP8), Qwen3-30B-A3B, Phi-4, gpt-oss-20b (TP1, TP2) and gpt-oss-120b. Long prompts (16k-120k tokens alone vs with other requests in the batch, and with chunked-prefill boundaries moved by other requests) give identical token IDs and logprobs. Rechecked on the 2026-10-19 nightly (v0.5.22-rocm724-mi35x-20261019): Qwen3-8B and Qwen3-30B-A3B pass every check.Speed Tests and Profiling
python3 -m sglang.benchmark.serving --backend sglang --dataset-name random --random-range-ratio 1.0 --request-rate inf, deterministic mode, before and after alternating twice on the same GPU (every pair within 0.5%), output throughput:* Qwen3-8B with YaRN (factor 4, 128k context). Time to first token drops by the same factors (Qwen3-8B 32k: 41.4 -> 22.3 s); inter-token latency is unchanged (decode does not use this kernel). gpt-oss ran with ROCm/aiter#6583's deterministic MoE.
Profile at 64k input (Qwen3-8B, 8 prompts, 40 forward steps, deterministic mode):
_fwd_kernel_unified79.0 -> 30.7 s of GPU time; total GPU time 96 -> 48 s.No change without
--enable-deterministic-inferenceor off gfx950.Checklist