Skip to content

[AMD] perf: compact Triton extend-attention for ragged prefill (AMD/HIP-only) - #29677

Merged
HaiShaw merged 9 commits into
sgl-project:mainfrom
valechen:improve-ragged-mised-prefill
Aug 6, 2026
Merged

HaiShaw merged 9 commits into
sgl-project:mainfrom
valechen:improve-ragged-mised-prefill

Conversation

@valechen

@valechen valechen commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR improves Triton extend-attention performance for ragged mixed-prefill batches by adding an optional compact query-tile launch grid.

The legacy grid is rectangular and sized by max_len_extend:

grid = (batch_size, head_num, ceil(max_len_extend / BLOCK_M))

In a mixed batch, every short decode/partial-prefill row pays tile work proportional to the longest extend row. The compact path launches only the actual per-request query tiles:

grid = (compact_q_tiles, head_num)
compact_q_tiles = sum_i ceil(extend_len_i / BLOCK_M)

and falls back to the legacy grid when compacting would not reduce launch work.

Framing — this closes a triton-vs-flash-attn gap, it is not a new technique.
The flash-attention varlen kernels already launch ragged-aware: the aiter backend calls flash_attn_varlen_func / mha_batch_prefill_func with cu_seqlens (qo_indptr / kv_indptr), and their internal tile scheduler does work proportional to the sum of per-request query tiles — max_q_len is only a scalar bound, never a grid multiplier. So the aiter/flash-attn path does not pay the rectangular penalty. Only the triton extend kernel used a literal (batch_size, head_num, cdiv(max_len_extend, BLOCK_M)) grid. This PR brings the triton extend kernel up to parity with that ragged-aware launching; it has no effect on (and is not needed for) the aiter backend.

Why this matters: Ragged mixed-prefill is production-real. Live serving batches commonly combine requests with different prompt lengths, and mixed chunking combines decode rows with long prefill chunks in the same attention call.

Platform scope: The optimization is AMD/HIP-only to avoid impacting other vendors. Both the compact grid logic and the optional scheduler tile-budget admission are gated on _is_hip / _IS_HIP.

Default behavior: The feature is enabled by default on AMD/HIP platforms (SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=True). To disable it for testing or comparison:

SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=0

Modifications

Core files (4):

  1. python/sglang/kernels/ops/attention/extend_attention.py

    • Add _compact_extend_q_tiles_per_head() to compute per-request tile counts
    • Read SGLANG_TRITON_COMPACT_EXTEND_ATTENTION at launch time (gated on _is_hip)
    • Launch compact grid only when compact_tiles < legacy_tiles, otherwise fall back
    • The explicit use_compact_tile_grid parameter stays vendor-neutral for testing
  2. python/sglang/srt/layers/attention/triton_backend.py

    • Thread forward_batch.extend_seq_lens_cpu into extend_attention_fwd() so compact path has exact per-request extend lengths
  3. python/sglang/srt/managers/schedule_policy.py

    • Add estimate_prefill_extend_tile_metrics() and optional scheduler tile-budget admission
    • Environment controls: SGLANG_PREFILL_TILE_BUDGET (default 0 = disabled), SGLANG_PREFILL_TILE_BUDGET_MODE=compact|legacy
    • Gated on _IS_HIP — non-AMD scheduler admission unchanged even if env vars are set
  4. python/sglang/srt/environ.py

    • Add SGLANG_TRITON_COMPACT_EXTEND_ATTENTION = EnvBool(True) environment variable definition
    • Enabled by default on AMD/HIP platforms

Tests (2):

  1. test/registered/attention/test_triton_attention_kernels.py

    • test_compact_extend_attention_tile_count: verify compact tile logic
    • test_extend_attention_compact_grid: compact vs legacy equivalence
  2. test/registered/unit/managers/test_prefill_adder.py

    • Scheduler tile-budget tests
    • test_prefill_tile_budget_disabled_on_non_hip: verify non-HIP no-op

All tests registered in CI (AMD + CUDA suites).

Accuracy Tests

Unit test correctness

All tests run in the registered SGLang test tree:

