Skip to content

[AMD] [GLM-5.3-Flash Day 0] Write and read the k-pool index-K cache in AITER's preshuffle layout - #38544

Closed
Raiden-Makoto wants to merge 6 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/reopen-37685
Closed

Raiden-Makoto wants to merge 6 commits into
sgl-project:mainfrom
Raiden-Makoto:RM/reopen-37685

Conversation

@Raiden-Makoto

@Raiden-Makoto Raiden-Makoto commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up contribution Raiden-Makoto#1 bounds each ROCm AITER fp8_mqa_logits call below its strict 2-GiB fp32-output limit. Above that limit AITER takes an uncompilable gl.store fallback and aborts every TP rank; the exact row split keeps the existing one-call path unchanged below the cap and supports contexts above roughly 262K tokens. The contributor commit remains authored by Yikai Zhang (Arist12); its original Claude coauthor trailer is preserved.

Replacement for #37685, which GitHub closed when its deleted support base was merged into main. The original author and review history remain credited there.

The k-pool DSA indexer has no ROCm path at all. _get_topk_paged picks between the tilelang paged-MQA kernel, whose selector returns False off CUDA, and DeepGEMM, which does not exist on ROCm — so GLM-5.3-Flash falls through to a CUDA-only kernel. This routes it to AITER and lays the cache out the way AITER reads it.

Side Change
read, dsa_indexer_kpool.py dispatch to aiter_paged_mqa_logits(..., preshuffle=True), resolved through DSAPagedMQALogitsBackend so --dsa-paged-mqa-logits-backend reaches this path instead of an is_hip() at the call site; resolve() already pins ROCm to AITER. It 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
write, kpool_fp8_index.py AITER reads the index-K rows in 16x16 tile order, so the four write kernels and the one read kernel now share _kpool_cache_k_offsets. The order follows _set_k_and_s_triton_kernel in index_buf_accessor.py, which already lays out the non-pooled indexer cache for the same AITER kernel — the two have to agree

Scope

The same PR now also changes _fp8_mqa_logits and extends test_dsa_mqa_logits_chunking.py; this is part of the same k-pool AITER correctness boundary, not a separate runtime path.

dsa_indexer_kpool.py and kpool_fp8_index.py. CUDA keeps DeepGEMM and tilelang; DSAPagedMQALogitsBackend.resolve() cannot return AITER off ROCm, and _kpool_cache_k_offsets returns the current row-major expression whenever PRESHUFFLE_TILE is 0, which is what aiter_can_use_preshuffle_paged_mqa() reports on every non-ROCm build. No new environment variable and no architecture gate — the existing --dsa-paged-mqa-logits-backend and the AITER capability probe decide.

Write and read must move together: with only one side converted the buffer is misread rather than rejected, so this is one PR.

Test plan

Merged contribution validation: scoped pre-commit passed; all 5 chunking tests, 3 preshuffle-layout tests, 3 multi-pool regressions, and 9 transform-index regressions pass. Contributor E2E evidence covers 150K unchanged output plus successful 300K and 600K cold prefills; the 300K case previously aborted all eight ranks. See ROCm/aiter#5114.

Combined main-based integration (RM/glm53-day0-main-integration tested at 9d0d62b744; current integration head 4e2f84ff3c; TP8/TP4 validation predates the above-cap guard, whose below-cap path is unchanged, pinned AITER d9e5ef7ce0, fresh caches): TP8 GSM8K 97.50% in 87.0s with 0.00% errors; TP4 GSM8K 96.97% in 320.2s with 0.00% errors. Decode CUDA graphs were enabled in both runs.

Recovery base: main @ 30e7a3072d.
Recovery validation on MI355X: scoped pre-commit passed; 3 layout, 3 multi-pool, and 9 transform regressions passed.

rocm/sgl-dev:v0.5.18-rocm720-mi35x-20260901, the image family pr-test-amd-rocm720.yml resolves to, on xinyuan/glm-5.3-flash-support @ 491cb225fa with no other PRs applied. aiter_can_use_preshuffle_paged_mqa() is True there (Triton 3.7.0) and the tile is 16.

Variant test_kpool_preshuffled_cache_layout.py
Reader left row-major, writer preshuffled 1 error — the round trip catches it
col_tile_id * (tile * tile) mistyped as col_tile_id * tile 3 failed — including 6511 != 8191 distinct offsets, i.e. colliding writes
This PR 3 passed on gfx950

Both negative cases matter because neither failure raises in production: the first misreads the cache, the second overwrites parts of it, and both surface only as a wrong top-k.

Check Detail
Coverage offsets against an independent reference for tile 0 and 16; a collision check over the whole K region; a round trip through gather_index_k_scale_prefix_into spanning two pages
Regression test_dsa_kpool_multi_pool.py 3 passed, test_dsa_transform_index.py 7 passed
Registration register_amd_ci(suite="stage-b-test-1-gpu-small-amd-mi35x")
pre-commit all hooks pass on all three files, including validate registered test CI registries
Accuracy not measured — GLM-5.3-Flash still cannot be served on ROCm from this branch; GSM8K lands once the remaining enablement is in

