Repository navigation
feat(plugins): GLM-5.2 DSA sparse MLA prefill: op, route and MI355X kernels - #83
Merged
Merged
Conversation
Add [email protected] to layers/dsa_backend: the sparse MLA that DeepseekSparseAttnBackend.forward_extend runs through triton_sparse_mla_fwd on HIP, with its reference, baseline and route. - The route hooks triton_sparse_mla_fwd and takes only new sequences' tokens (no cached prefix, read from the backend's host lengths): a new sequence's first topk tokens name fewer than topk slots, where kernels can skip the -1s. Speculative decoding, sglang's short-sequence path (max_topk_length <= 512) and stream capture stay on sglang. - aklr/core: a causal_topk distribution draws the top-k slots of one new sequence as sglang's indexer hands them over (rows short of topk name all their positions in order, then -1; full rows change by about one slot per token); its domain is any distinct slots and any number of -1s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on MI355X Five Gluon schemas of [email protected] for GLM-5.2's absorbed MLA prefill (kv_dim 576, top-k 2048, fp8 q and KV): 8 heads (TP8) and 16 heads (TP4), n_tokens 3072-16384 of a new sequence, the KV pool at serving size (1835008 rows). - The kernels skip a row's -1 slots, which a new sequence's first 2048 tokens hold, and read sglang's fp8 q directly, converting it to bf16 as they load it. - The TP4 5120-16384 kernel reads the pool in place instead of repacking all of it on every call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
had a problem deploying
to
gpu-trusted
November 6, 2026 07:05 — with
GitHub Actions
Failure
ChengYao-amd
had a problem deploying
to
gpu-trusted
November 6, 2026 07:27 — with
GitHub Actions
Failure
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
had a problem deploying
to
gpu-trusted
November 6, 2026 07:56 — with
GitHub Actions
Failure
ChengYao-amd
marked this pull request as ready for review
November 6, 2026 08:35
ChengYao-amd
requested review from
RuibinCheung,
irvineoy,
jiejingzhangamd,
kyle-256,
xiaobochen-amd and
zhenhuang12
as code owners
November 6, 2026 08:35
…refill Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 9, 2026 07:35 — with
GitHub Actions
Inactive
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 10, 2026 08:45 — with
GitHub Actions
Inactive
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 10, 2026 11:24 — with
GitHub Actions
Inactive
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 10, 2026 11:45 — with
GitHub Actions
Inactive
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 11, 2026 01:50 — with
GitHub Actions
Inactive
zhenhuang12
added a commit
that referenced
this pull request
Nov 16, 2026
…ts call A schema's workload now carries `models`: the models whose serving makes that very call, sorted, each once, lowercase (`kimi-k3`, `deepseek-v4-pro`, `glm-5.2`). The file's `models`, right after `op_type`, is their union, written by `schema_text` and so checked on parse: the file shows at a glance which models it is for, and each workload which of them calls it. The uuid hashes neither, so no file moves; the schema_version stays 5. A workload without `models` still parses (a base from before this change is read as it is), and `schema_errors` refuses it (E10), so `export check` and audit require it of every committed and changed file. `OpContract.narrow` keeps its signature; `workload_for` takes the models. `python -m aklr export` takes `--model`: a new file's workloads carry it, and a committed file the calls reach is listed with the called workloads that do not name it. All 698 committed schemas (4606 workloads) are labelled. A workload takes the model named by the commit that added it, in AKLR or, for AKLR's initial commit, in SIKL (whose main is that commit); a kernel added later at an existing Point takes the Point's models. Where one scenario holds workloads of several commits, they are told apart: - flash_mla sparse decode and fp8_paged_mqa_logits (64 heads): SIKL #71's are deepseek-v4-flash, SIKL #83's deepseek-v4-pro; the three 262144-row ones of #96 ("DSV4") name both. - deepseek_v2_fp8_moe at model_dim 6144: #46's are glm-5.2, #124's and #181's glm-5.3. - gemm_n7168_k512: #159's multiples of 7 (DSPARK's draft) are kimi-k3. Workloads from SIKL #52, which gave the pre-existing definitions their default sweep, take the model of the commit that added the definition: SIKL #50 (DeepSeek-V4-Flash's schema set), #35 and #47 (Kimi-K3). The definitions of SIKL #18 and #36 name no model and are labelled by their shapes, as the owner reviewed: hidden-6144 GEMMs and MoE as glm-5.2, gemm_a8w8_blockwise_scaled_n3072_k1536 as deepseek-r1, gemm_n7168_k512's sweep as glm-5.2 and kimi-k3, the hidden-6144 norms as glm-5.2 and glm-5.3. By the owner's choice, DeepSeek-R1's workloads also name deepseek-v3, the DSA indexer ones name glm-5.2 and glm-5.3, and gemm_n4096_k2048 and gemm_n512_k4096 also name qwen3.5. The Qwen3.5 gated-attention decode workloads (qkv_dim 4608) also name qwen3-next, whose TP2 route falls through to that op (#78).
zhenhuang12
added a commit
that referenced
this pull request
Nov 17, 2026
…ts call A schema's workload now carries `models`: the models whose serving makes that very call, sorted, each once, lowercase (`kimi-k3`, `deepseek-v4-pro`, `glm-5.2`). The file's `models`, right after `op_type`, is their union, written by `schema_text` and so checked on parse: the file shows at a glance which models it is for, and each workload which of them calls it. The uuid hashes neither, so no file moves; the schema_version stays 5. A workload without `models` still parses (a base from before this change is read as it is), and `schema_errors` refuses it (E10), so `export check` and audit require it of every committed and changed file. `OpContract.narrow` keeps its signature; `workload_for` takes the models. `python -m aklr export` takes `--model`: a new file's workloads carry it, and a committed file the calls reach is listed with the called workloads that do not name it. All 705 committed schemas (4668 workloads) are labelled. A workload takes the model named by the commit that added it, in AKLR or, for AKLR's initial commit, in SIKL (whose main is that commit); a kernel added later at an existing Point takes the Point's models. Where one scenario holds workloads of several commits, they are told apart: - flash_mla sparse decode and fp8_paged_mqa_logits (64 heads): SIKL #71's are deepseek-v4-flash, SIKL #83's deepseek-v4-pro; the three 262144-row ones of #96 ("DSV4") name both. - deepseek_v2_fp8_moe at model_dim 6144: #46's are glm-5.2, #124's and #181's glm-5.3. - gemm_n7168_k512: #159's multiples of 7 (DSPARK's draft) are kimi-k3. Workloads from SIKL #52, which gave the pre-existing definitions their default sweep, take the model of the commit that added the definition: SIKL #50 (DeepSeek-V4-Flash's schema set), #35 and #47 (Kimi-K3). The definitions of SIKL #18 and #36 name no model and are labelled by their shapes, as the owner reviewed: hidden-6144 GEMMs and MoE as glm-5.2, gemm_a8w8_blockwise_scaled_n3072_k1536 as deepseek-r1, gemm_n7168_k512's sweep as glm-5.2 and kimi-k3, the hidden-6144 norms as glm-5.2 and glm-5.3. By the owner's choice, DeepSeek-R1's workloads also name deepseek-v3, the DSA indexer ones name glm-5.2 and glm-5.3, and gemm_n4096_k2048 and gemm_n512_k4096 also name qwen3.5. The Qwen3.5 gated-attention decode workloads (qkv_dim 4608) also name qwen3-next, whose TP2 route falls through to that op (#78). Rebased onto main at #235: the files main rewrote (#169, #197, #217) keep their Points' models under the new uuids and paths, and #212's seven GEMM files, at Points new to the tree, are glm-5.2.
kyle-256
approved these changes
Nov 17, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
GLM-5.2's DSA prefill on HIP runs
triton_sparse_mla_fwdfromDeepseekSparseAttnBackend.forward_extend, and no AKLR op covers it. A new sequence's token i < 2048 names only i + 1 of its 2048 top-k slots; the rest are -1. This PR adds:triton_sparse_mla_fwd, and 7–12% faster in TTFT end to end.Scope
Op
[email protected]inplugins/sglang/layers/dsa_backend:[email protected]: fp8 q[n_tokens, n_heads, kv_dim], fp8 KV pool, int32 top-k with -1 for none, bf16 output, SqnrBound 20 dB;triton_sparse_mla_fwdasforward_extendcalls it.Route on
sglang.kernels.ops.attention.dsa.triton_sparse_mla.triton_sparse_mla_fwd, whichforward_extendimports at each call. It takes a call only when:seq_lens_sum == sum(dsa_extend_seq_lens_list)on the backend's host metadata, so no device sync;topk_lengthis None andmax_topk_lengthis None or > 512, so sglang's own short-sequence path stays.Calls during stream capture stay on sglang. So do tokens after a cached prefix (later chunks of a chunked prefill, radix hits): every row is full there, and skipping -1s gains nothing.
aklr/core:CausalTopkDistribution(causal_topk):magnified_inputsskips it likeint_range.Kernels: Gluon schemas for kv_dim 576, top-k 2048, fp8 q and KV, n_slots 1835008. n_slots is the pool of
--kv-cache-dtype fp8_e4m3 --max-total-tokens 1835008; it must stay below the kernels' 2 GiB addressing.Not covered:
Tradeoffs
triton_sparse_mla_fwd, notforward_extend(about 370 lines over many backends). The prefix check readsget_attn_backend().forward_metadata, as the qwen3_5 route does.Verification
Environment: head
02ee530(main merged in; kernels and validation on275b7d1, full pytest on2e6a1d7), MI355X,lmsysorg/sglang:v0.5.22-rocm10-mi35x(ROCm 7.15, torch 2.11.0+rocm10.0.0, Triton 3.8.0, AITERdbd8bf5)Gate overrides: none
Contracts
Workloads come from GLM-5.2-MXFP4 on sglang 0.5.22, TP8,
--kv-cache-dtype fp8_e4m3:[M, 8, 576]fp8 buffer,indicesis[M, 1, 2048]int32, andmax_topk_lengthis 2048.SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD).Kernels
[email protected](8 heads)dsa_sparse_mla_prefill_baseline(sglangtriton_sparse_mla_fwd)[email protected](16 heads)Accuracy, by how many slots a row holds: the inputs of 6 layers (0, 3, 20, 40, 60, 77) were dumped from real GLM-5.2 prefills of 4096 / 8192 / 16384 tokens. Below is the SQNR against fp32, min–max over layers and lengths.
triton_sparse_mla_fwd(dB)Validation log
End to end
GLM-5.2-MXFP4, sglang 0.5.22,
--kv-cache-dtype fp8_e4m3 --max-total-tokens 1835008. TTFT is the median of 10 single requests of random tokens (new sequences), in ms.AKLR_SGLANG_PLUGIN=1and[email protected], so AKLR's other ops stay on.AKLR_DISABLE.AKLR_EXPORTcall records: at TP8 and TP4, n_tokens 4096 / 8192 / 16384 are served in every layer; other lengths recordno_workload.ISL ≤ 2048 runs sglang's dense attention and is the control.
Correctness: chat prompts of exactly 4096 / 8192 / 16384 tokens (a number stated first, asked for last).
Code
pytest testson2e6a1d7, in the CI image: 745 passed, 123 skipped. After merging main (02ee530):export checkand the audit against main pass; without a GPU,tests/core/contract,tests/ops/test_contracts.pyandtests/pluginsfail only where main's do (routes whose targets need a GPU at import).tests/core/contract/test_causal_topk.py: row counts and order, slow change of full rows, domain, same-seed repeatability, a sequence longer than the pool;tests/plugins/sglang/cases.py(n_tokens 96 > top-k 64, so it draws both kinds of row);names.txtregenerated.aklr/corechanges:causal_topkis new and only this op uses it;magnified_inputsskipping it changes no committed schema.Not run
validationjob validates every schema, sinceaklr/corechanges).Risk
Affects: GLM-5.2 TP4 / TP8 prefill of new sequences on MI355X with an fp8 KV cache, at the listed n_tokens.
aklr/coregains a distribution kind.If wrong: a wrong attention output in those prefills, or a crash in the route.
Undo:
[email protected]; otherwisegit revert.🤖 Generated with Claude Code