# Scheduler tile-budget tests
python3 -m pytest -q test/registered/unit/managers/test_prefill_adder.py -k tile
# 3 passed, 10 deselected

# Compact tile-count and compact-vs-legacy equivalence
python3 -m pytest -q \
  test/registered/attention/test_triton_attention_kernels.py::TestTritonAttention::test_compact_extend_attention_tile_count \
  test/registered/attention/test_triton_attention_kernels.py::TestTritonAttention::test_extend_attention_compact_grid
# 2 passed

# Existing extend-attention tests under compact mode
SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1 python3 -m pytest -q \
  test/registered/attention/test_triton_attention_kernels.py::TestTritonAttention::test_extend_attention \
  test/registered/attention/test_triton_attention_kernels.py::TestTritonAttention::test_extend_attention_sliding_window
# 2 passed

Model accuracy (4-GPU, real weights, Triton backend)

Setup: amd/DeepSeek-R1-MXFP4, TP=4, Triton backend (--attention-backend triton), MI355X (gfx950), compact grid enabled (SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1), --kv-cache-dtype fp8_e4m3. Requires the forward_mla.py w_kc None guards for Quark MXFP4.

GSM8K result (1319 questions, 5-shot):

Accuracy: 0.940  (passes required >0.94)
Invalid: 0.000
Output throughput: 1022.1 token/s

This validates the full multi-GPU model path with the compact grid actually exercised — the Triton extend kernel is the code path this PR modifies. Accuracy matches the AITER reference (0.946) within run-to-run noise, confirming the compact grid produces numerically correct results end-to-end.

Server command (Triton backend)
HIP_VISIBLE_DEVICES=4,5,6,7 \
SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1 \
python3 -m sglang.launch_server \
  --model-path amd/DeepSeek-R1-MXFP4 --tp-size 4 --trust-remote-code \
  --chunked-prefill-size 131072 --host 0.0.0.0 --port 9000 \
  --disable-radix-cache --mem-fraction-static 0.8 \
  --max-running-requests 64 --kv-cache-dtype fp8_e4m3 \
  --attention-backend triton
GSM8K client command
python3 benchmark/gsm8k/bench_sglang.py \
  --host http://localhost --port 9000 --backend srt \
  --num-shots 5 --num-questions 1319 --parallel 1319

Speed Tests and Profiling

Hardware: 4x AMD Instinct MI355X (gfx950)

Setup: Production-like Triton serving benchmark (SGLang HTTP server + sglang.bench_serving)

  • Model: Qwen/Qwen2.5-7B-Instruct, --load-format dummy, TP=4
  • Attention: --attention-backend triton, --enable-mixed-chunk --chunked-prefill-size 2048
  • Config: SGLANG_USE_AITER=0, no SGLANG_PREFILL_TILE_BUDGET
  • Variable: only SGLANG_TRITON_COMPACT_EXTEND_ATTENTION toggled (1 = compact, 0 = default)

Fixed-workload throughput, CUDA graphs ENABLED (mean of 3 seeds)

These are end-to-end measurements (prefill + decode) via sglang.bench_serving at --request-rate inf (all requests fired at once, closed-loop, to fixed-workload throughput). Tok/s is total end-to-end throughput; TTFT is the prefill latency; TPOT is the per-output-token (decode) latency.

Workload notation <INPUT>/<OUTPUT>, <N> req: INPUT/OUTPUT are the input and output length parameters, N is the number of requests (--num-prompts). Actual lengths are sampled uniformly from [len * range_ratio, len]:

  • Ragged = --random-range-ratio 0.5 → lengths vary (e.g. 4096/128 → inputs in [2048, 4096], outputs in [64, 128], i.e. 64–128 decode iterations per request).
  • Uniform = --random-range-ratio 1.0 → every request is exactly INPUT/OUTPUT (e.g. 4096/128 → all inputs 4096, all outputs 128).
Workload Compact tok/s Default tok/s Tok/s delta TTFT delta TPOT delta
Ragged 4096/128, 64 req † 49,877 14,581 +242.0% -67.2% -76.2%
Ragged 8192/64, 32 req 50,223 16,673 +201.2% -63.1% -71.3%
Uniform 4096/128, 64 req 49,610 11,976 +314.2% -72.4% -80.0%