CI States

Latest PR Test (Base): ❌ Run #34768741185
Latest PR Test (Extra): ❌ Run #34768740936
Latest PR Test (AMD ROCm 10): ❌ Run #34768741042

Jacob0226 and others added 2 commits September 8, 2026 12:41
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.

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

Arist12 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Heads-up on one shape this path can hit. IndexerKPool._fp8_mqa_logits hands AITER the whole [num_q x num_k] fp32 logits, and above 2 GiB that kernel takes a gl.store fallback that fails to compile — the LLVM assertion abort()s the process rather than raising, so every TP rank dies at once (ROCm/aiter#5114; the same limit #36960 bounded for Indexer, details in #37478). It is reachable with a single request: the ragged k-pool logits are [chunk_tokens x seq_len/index_kpool], so at index_kpool = 4 and --chunked-prefill-size 8192 the cap falls at roughly 262k tokens of context. On 8x MI355X on this branch, a 150,010-token prompt is fine and a 300,010-token one takes all 8 ranks down.

I've opened Raiden-Makoto#1 against RM/reopen-37685 so it can go in with this PR: it splits the query rows so each AITER call stays under the cap, which is exact here (bit-identical to the unsplit call, and the 300k-token prompt returns with it). Happy to hand the hunk over for you to fold into your own commits instead, if that is simpler.

@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Sep 9, 2026
1am9trash and others added 3 commits September 9, 2026 08:24
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. Split the query rows so
each call stays under the cap.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
# Conflicts:
#	python/sglang/srt/layers/attention/dsa/dsa_indexer_kpool.py
@Raiden-Makoto

Copy link
Copy Markdown
Contributor Author

Folded the long-context guard in from Raiden-Makoto#1 via rebase merge. The commit remains authored by Yikai Zhang (Arist12), with the contributor-provided Claude coauthor trailer preserved. Re-resolved against current main; scoped pre-commit passes, along with 5 chunking tests, 3 preshuffle-layout tests, 3 multi-pool regressions, and 9 transform-index regressions. The clean integration branch is updated at 4e2f84ff3c.

@kevin-mii kevin-mii 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.

Validated this on 8x MI350X (gfx950, lmsysorg/sglang-rocm:v0.5.19-rocm720-mi35x-20260910, aiter 4ad998328): the 4 test files pass on the PR head and on the PR merged onto current main; an independent write-with-_kpool_cache_k_offsets / read-with-aiter_paged_mqa_logits(preshuffle=True) round trip matches a torch reference (rel err 2e-5, row-major control 3.3); the ragged wrapper's forced split is bit-identical to the unsplit call; raw aiter fp8_mqa_logits still abort()s at 2.29 GB on this image so the guard is needed; and on the integration stack GLM-5.3-Flash TP4 passes needle retrieval up to 56k tokens plus 144k/288k-token prefills, GSM8K (run_eval, 1319) = 0.970. One placement nit inline.

from sglang.test.ci.ci_register import register_amd_ci
from sglang.test.test_utils import CustomTestCase

register_amd_ci(est_time=60, suite="stage-b-test-1-gpu-small-amd-mi35x")

@kevin-mii kevin-mii Sep 11, 2026 •

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.

nit: this test launches no server, only Triton kernels, so per the placement table in test/registered/README.md ("CUDA kernel correctness -> kernels/"; the e2e/ tree is for tests that launch a server/engine) it belongs under kernels/, e.g. next to kernels/ops/attention/test_dsa_transform_index.py which this PR already extends.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed semantically. The current registry checker conflicts with that README guidance for this AMD-only test: a newly added test/registered/kernels/... path is rejected because kernels is not in _TEST_KINDS, while test/registered/kernel/... is rejected because the MI35x AMD suite is not a *-kernel-* suite. e2e/attention is therefore the only currently dispatchable location for stage-b-test-1-gpu-small-amd-mi35x. Happy to move it once the taxonomy exposes an AMD kernel suite or the checker permits the documented kernels/ path.

@Raiden-Makoto

Copy link
Copy Markdown
Contributor Author

Closing this replacement because @Jacob0226 will reopen and maintain the original PR, #37685. Please continue review and CI there.

@Jacob0226

Copy link
Copy Markdown
Contributor

Thanks @Raiden-Makoto. Reopening as #39341 rather than #37685: #37685's base branch xinyuan/glm-5.3-flash-support has been deleted, so GitHub will not let it reopen. #39341 is off main and its changed files are byte-identical to this PR's head. @Arist12's 2-GiB MQA-logits bound is carried across with its authorship and its original coauthor trailer.

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