Skip to content

[AMD] [GLM-5.3-Flash Day 0] Enable the k-pool DSA indexer on gfx950 - #39341

Merged
hnyls2002 merged 10 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-day0-kpool-preshuffle
Sep 22, 2026
Merged

hnyls2002 merged 10 commits into
sgl-project:mainfrom
Jacob0226:jacob/glm53-day0-kpool-preshuffle

Conversation

@Jacob0226

@Jacob0226 Jacob0226 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GLM-5.3-Flash does not start on ROCm. The server dies on the first forward with

NotImplementedError: kpool indexer is only supported on CUDA

The k-pool indexer computes the scores that decide which tokens sparse attention looks at. It needs two pieces that exist only on NVIDIA — a tilelang kernel whose own selector returns False off CUDA, and DeepGEMM, which has no ROCm build. With neither available there is nothing left to call, so it raises instead of falling back.

This gives ROCm those two pieces by calling AITER, and fixes the one thing that has to move with them: the memory layout of the cache AITER reads.

What Change
decode scores AITER's paged kernel instead of tilelang/DeepGEMM
prefill scores AITER's Triton kernel instead of DeepGEMM
the cache both use AITER expects it written in 16x16 tiles, not row by row, so the five kernels that touch it now share one offset helper
very long prompts AITER's prefill kernel miscompiles once its output passes 2 GiB and kills every rank; the work is split to stay under it (ROCm/aiter#5114, @Arist12)

Scope

Two files in the ROCm k-pool indexer path, plus tests. Nothing outside that path moves.

Affected GLM-5.3-Flash on MI355X (gfx950)
Unaffected CUDA, and any ROCm model without a pooled DSA indexer — same branches as before
New knobs none; the existing --dsa-paged-mqa-logits-backend and AITER's capability probe decide

Read and write must land together: convert one side only and the cache is misread rather than rejected, which is why this is one PR.

This does not wait on AITER. ROCm/aiter#5114 is the upstream bug report, not a fix. The row split here is the SGLang-side workaround, and it is the same one already merged for the non-pooled indexer in #36960 — dsa_indexer.py on main carries the identical bound today.

Test plan

Recovery of #37685 and its #38544 replacement; rebuilt on main @ 6388b6cfb, files byte-identical to #38544's head, so these numbers are carried over rather than re-run.

A wrong layout never raises, it silently returns a wrong top-k — so the test runs against two deliberately broken ones as well. Image rocm/sgl-dev:v0.5.18-rocm720-mi35x-20260901, gfx950, layout the only variable:

Layout under test Result
reader row-major, writer tiled 1 error
tile stride short by a factor of the tile width 3 failed — writes collide, 6511 distinct offsets where 8191 are needed
this PR 3 passed