Variance: Total tok/s CV ≤ 2.5% across 3 seeds — the gap is not seed noise.

Why graphs matter: The default path barely improves with graphs because its bottleneck is the rectangular prefill grid (not graph-captured). The compact path removes that waste, letting decode graphs take effect.

Open-loop traffic, production-shaped arrivals

This is the realistic SLA story. With a fixed offered rate of 8 req/s (CUDA graphs ENABLED, the default deployment), the legacy Triton path cannot keep up — it drains only 3.48 req/s, so the queue builds and latency collapses. With the compact grid, the same server on the same hardware sustains the offered load at sub-second latency.

Config: --request-rate 8 --max-concurrency 64 --random-input-len 4096 --random-output-len 128 --random-range-ratio 0.5 --num-prompts 128

Metric Compact Default Delta
Sustained request throughput 8.86 req/s 3.48 req/s +154.6%
Total throughput 28,439 tok/s 11,182 tok/s +154.3%
Mean E2E latency 0.88 s 16.68 s -94.7%
P99 E2E latency 1.43 s 30.96 s -95.4%
Mean TTFT 87 ms 2,485 ms -96.5%
Mean TPOT 8.2 ms 147.2 ms -94.4%

At an offered rate of 8 req/s the default path falls behind (3.48 < 8 req/s) and mean end-to-end latency blows up to ~16.7 s (P99 ~31 s); compact keeps up at ~0.88 s mean — the difference between an SLA-violating server and a healthy one, with no config change other than the compact flag.

Server command (Triton benchmark)

Launched once per setting; only SGLANG_TRITON_COMPACT_EXTEND_ATTENTION differs (1 = compact, 0 = default). The command below is the graph-ENABLED (default) deployment used for all numbers above.

SGLANG_USE_AITER=0 USE_ROCM_AITER_ROPE_BACKEND=0 \
SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1 \
python3 -m sglang.launch_server \
  --model-path Qwen/Qwen2.5-7B-Instruct --trust-remote-code \
  --tensor-parallel-size 4 --load-format dummy --attention-backend triton \
  --host 0.0.0.0 --port 8011 --mem-fraction-static 0.80 --context-length 32768 \
  --chunked-prefill-size 2048 --enable-mixed-chunk --max-running-requests 128 \
  --disable-custom-all-reduce --watchdog-timeout 10000
Saturated client command (per workload/seed)
python3 -m sglang.bench_serving \
  --backend sglang --host 127.0.0.1 --port 8011 \
  --model Qwen/Qwen2.5-7B-Instruct --dataset-name random \
  --random-input-len 4096 --random-output-len 128 --random-range-ratio 0.5 \
  --num-prompts 64 --request-rate inf --warmup-requests 4 --flush-cache --seed 1 \
  --output-file ragged_4096x128_n64_seed1.json
# Other workloads: 8192/64 n32 ratio 0.5; 4096/128 n64 ratio 1.0 (uniform)
# Repeated with --seed 1, 2, 3 for variance check
Open-loop client command
python3 -m sglang.bench_serving \
  --backend sglang --host 127.0.0.1 --port 8011 \
  --model Qwen/Qwen2.5-7B-Instruct --dataset-name random \
  --random-input-len 4096 --random-output-len 128 --random-range-ratio 0.5 \
  --num-prompts 128 --request-rate 8 --max-concurrency 64 \
  --warmup-requests 4 --flush-cache --seed 1

Multi-model breadth

The compact grid's benefit is a function of the per-GPU attention geometry (query heads, head_dim) and batch raggedness — not of weight values — so it generalizes across model families. Kernel microbenchmark of extend_attention_fwd(compact vs legacy) at each model's published shape, mapped to a realistic tensor-parallel shard, single MI355X. Every result is numerically bit-exact (max abs diff = 0.0). Speedup is the extend-attention kernel time.

