Skip to content

[Perf] [AMD] GLM5: Row-streaming KDA packed decode on gfx950 - #44659

Open
Raiden-Makoto wants to merge 3 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/glm53-kda-rowstream-decode
Open

Raiden-Makoto wants to merge 3 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/glm53-kda-rowstream-decode

Conversation

@Raiden-Makoto

@Raiden-Makoto Raiden-Makoto commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GLM-5.3-Flash's KDA layers use the safe gate (lower_bound), so on ROCm their decode skips the packed decode path. It runs fused_sigmoid_gating_delta_rule_update, which holds a [BV, K] FP32 state tile per program. The recurrent state update is bandwidth-bound on that FP32 state, and this kernel reaches only about 5 TB/s of in-place state traffic on MI355X at decode batch sizes.

This change adds a gfx950 Triton kernel that streams the FP32 state in row chunks per (request, head, row group), and routes GLM-5.3's safe-gate layers to the packed decode path on gfx950. CUDA already uses its own row-streaming kernel in this dispatcher; other HIP targets keep their current path.

Modifications

  • Add kda_packed_decode_rowstream, a gfx950 Triton row-streaming KDA decode kernel. It fuses QK L2 norm, the per-K gate with the optional safe-gate lower_bound, the sigmoid beta, the delta-rule state update, and the output. It uses one static launch configuration per decode batch bucket.
  • In fused_recurrent_kda_packed_decode, dispatch to the row-streaming kernel when covered() holds: gfx950, K=V=128, BF16 packed qkv, contiguous FP32 [slots, HV, V, K] state, and contiguous output and indices. Everything else keeps the existing CUDA and Triton paths.
  • Set TritonKDAKernel.supports_packed_decode_safe_gate on gfx950 only, so safe-gate layers reach the packed path there.
  • Padded -1 slots write zero output and leave the state pool untouched.
  • Add a gfx950 suite comparing output and final state against fused_sigmoid_gating_delta_rule_update. It covers every batch bucket, TP4 and TP8 head counts, safe gate on and off, padded slots, untouched pool slots, and 16 consecutive decode steps.

Accuracy Tests

Focused validation passed 3 gfx950 row-streaming tests (29 subtests) and the KDA Triton unit suite (5 passed, 1 skipped). Coverage includes batch buckets 1-64, 16 and 8 heads, safe gate on and off, padded -1 slots, untouched pool slots, state over 16 decode steps (atol/rtol 1e-5), output (atol/rtol 2e-2), and finite outputs. CUDA-graph replay is exercised by the CUDA-graph E2E runs below.

Full GLM-5.3-Flash MXFP4 TP4 GSM8K on snapshot b5688f25491202978c19c4d036eef579f61bbe07: 1,319 examples, 64 evaluator threads, 32,768 maximum output tokens, thinking enabled, temperature 1.0, top-p 0.95, sampling seed unset.

Configuration Score Stop rate Truncated rate Error rate
Base main 97.80% 100.00% 0.00% 0.00%
Row-streaming packed decode 97.27% 99.92% 0.08% 0.00%

Speed Tests and Profiling

Environment:

  • Hardware: AMD Instinct MI355X (gfx950)
  • Docker image: rocm/sgl-dev:v0.5.21-rocm724-mi35x-20261014
  • Model: amd/GLM-5.3-Flash-Quark-MXFP4, snapshot b5688f25491202978c19c4d036eef579f61bbe07
  • AITER: image default (e7d2453f2)
  • Base source SHA: 4e85e8ed37
  • Validated source SHA: ac7a44ecc5

Recurrent decode state update

GLM-5.3 shapes (K=V=128, FP32 state, safe gate lower_bound=-5), timed inside CUDA graphs. The baseline is the path GLM's safe-gate layers take on main (fused_sigmoid_gating_delta_rule_update); the candidate is fused_recurrent_kda_packed_decode dispatching to the row-streaming kernel. State bandwidth counts one FP32 state read plus one write per request.

TP Heads Batch Baseline (µs) Row-streaming (µs) Speedup State TB/s
4 16 1 6.57 3.02 2.18x 0.69
4 16 4 7.06 3.64 1.94x 2.30
4 16 8 8.13 4.64 1.75x 3.61
4 16 16 10.22 6.90 1.48x 4.86
4 16 32 14.63 10.71 1.37x 6.26
4 16 64 29.94 21.44 1.40x 6.26
8 8 1 6.55 2.92 2.24x 0.36
8 8 4 6.73 3.27 2.06x 1.28
8 8 8 7.11 3.64 1.95x 2.31
8 8 16 8.15 5.26 1.55x 3.19
8 8 32 10.27 6.63 1.55x 5.06
8 8 64 14.36 11.28 1.27x 5.95

Every measured cell beats the baseline.

End-to-end serving

GLM-5.3-Flash MXFP4 snapshot b5688f25491202978c19c4d036eef579f61bbe07, TP4, random 8K input / 1K output. The first concurrency-4 run in each repetition is the warmup; the tables average the two measured runs per concurrency. Arm A is base main (4e85e8ed37); arm B is that base plus this change (ac7a44ecc5). The arms are otherwise identical.

A. Base main:

Concurrency TTFT (ms) ITL (ms) E2EL (ms) Output tok/s
4 608.01 8.275 9071.17 451.38
8 978.75 9.405 10602.98 772.35
16 1675.54 11.070 12999.19 1259.97
32 3053.67 13.865 17234.92 1900.60
64 5814.07 19.205 25460.99 2573.09