The 2-GiB bound (@Arist12's commit, authorship intact): on 8x MI355X a 150K-token prompt is unchanged, and 300K and 600K now finish — 300K previously took all eight ranks down.

End to end, since no single PR here can serve the model on its own: main plus the eight open Day-0 PRs — #39338, #39339, #39340, #39341, #38545, #38546, #38547 and #39317 — which all merge cleanly onto it. rocm/sgl-dev:v0.5.19-rocm720-mi35x-20260909, MI355X TP4, decode CUDA graphs on, 1,319 GSM8K examples, one scoring pass each. Only the checkpoint differs between the two rows:

Checkpoint GSM8K
zai-org/GLM-5.3-Flash, block FP8 97.27%
amd/GLM-5.3-Flash-Quark-MXFP4 96.51%

Accuracy: not attributable to this PR in isolation, and there is no standalone baseline — GLM-5.3-Flash does not start on ROCm without the rest of the stack.


CI States

Latest PR Test (Base): ⏳ Run #35778831874
Latest PR Test (Extra): ❌ Run #35778831876
Latest PR Test (AMD ROCm 10): ⏳ Run #35778831779

…ayout

The k-pool indexer is CUDA-only end to end. forward_cuda raises
NotImplementedError off CUDA, the paged (decode) path picks between a
tilelang kernel whose selector returns False off CUDA and DeepGEMM, and
the ragged (prefill) path calls deep_gemm.fp8_mqa_logits directly.
DeepGEMM has no ROCm build, so GLM-5.3-Flash cannot start.

Open the forward gate to HIP and route both logits paths to AITER:

  - paged: aiter_paged_mqa_logits(..., preshuffle=True), resolved through
    DSAPagedMQALogitsBackend so --dsa-paged-mqa-logits-backend reaches
    this path rather than branching on is_hip() at the call site.
    resolve() already pins ROCm to AITER.
  - ragged: _fp8_mqa_logits() picks aiter.ops.triton.fp8_mqa_logits on
    HIP. It takes the fp8 values and scales as separate arguments where
    DeepGEMM takes a tuple.

AITER's paged kernel reads the index-K cache in a 16x16 tile order, so
kpool_fp8_index has to write it that way. The four write kernels and the
one read kernel now share _kpool_cache_k_offsets, which follows
_set_k_and_s_triton_kernel in index_buf_accessor.py -- the non-pooled
indexer already lays its cache out this way for the same AITER kernel,
and the two must agree.

aiter_paged_mqa_logits inserts the next_n dim itself, so q_fp8 stays
[tokens, heads, dim] through the dispatch and the tilelang and DeepGEMM
branches unsqueeze at their own call sites.

AITER's fp8_mqa_logits only compiles while the fp32 [num_q x num_k]
logits fit a 32-bit buffer_store offset; above 2 GiB it takes a gl.store
fallback that fails to compile and abort()s every TP rank. The query rows
are split so each call stays under the cap. That bound is Yikai Zhang's
work, contributed to the sgl-project#38544 replacement.

Add layout coverage. A write/read disagreement here does not raise, it
silently returns the wrong top-k, so the offsets are pinned against an
independent reference, checked for collisions, and round-tripped through
the reader. The round trip follows the runtime tile rather than pinning
16, so it also holds on a build without AITER's preshuffle kernel.

Recovers sgl-project#37685, which GitHub closed when its base branch
xinyuan/glm-5.3-flash-support was merged into main, and supersedes the
sgl-project#38544 replacement.

Co-Authored-By: Yikai Zhang <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Raiden-Makoto <[email protected]>
@Jacob0226 Jacob0226 changed the title [AMD] [GLM-5.3-Flash Day 0] Write and read the k-pool index-K cache in AITER's preshuffle layout [AMD] [GLM-5.3-Flash Day 0] Enable the k-pool DSA indexer on gfx950 Sep 14, 2026
1am9trash pushed a commit that referenced this pull request Sep 17, 2026
Squashed from #39341, which carries the same change
against main and remains open there for review.

Co-Authored-By: Jacob Chang <[email protected]>
Co-Authored-By: Yikai Zhang <[email protected]>
Jacob0226 and others added 4 commits September 18, 2026 15:35
Two textual conflicts, plus one the merge could not see.

dsa_indexer_kpool.py imports: main added dsa_use_prefill_cp from dsa/utils
while this branch added aiter_can_use_preshuffle_paged_mqa beside it and a
DSAPagedMQALogitsBackend import. Independent additions, both kept.

test_dsa_mqa_logits_chunking.py: main moved the chunk decision into
mqa_logits_utils and rewrote the first three tests around
mqa_logits_should_chunk; this branch added the k-pool split tests, which need
sys/types/mock and dsa_indexer_kpool. Both import sets kept. The branch also
imported dsa_indexer, which main's rewrite left unused, so it is dropped
rather than tripping ruff F401.

The silent one: main's mqa_logits_utils now defines MQA_LOGITS_MAX_BYTES_ROCM
and MQA_LOGITS_BYTES_PER_ELEM with the same values, and for the same aiter
buffer_store reason, as the private copies this branch added to
dsa_indexer_kpool. Two definitions of one 2 GiB bound would have to be updated
together when ROCm/aiter#5114 ships, so the private pair is removed and the
shared constants are used, as dsa_indexer.py already does. The test patches
the imported name accordingly.
@kevin-mii

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/unit/model_executor/runner_utils/test_graph_pool_borrow.py::TestGraphPoolBorrow.test_input_logprobs_survive_replay_with_growing_chunks

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/unit/model_executor/runner_utils/test_graph_pool_borrow.py::TestGraphPoolBorrow.test_input_logprobs_survive_replay_with_growing_chunks:

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/model_executor/runner_utils/test_graph_pool_borrow.py TestGraphPoolBorrow.test_input_logprobs_survive_replay_with_growing_chunks

@kevin-mii

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@kevin-mii

Copy link
Copy Markdown
Collaborator

base-b: 16/20 jobs green on 2f57e29, no failures. Remaining shards (base-b-test-1-gpu-large (3), base-b-test-2-gpu-large (3,4,5)) are queued on runner availability: https://github.com/sgl-project/sglang/actions/runs/35666108660

The earlier base-b-test-1-gpu-small red was test_graph_pool_borrow.py::TestGraphPoolBorrow.test_input_logprobs_survive_replay_with_growing_chunks flaking; it passed on rerun on the same SHA, and the remaining failures in that attempt were fail-fast cascades.

…take

The three layout cases compared `_kpool_cache_k_offsets` against a retyped
copy of its own formula, so they stayed green if the non-pooled writer in
`index_buf_accessor` ever changed its tile order -- the one drift the module
docstring says it fears. Replace them with a round trip that writes through
`SetKAndS.triton` and reads back through `gather_index_k_scale_prefix_into`,
so both writers and the reader are pinned to each other by execution, not by
a second copy of the arithmetic. The file launches no server, so it moves
from `e2e/attention/` to `unit/layers/attention/` beside the chunking test,
and `est_time` follows the ~8 s measured on mi35x.

`_fp8_mqa_logits` hand-rolled the row split that `mqa_logits_rows_per_chunk`
already implements and the DSV4 indexers already use; reuse it. With the
helper's own tests covering the "everything fits" branch, the
`below_the_cap_is_one_call` case is a duplicate and goes. The split case
stays: it checks the wrapper's slicing and reassembly, which nothing else
covers.

Comments and docstrings the PR added are trimmed to the one constraint that
makes each line look right.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kevin-mii

Copy link
Copy Markdown
Collaborator

Pushed 7483fff30b onto this branch (maintainer edit) to trim the tests to the cases that can fail on a real mistake, per .claude/rules/unit-test-admission.md.

Layout tests: three cases → one. The three cases in test_kpool_preshuffled_cache_layout.py compared _kpool_cache_k_offsets against a retyped copy of its own formula, so they would stay green if _set_k_and_s_triton_kernel in index_buf_accessor.py ever changed its tile order — the one drift the module docstring says it fears. Replaced with a round trip that writes through SetKAndS.triton and reads back through gather_index_k_scale_prefix_into, so both writers and the reader are pinned to each other by execution rather than a second copy of the arithmetic. The file launches no server, so it moved from e2e/attention/ to unit/layers/attention/; est_time follows the ~8 s measured on mi35x.

Chunking: reuse the existing helper, drop the duplicate case. _fp8_mqa_logits hand-rolled the row split that mqa_logits_rows_per_chunk already implements and the DSV4 indexers already use. With the helper's own tests covering the "everything fits" branch, test_kpool_below_the_cap_is_one_call was redundant. The split case stays: it is the only check on the wrapper's slicing and reassembly.

Comments and docstrings added by the PR are trimmed to the one constraint that makes each line look right.

CUDA coverage gap (not this PR's fault). The PR rewrites all five kpool cache write kernels, and on CUDA the new PRESHUFFLE_TILE=0 path must reduce to the old row-major layout. The tests for those kernels (test_dsa_kpool_multi_pool.py, test_dsa_kpool_metadata_fusion.py) register on base-b-kernel-unit, which is dispatched only when python/sglang/kernels/** or test/registered/kernels/** change. This PR touches python/sglang/srt/..., so call-jit-kernel-tests was skipped on every head; the only coverage is the scheduled run on main. Dispatching them by hand below so there is pre-merge evidence; the path-filter fix will go in a separate CI PR.

mi35x stage-b-test-1-gpu-small-amd-mi35x already passed on the new head; CUDA base is still running.

@sgl-project sgl-project deleted a comment from github-actions Bot Sep 22, 2026
@kevin-mii

kevin-mii commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

CUDA kpool kernel tests dispatched by hand on the 1-gpu-5090 pool against 7483fff30b (the 1-gpu-h100 queue was not picking up): both pass.

https://github.com/sgl-project/sglang/actions/runs/35698964347

File Result
registered/kernels/ops/attention/test_dsa_kpool_multi_pool.py 3 tests, OK
registered/kernels/ops/attention/test_dsa_kpool_metadata_fusion.py 1 test, OK

These two register on base-b-kernel-unit, which per-PR CI only dispatches for changes under python/sglang/kernels/** or test/registered/kernels/**, so they had not run on any head of this PR. Both are plain Triton kernels with no compute-capability gate, so the 5090 result stands in for the H100 one. The path-filter gap will be fixed in a separate CI PR.

@hnyls2002
hnyls2002 merged commit 3afdde5 into sgl-project:main Sep 22, 2026
64 of 92 checks passed
hdt98 added a commit to hdt98/sglang that referenced this pull request Sep 25, 2026
Adopt upstream sgl-project#39341 (k-pool DSA indexer on gfx950) and sgl-project#39779 (MXFP4 MTP
draft mapper) in the conflicted files. Keep on top of them the int64 page
index in the index-K prefix gather, and count aiter's 256-column row padding
when splitting ragged MQA logits under the 2 GiB cap.
hdt98 added a commit to hdt98/sglang that referenced this pull request Sep 25, 2026
Reset quark.py to upstream sgl-project#39779's per-expert fused config resolution and
keep only the block-FP8 activation-grouping check. Fused shared experts are
CUDA-only, so the removed shared-expert precision matching loses nothing on
ROCm.

Drop tests whose targets are now upstream code or duplicate upstream
coverage: k-pool cache layout and backend dispatch (sgl-project#39341), TileLang
zero-RoPE (sgl-project#38547), transform_index widths (sgl-project#39340), mHC HIP dispatch
(sgl-project#38545), the NextN name mapper, write-plan multi-pool, negative-slot
scatter, and the comment-only AITER runner. Keep one focused test per
production change this branch owns.
hdt98 added a commit to hdt98/sglang that referenced this pull request Sep 25, 2026
… next

Adopting sgl-project#39341 reassembled the chunked ragged MQA logits into one
[rows, keys] fp32 matrix before top-k. At AgentX long context that matrix
reaches several GiB per rank and exhausted HBM at c32 (HSA out of resources).
Restore the pre-overhaul structure: top-k consumes each capped block of rows
before the next block's logits are computed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants