Repository navigation
[AMD] [GLM-5.3-Flash Day 0] Write and read the k-pool index-K cache in AITER's preshuffle layout - #38544
[AMD] [GLM-5.3-Flash Day 0] Write and read the k-pool index-K cache in AITER's preshuffle layout#38544Raiden-Makoto wants to merge 6 commits into
Conversation
9ccbf64 to
4a0aa5e
Compare
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.
4a0aa5e to
846d708
Compare
|
Heads-up on one shape this path can hit. I've opened Raiden-Makoto#1 against |
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
|
Folded the long-context guard in from Raiden-Makoto#1 via rebase merge. The commit remains authored by Yikai Zhang ( |
kevin-mii
left a comment
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Closing this replacement because @Jacob0226 will reopen and maintain the original PR, #37685. Please continue review and CI there. |
|
Thanks @Raiden-Makoto. Reopening as #39341 rather than #37685: #37685's base branch |
Summary
Follow-up contribution Raiden-Makoto#1 bounds each ROCm AITER
fp8_mqa_logitscall below its strict 2-GiB fp32-output limit. Above that limit AITER takes an uncompilablegl.storefallback 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_pagedpicks between the tilelang paged-MQA kernel, whose selector returnsFalseoff 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.dsa_indexer_kpool.pyaiter_paged_mqa_logits(..., preshuffle=True), resolved throughDSAPagedMQALogitsBackendso--dsa-paged-mqa-logits-backendreaches this path instead of anis_hip()at the call site;resolve()already pins ROCm to AITER. It inserts thenext_ndim itself, soq_fp8stays[tokens, heads, dim]through the dispatch and the tilelang and DeepGEMM branches unsqueeze at their own call siteskpool_fp8_index.py_kpool_cache_k_offsets. The order follows_set_k_and_s_triton_kernelinindex_buf_accessor.py, which already lays out the non-pooled indexer cache for the same AITER kernel — the two have to agreeScope
The same PR now also changes
_fp8_mqa_logitsand extendstest_dsa_mqa_logits_chunking.py; this is part of the same k-pool AITER correctness boundary, not a separate runtime path.dsa_indexer_kpool.pyandkpool_fp8_index.py. CUDA keeps DeepGEMM and tilelang;DSAPagedMQALogitsBackend.resolve()cannot return AITER off ROCm, and_kpool_cache_k_offsetsreturns the current row-major expression wheneverPRESHUFFLE_TILEis 0, which is whataiter_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-backendand 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-integrationtested at9d0d62b744; current integration head4e2f84ff3c; TP8/TP4 validation predates the above-cap guard, whose below-cap path is unchanged, pinned AITERd9e5ef7ce0, 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 familypr-test-amd-rocm720.ymlresolves to, onxinyuan/glm-5.3-flash-support@491cb225fawith no other PRs applied.aiter_can_use_preshuffle_paged_mqa()isTruethere (Triton 3.7.0) and the tile is 16.test_kpool_preshuffled_cache_layout.pycol_tile_id * (tile * tile)mistyped ascol_tile_id * tile6511 != 8191distinct offsets, i.e. colliding writesBoth 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.
gather_index_k_scale_prefix_intospanning two pagestest_dsa_kpool_multi_pool.py3 passed,test_dsa_transform_index.py7 passedregister_amd_ci(suite="stage-b-test-1-gpu-small-amd-mi35x")pre-commitvalidate registered test CI registriesCI States
Latest PR Test (Base): ❌ Run #34768741185
Latest PR Test (Extra): ❌ Run #34768740936
Latest PR Test (AMD ROCm 10): ❌ Run #34768741042