B. Row-streaming packed decode (delta versus base main):

Concurrency TTFT (ms) Delta ITL (ms) Delta E2EL (ms) Delta Output tok/s Delta
4 608.87 +0.14% 8.175 -1.21% 8973.14 -1.08% 456.30 +1.09%
8 979.57 +0.08% 9.300 -1.12% 10489.88 -1.07% 780.67 +1.08%
16 1677.03 +0.09% 11.000 -0.63% 12934.15 -0.50% 1266.31 +0.50%
32 3053.68 +0.00% 13.845 -0.14% 17217.60 -0.10% 1902.51 +0.10%
64 5810.74 -0.06% 19.075 -0.68% 25324.46 -0.54% 2586.97 +0.54%

Row-streaming improves ITL by 0.14-1.21%, E2E latency by 0.10-1.08%, and output throughput by 0.10-1.09% across the complete TP4 matrix. TTFT is unchanged within +0.14%.

TP8 end-to-end serving

GLM-5.3-Flash MXFP4 TP8, 131,072 context, random 8K input / 1K output. The first concurrency-4 run in each repetition is the warmup; the tables average the two measured runs per concurrency. Arm A is base main (4e85e8ed37); arm B is that base plus this change (ac7a44ecc5). The arms are otherwise identical.

A. Base main:

Concurrency TTFT (ms) ITL (ms) E2EL (ms) Output tok/s
4 520.02 7.685 8382.05 488.47
8 863.54 8.495 9553.83 857.12
16 1509.95 9.455 11182.09 1464.62
32 2753.16 11.825 14846.35 2206.28
64 5252.95 16.000 21623.88 3029.46

B. Row-streaming packed decode (delta versus base main):

Concurrency TTFT (ms) Delta ITL (ms) Delta E2EL (ms) Delta Output tok/s Delta
4 521.74 +0.33% 7.615 -0.91% 8311.05 -0.85% 492.64 +0.85%
8 867.08 +0.41% 8.400 -1.12% 9463.28 -0.95% 865.32 +0.96%
16 1512.95 +0.20% 9.405 -0.53% 11133.60 -0.43% 1471.01 +0.44%
32 2758.60 +0.20% 11.740 -0.72% 14770.14 -0.51% 2217.64 +0.52%
64 5263.99 +0.21% 15.980 -0.12% 21614.19 -0.04% 3030.76 +0.04%

Row-streaming improves TP8 ITL by 0.12-1.12%, E2E latency by 0.04-0.95%, and output throughput by 0.04-0.96% across the complete matrix. TTFT is 0.20-0.41% higher. The change touches only the decode state update; prefill does not call this kernel.

Checklist

Scoped isort, Ruff, Ruff format, codespell, registered-test validation, and trailing-whitespace/end-of-file checks pass on the changed files.


CI States

Latest PR Test (Base): ❌ Run #44600717123
Latest PR Test (Extra): ⊘ Skipped -- add the run-ci-nv-extra label to opt in.
Latest PR Test (AMD ROCm 10): ❌ Run #44600716961

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@Raiden-Makoto
Raiden-Makoto marked this pull request as ready for review October 16, 2026 04:07
@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Oct 16, 2026
@github-actions

This comment has been minimized.

@Raiden-Makoto Raiden-Makoto changed the title [AMD] [GLM5] Row-streaming KDA packed decode on gfx950 [Perf] [AMD] GLM5: Row-streaming KDA packed decode on gfx950 Oct 19, 2026
Raiden-Makoto added a commit to Raiden-Makoto/squidward that referenced this pull request Oct 20, 2026
from sglang.kernels.ops.attention.fla.fused_recurrent import (
fused_recurrent_kda_packed_decode,
)
from sglang.kernels.ops.attention.fla.fused_sigmoid_gating_recurrent import (

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.

This test now runs on MI35x and fails here with ModuleNotFoundError: #45112 moved fused_sigmoid_gating_recurrent to sglang.kernels.ops.attention.linear (job). Please merge main and update the import.

@@ -0,0 +1,187 @@
"""Row-streaming KDA packed decode for gfx950.

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.

After #45112, fla/ holds the vendored FLA ops and SGLang's own linear-attention kernels live in attention/linear/. This file belongs there too, next to fused_sigmoid_gating_recurrent.py.

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

LGTM

Add a gfx950 row-streaming packed KDA decode kernel and route validated safe-gate KDA geometry through it. Unsupported hardware, layouts, dtypes, dimensions, and indices retain the existing decode path.
@Raiden-Makoto
Raiden-Makoto force-pushed the RM/glm53-kda-rowstream-decode branch from 65e59de to 6b1ca08 Compare October 27, 2026 15:56
@Jacob0226

Copy link
Copy Markdown
Contributor

NV CI all green
image

Raiden-Makoto added a commit to Raiden-Makoto/squidward that referenced this pull request Nov 2, 2026
Port sgl-project#44416's HIP gate/top-k onto sgl-project#44994's TopK.routing_inputs(), keep
sgl-project#41615's aiter_sparse_mla routing beside the ROCm DCP path, keep sgl-project#44659's
HIP guard and sgl-project#38764's conv tuning, and take main's fp32 correction-bias
routing that supersedes sgl-project#44415's copy.
@github-actions

This comment has been minimized.

This branch has not been deployed

No deployments
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