Model per-GPU H_Q/H_KV/D mixed (1×2048 + 31×1) ragged (4×1024 + 28×8)
Llama-3.1-8B 32/8/128 14.9× 5.8×
Llama-3.1-70B 16/2/128 11.7× 4.7×
Llama-3.1-405B 16/1/128 11.6× 4.8×
Qwen2.5-7B 28/4/128 13.6× 5.3×
Qwen2.5-72B 16/2/128 11.7× 4.8×
Mistral-7B-v0.3 32/8/128 15.0× 5.7×
Mixtral-8x7B 16/4/128 12.8× 5.0×
Mixtral-8x22B 12/2/128 11.3× 4.6×
Gemma-2-9B 16/8/256 9.2× 4.1×
Gemma-2-27B 16/8/128 12.8× 5.1×
Phi-3-medium-14B 20/5/128 13.8× 5.2×
Command-R+-104B 24/2/128 13.2× 5.2×
Yi-34B 14/2/128 11.2× 4.8×
Falcon-40B (MQA) 32/1/64 13.3× 5.3×
GPT-3-175B (closed-weight) 12/12/128 12.2× 4.8×
GPT-J-6B (closed-weight) 16/16/256 9.2× 4.1×
PaLM-540B (MQA, closed-weight) 6/1/256 7.0× 3.4×

Covers GQA, MQA, and MHA; dense and MoE; head_dim 64/128/256 (the 256 cases land ~9× vs ~12–15× for 128, still large). Closed-weight rows use published shapes —
just as valid since the effect is geometry-only.

TinyLlama-1.1B End2End

Independent end-to-end (prefill + decode) serving run on a different architecture than Qwen — TinyLlama-1.1B (LlamaForCausalLM), TP=1, dummy weights, --attention-backend triton, saturated (--request-rate inf, closed-loop) ragged 2048/128, mean of 2 seeds.

Workload: --random-input-len 2048 --random-output-len 128 --random-range-ratio 0.5 → inputs in [1024, 2048], outputs in [64, 128], i.e. 64–128 decode iterations per request.

Metric Default Compact Delta
Total throughput 8,375 tok/s 67,477 tok/s +706%
Request throughput 5.05 req/s 40.7 req/s +706%
Mean TTFT 8,777 ms 1,167 ms −87%
Mean E2E 24,411 ms 2,768 ms −89%

The gain exceeds Qwen-7B's +242% because for a tiny model the rectangular attention-grid waste is a larger fraction of per-step compute.

DeepSeek R1 MXFP4 prefill-only validation

Test Environment:

  • Model: amd/DeepSeek-R1-MXFP4 (Quark MXFP4 quantization, DeepSeek V3 architecture, 671B parameters)
  • Hardware: 4× AMD MI355X (gfx950), TP=4
  • Backend: --attention-backend triton
  • Requires forward_mla.py w_kc None guards for Quark MXFP4
  • Workload: Prefill-only (large input, 1 output token) — the PR's optimization target

Open-loop traffic benchmark (4 req/s arrival rate, 64 requests):

Metric Baseline Compact Delta
Sustained throughput 15,810 tok/s 16,181 tok/s +2.4%
Sustained request rate 3.92 req/s 4.01 req/s +2.3%
Mean latency 1.25s 0.83s -33.8%
P50 latency 1.01s 0.73s -27.6%
P99 latency 3.16s 2.69s -14.8%

Key Findings:

  1. Compact provides measurable benefit for prefill: +2.4% throughput, -33.8% mean latency
  2. Both modes sustain 4 req/s (baseline at 98%, compact at 100% utilization)
  3. Much smaller gain than Qwen (+2.4% vs +154%) because:
    • Attention is only 12% of DeepSeek prefill time (profiler-measured)
    • Communication (42%) and MoE (34%) dominate
    • 671B MXFP4 is memory-bandwidth-bound

Why Latency Improvement is Larger Than Throughput:

The -33.8% latency improvement vs +2.4% throughput makes sense:

  • At 4 req/s (near saturation), baseline starts queueing requests
  • Compact's 2.4% efficiency gain reduces queue wait time disproportionately
  • Throughput improvement is limited by system bottlenecks (communication, MoE)
  • Latency improvement reflects reduced queueing delays

