Skip to content

[AMD] Fix Triton 3.7 gfx950 extend-attention spills - #34741

Merged
HaiShaw merged 1 commit into
sgl-project:mainfrom
HaiShaw:fix/k3_triton-37_regression
Aug 14, 2026
Merged

HaiShaw merged 1 commit into
sgl-project:mainfrom
HaiShaw:fix/k3_triton-37_regression

Conversation

@kkHuang-amd

@kkHuang-amd kkHuang-amd commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Use an N32 tile for the gfx950 Lq576/Lv512 extend-attention specialization on Triton 3.7+ to eliminate register spilling and recover Kimi-K3 prefill performance, while preserving the existing Triton 3.6 configuration.

Motivation

On MI355X/gfx950, Triton 3.7 regresses the extend_attention.py::_fwd_kernel specialization for Lq=576, Lv=512, BLOCK_M=64, BLOCK_N=64, and num_warps=4:

  • VGPR usage increases from 483 to 512.
  • The kernel gains a 472-byte private segment and 186 scratch load/store instructions.
  • Rank-0 late-prefill p50 increases from 5.99 ms to 13.78 ms (+130%).
  • The kernel adds 187.17 ms, explaining 84.34% of the measured 221.93 ms prefill-span increase.
  • Kimi-K3 C32 throughput drops from the 6.19k tok/s range to 5.88k tok/s.

Reducing BLOCK_N to 32 preserves BLOCK_M and the launch grid while lowering KV-tile register pressure.

Modifications

  • Detect Triton 3.7+ from triton.__version__.
  • On gfx950 only, select (BLOCK_M, BLOCK_N, num_warps) = (64, 32, 4) for Lq=576/Lv=512 when using Triton 3.7+.
  • Keep the existing (64, 64, 4) tile for Triton 3.6 and all non-matching architectures/shapes.
  • Add block-selection coverage for both Triton version paths.
  • Add a numerical N64-vs-N32 test for the gfx950 Lq=576/Lv=512 shape.

Accuracy Tests

Focused correctness:

  • test_extend_attention_block_sizes: passed.
  • test_extend_attention_triton37_lq576_n32: passed.
  • Maximum absolute N64-vs-N32 difference: 0.00390625 (atol=2e-2, rtol=1e-2).

Full GSM8K control (1319 requested examples; 5 are reserved for few-shot prompting, so 1314 are scored):

Configuration Correct Score
Triton 3.7 N64 baseline 1251 / 1314 0.95205479
Triton 3.7 N32 candidate 1252 / 1314 0.95281583

The candidate does not regress full-set GSM8K accuracy. Maximum token capacity remains 933883.

Speed Tests and Profiling

Environment:

  • 8x AMD Instinct MI355X / gfx950
  • Torch 2.9.1 + ROCm 7.2
  • Triton 3.7
  • Kimi-K3 BF16, TP8

Isolated matched late-prefill shape (B=2, extend lengths [8192, 7661], Hq/Hkv=12/1, Lq/Lv=576/512):

Configuration p50 VGPR Private segment Scratch instructions
N64 baseline 12.57 ms 512 472-484 B 186-214
N32 candidate 5.24 ms 392-433 0 B 0

The candidate improves isolated p50 by 58.3% and removes all scratch spilling.

Serving benchmark: random 8192-input/1024-output requests, 64 warmups, no radix cache.

Concurrency Triton 3.7 baseline N32 candidate Delta
C2 970.53 tok/s 973.94 tok/s +0.35%
C4 1718.97 tok/s 1748.71 tok/s +1.73%
C8 2839.40 tok/s 2901.37 tok/s +2.18%
C16 4309.25 tok/s 4460.33 tok/s +3.51%
C32 5881.93 tok/s 6198.56 tok/s +5.38%

The N32 tile restores the full C2-C32 endpoint matrix. Triton 3.6 retains N64 because N32 regresses the isolated Triton 3.6 shape by 17.2% (5.34 ms to 6.26 ms).

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

Use the N32 tile for Lq576/Lv512 to eliminate scratch spilling without regressing Triton 3.6, with selection and numerical coverage.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a Triton 3.7-specific gfx950 tile configuration to prevent register spilling for Lq=576/Lv=512 extend attention.

Changes:

  • Selects a 64×32 tile for the affected configuration.
  • Adds tile-selection and numerical-equivalence tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/sglang/kernels/ops/attention/extend_attention.py Adds Triton version detection and the gfx950 workaround.
test/registered/attention/test_triton_attention_kernels.py Tests configuration selection and numerical accuracy.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kkHuang-amd kkHuang-amd changed the title Fix Triton 3.7 gfx950 extend-attention spills [AMD] Fix Triton 3.7 gfx950 extend-attention spills Aug 13, 2026
@kkHuang-amd kkHuang-amd added amd run-ci CI: run the baseline test suite on this PR labels Aug 13, 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.

triton3.7 and _gfx95 specific changes

@HaiShaw
HaiShaw merged commit 65d6210 into sgl-project:main Aug 14, 2026
182 of 224 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd jit-kernel 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