Profiling Breakdown (prefill-only, PyTorch profiler):

Component breakdown for DeepSeek R1 MXFP4 prefill (TP=4, 4096 input tokens):

  • Communication (TP all-reduce): 42% (22.85ms)
  • MoE compute: 34% (18.46ms)
  • Attention (extend_attention): 12% (6.56ms) ← PR's optimization target
  • Weight loading + dequantization: 12% (6.66ms)

Even in prefill (this PR's target), attention is only ~12% of execution time. A 50-67% reduction in attention tiles (compact grid) would theoretically save 3.3-4.4ms out of 54.5ms (~6-8% end-to-end speedup). The observed +2.4% reflects that:

  1. Tile reduction doesn't eliminate 100% of wasted compute
  2. DeepSeek R1 is memory-bandwidth-bound, not compute-bound
  3. Communication and MoE dominate, not attention

Mixed Workload Results:

A testing with 1 prefill + 10 decode iterations showed minimal benefit (+0.1% throughput) because prefill attention is only a small fraction of the overall E2E time when combined with decode. The prefill-only test above correctly isolates the PR's optimization target and shows the measurable +2.4% throughput gain on prefill workloads.

Server command (Baseline mode)
HIP_VISIBLE_DEVICES=4,5,6,7 \
SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=0 \
python3 -m sglang.launch_server \
  --model-path amd/DeepSeek-R1-MXFP4 \
  --tp-size 4 --trust-remote-code \
  --chunked-prefill-size 131072 --host 0.0.0.0 --port 9000 \
  --log-requests --disable-radix-cache --mem-fraction-static 0.8 \
  --max-running-requests 64 --kv-cache-dtype fp8_e4m3 \
  --attention-backend triton
Server command (Compact mode)
# Same as baseline, but with SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1
HIP_VISIBLE_DEVICES=4,5,6,7 \
SGLANG_TRITON_COMPACT_EXTEND_ATTENTION=1 \
python3 -m sglang.launch_server \
  --model-path amd/DeepSeek-R1-MXFP4 \
  --tp-size 4 --trust-remote-code \
  --chunked-prefill-size 131072 --host 0.0.0.0 --port 9000 \
  --log-requests --disable-radix-cache --mem-fraction-static 0.8 \
  --max-running-requests 64 --kv-cache-dtype fp8_e4m3 \
  --attention-backend triton
Client command (Prefill-only benchmark)
python3 open_loop_benchmark_r1_mxfp4.py \
    --mode {baseline|compact} \
    --request-rate 4 \
    --max-concurrency 64 \
    --random-input-len 4096 \
    --random-output-len 1 \
    --random-range-ratio 0.5 \
    --num-prompts 64 \
    --seed 42

Conclusion:

The optimization works as designed and provides measurable benefit (+2.4% throughput, -33.8% latency) on DeepSeek R1 MXFP4 prefill workloads, but the gain is modest compared to smaller models because DeepSeek R1's unique architecture (massive MoE + TP communication) means attention is only 12% of prefill time. The compact grid successfully reduces wasted tile launches, but this translates to limited end-to-end impact when the model is dominated by communication and MoE compute rather than attention.

Caveats

  • Large serving wins are for the Triton attention backend under mixed prefill. They should not be claimed for the AITER / DeepSeek-R1-MXFP4 path; on that path (uniform 70k prompts, AITER, speculative decode) end-to-end movement is modest, which is expected since the PR targets the Triton extend grid.

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 #31030229198
Latest PR Test (Extra): ❌ Run #31119790024

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@hubertlu-tw hubertlu-tw changed the title perf: compact Triton extend-attention for ragged prefill (AMD/HIP-only) [AMD] perf: compact Triton extend-attention for ragged prefill (AMD/HIP-only) Jun 29, 2026
@hubertlu-tw

Copy link
Copy Markdown
Collaborator

@valechen please run

$ pip install pre-commit
$ pre-commit run --all-files

to fix linter errors for your PR. Thanks.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

root and others added 2 commits August 3, 2026 18:55
Remove the SGLANG_PREFILL_TILE_BLOCK_M env var and derive BLOCK_M from
_get_block_sizes_for_extend_attention() in TritonAttnBackend, threading it
through the scheduler to PrefillAdder's tile-budget admission. This drops a
user-facing knob and fixes a latent mismatch: the fixed default of 64 was
wrong for head_dim=192 (DeepSeek MLA), where the kernel actually uses 128.
@valechen
valechen force-pushed the improve-ragged-mised-prefill branch from 022d3f0 to 8b3d6c4 Compare August 3, 2026 19:13
@valechen

valechen commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@valechen

valechen commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@sgl-project sgl-project deleted a comment from amd-bot Aug 4, 2026
@michaelzhang-ai

michaelzhang-ai commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

The only AMD pr ci issue (https://github.com/sgl-project/sglang/actions/runs/30872051504/job/91882062824?pr=29677#logs) is pre-existing on main: run 30816055633 (head 3953788, Aug 3) fails on the same file with the same error. The main run before it passed, so it's a flaky PD-disagg transfer on the MI35x fabric. Don't keep re-running — that job queued 12.5h before starting. Just post the main link so the merge oncall can waive it.

The rest of the board is actually good. The full AMD matrix ran this time (unlike July, when the gate timed out and skipped everything), and all four of your tests passed on real HIP hardware:

test_triton_attention_kernels.py passed mi300 1-gpu-small-amd part 3
test_prefill_adder.py passed mi300 1-gpu-small-amd part 10
test_verify_splitkv.py passed mi35x 1-gpu-small-amd
test_deepseek_mla_dispatch.py passed mi35x 1-gpu-small-amd
So the compact grid branch was genuinely exercised with _is_hip=True — the gap flagged last time is closed.

@HaiShaw @valechen

@HaiShaw

HaiShaw commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

@valechen @bingxche look to have all PR Test Base / base-a/b/c tests passing before merge.

@yichiche

yichiche commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

@HaiShaw All PR Test Base / base-a/b/c clear.

@yctseng0211

Copy link
Copy Markdown
Collaborator

cuda CI all green
amd ci : stage-b-test-1-gpu-small-amd (linux-mi300-1gpu-sglang, 8) is a known issue, resolved in the latest main.

@yctseng0211

yctseng0211 commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

To test amd stage-c (skipped for the failed stage-b)
https://github.com/sgl-project/sglang/actions/runs/31120528274
cc: @michaelzhang-ai please help monitor this run, thanks.

@HaiShaw
HaiShaw merged commit 18e6c61 into sgl-project:main Aug 6, 2026
312 of 350 checks passed
@yichiche

yichiche commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

This PR includes #30407. For the experiment on how it resolves the segmentation fault, please see here.

saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
akao-amd added a commit to akao-amd/sglang that referenced this pull request Dec 3, 2026
…during server warmup

ROCM-31261: since sgl-project#29677 the first multi-request prefill after a fresh start
JIT-compiles new variants of the Triton extend-attention kernel (_fwd_kernel)
on every rank: `compact_batch_size` is an int argument Triton specializes when
it equals 1, and the compact tile grid (ragged batches, HIP) is a constexpr.
The bs=1 warmup covers neither, so ~0.9 s of compiles land in the first
client's prefills. On MI355X, gpt-oss-120b TP8, QA's cold benchmark (32 x 8000
tokens): median TTFT 245 ms on 0.5.15 vs 1063 ms on 0.5.18 and 1268 ms on 0.5.21.

- extend_attention: do_not_specialize compact_batch_size, so the batch size no
  longer selects a binary (also covers bs divisible by 16).
- http_server: the warmup also prefills a uniform and a ragged pair (1 new
  token each) before the server reports ready; SGLANG_WARMUP_BATCHED_EXTEND=0
  turns it off.

Measured on 0.5.21 (088f7d8), caches wiped: cold median TTFT 1268 -> 314 ms
(warm-cache 312 ms), no _fwd_kernel compiles during serving.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd bypass-fastfail deepseek documentation Improvements or additions to documentation high priority jit-kernel npu run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants