Repository navigation
feat(gemm): GLM-5.2 MXFP4 bf16 projections at the speculative verify token counts - #212
Merged
Merged
Conversation
…token counts GLM-5.2 MXFP4 keeps its attention, indexer and router projections in bf16, and with EAGLE 5/1/6 the target verifies 6 tokens per request, so these GEMMs see 6, 12, ..., 96 rows (TP8 at 1-5 running requests, TP4 up to 16). The gemm route reaches all of them, but the committed workloads are powers of two only. New schemas, committed ones unchanged: - n2048 k2048 (TP8 q_b): the committed small-m FlyDSL kernel at 6-30 rows. - n6144 k2048 (TP8 o_proj): the committed Triton kernel at 6-30 rows. - n4096 k2048 (TP4 q_b, indexer wq_b): the committed FlyDSL kernel at 6-96 rows, with a configuration for 65-96 rows, whose 48-row halves have three 16-row fragments (the committed one asserts there). - n6144 k4096 (TP4 o_proj): the committed FlyDSL kernel at 6-96 rows. Its row split started the second half at the padded tile instead of m / 2, so rows of the first half past m / 2 were never written when m / 2 is not a multiple of 16 (34-48, 66-84); the copy starts it at m / 2. - n32 k6144 (indexer weights_proj): a Triton split-K kernel. The last workgroup of a column tile to arrive sums the fp32 partials in split order, so the result is bitwise reproducible. - n256 k6144 (router) at 6 rows and n2624 k6144 (fused q_a / kv_a) at 48-60 rows: committed kernels. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChengYao-amd
temporarily deployed
to
gpu-trusted
November 14, 2026 14:07 — with
GitHub Actions
Inactive
zhenhuang12
approved these changes
Nov 16, 2026
zhenhuang12
marked this pull request as ready for review
November 16, 2026 08:37
zhenhuang12
requested review from
RuibinCheung,
irvineoy,
jiejingzhangamd,
kyle-256 and
xiaobochen-amd
as code owners
November 16, 2026 08:37
There was a problem hiding this comment.
🟡 Changes recommended
Graph-captured invocations can read uninitialized counters or corrupt shared reduction scratch during concurrent replays, causing incorrect or unwritten outputs.
1 open issue
What changed in this PR
Adds seven [email protected] schemas so AKLR can accelerate GLM-5.2 MXFP4 bf16 projections at speculative-verification token counts instead of falling back.
Changes:
- Adds 62 workloads at selected multiples of six, leaving existing schemas unchanged.
- Reuses existing kernels with an additional larger-row configuration and a corrected row split.
- Introduces a fixed-order Triton split-K kernel for the narrow indexer projection.
| File | Description |
|---|---|
aklr/ops/gemm/impls/triton/gemm_n6144_k2048/0774cef6a82ceb70.json |
Covers TP8 output projections at 6–30 rows. |
aklr/ops/gemm/impls/triton/gemm_n32_k6144/65f19013d279858b.json |
Adds split-K indexer projections at 6–96 rows. |
aklr/ops/gemm/impls/triton/gemm_n2624_k6144/041f29d9ee169248.json |
Covers fused projections at 48, 54 and 60 rows. |
aklr/ops/gemm/impls/flydsl/gemm_n6144_k4096/02add52af772193d.json |
Covers TP4 output projections with corrected row splitting. |
aklr/ops/gemm/impls/flydsl/gemm_n4096_k2048/a18601ce69407734.json |
Covers query/indexer projections through 96 rows with an added configuration. |
aklr/ops/gemm/impls/flydsl/gemm_n256_k6144/9bc59fe90224c762.json |
Covers the router projection at six rows. |
aklr/ops/gemm/impls/flydsl/gemm_n2048_k2048/4d9208db05b89bab.json |
Covers TP8 query projections at 6–30 rows. |
Review effort: Max
| "sources": [ | ||
| { | ||
| "path": "kernel.py", | ||
| "content": "\"\"\"Narrow-n BF16 NT GEMM ``out = a @ b.T`` for k = 6144 and a few dozen rows (Triton, gfx950).\n\nThe weight is a few MB, so a column tiling alone leaves most CUs idle: K is split over SPLIT\nworkgroups per column tile. Each writes its fp32 partial through to memory and bumps the tile's\narrival counter; the last to arrive sums the partials in split order, stores bf16 and resets the\ncounter. The sum order is fixed, so the result is bitwise reproducible. Partials and counters are\nkept per device and stream.\"\"\"\n\nimport functools\n\nimport torch\nimport triton\nimport triton.language as tl\n\n\[email protected]\ndef _wait_stores(x):\n return tl.inline_asm_elementwise(\"s_waitcnt vmcnt(0)\", \"=r,r\", [x], dtype=tl.int32, is_pure=False, pack=1)\n\n\[email protected]\ndef _splitk_kernel(\n A,\n B,\n C,\n P,\n CNT,\n M,\n N: tl.constexpr,\n K: tl.constexpr,\n BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr,\n BLOCK_K: tl.constexpr,\n SPLIT: tl.constexpr,\n):\n pid_n = tl.program_id(0)\n pid_k = tl.program_id(1)\n pid_m = tl.program_id(2)\n KC: tl.constexpr = K // SPLIT\n offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n offs_k = pid_k * KC + tl.arange(0, BLOCK_K)\n row_ok = offs_m[:, None] < M\n a_ptrs = A + offs_m[:, None] * K + offs_k[None, :]\n b_ptrs = B + offs_n[None, :] * K + offs_k[:, None]\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for _ in tl.range(0, KC // BLOCK_K):\n a = tl.load(a_ptrs, mask=row_ok, other=0.0)\n b = tl.load(b_ptrs, cache_modifier=\".cg\")\n acc = tl.dot(a, b, acc=acc)\n a_ptrs += BLOCK_K\n b_ptrs += BLOCK_K\n if SPLIT == 1:\n tl.store(C + offs_m[:, None] * N + offs_n[None, :], acc.to(C.dtype.element_ty), mask=row_ok)\n else:\n tile_id = pid_m * tl.num_programs(0) + pid_n\n tile = tile_id * BLOCK_M * BLOCK_N\n loc = tl.arange(0, BLOCK_M)[:, None] * BLOCK_N + tl.arange(0, BLOCK_N)[None, :]\n stride = tl.num_programs(2) * N * BLOCK_M\n part = P + pid_k * stride + tile + loc\n tl.store(part, acc, cache_modifier=\".wt\")\n _wait_stores(pid_k)\n tl.debug_barrier()\n arrived = tl.atomic_add(CNT + tile_id, 1, sem=\"acq_rel\", scope=\"gpu\")\n if arrived == SPLIT - 1:\n tot = tl.load(P + tile + loc, cache_modifier=\".cv\")\n for s in tl.static_range(1, SPLIT):\n tot += tl.load(P + s * stride + tile + loc, cache_modifier=\".cv\")\n c_ptrs = C + offs_m[:, None] * N + offs_n[None, :]\n tl.store(c_ptrs, tot.to(C.dtype.element_ty), mask=row_ok)\n tl.atomic_xchg(CNT + tile_id, 0, sem=\"relaxed\", scope=\"gpu\")\n\n\n# (n, k) -> m upper bound -> (BLOCK_M, BLOCK_N, SPLIT, BLOCK_K, num_warps)\n_CONFIGS = {\n (32, 6144): {16: (16, 32, 24, 256, 4), 128: (16, 32, 12, 256, 2)},\n}\n_MAX_PART = 1 << 22 # fp32 partials per device and stream\n_MAX_TILES = 1024\n\n\[email protected]\ndef _workspace(device, stream):\n p = torch.empty(_MAX_PART, device=device, dtype=torch.float32)\n cnt = torch.zeros(_MAX_TILES, device=device, dtype=torch.int32)\n return p, cnt\n\n\ndef launch(a, b, out, cfg):\n m, k = a.shape\n n = b.shape[0]\n block_m, block_n, split, block_k, warps = cfg\n m_tiles = triton.cdiv(m, block_m)\n assert split * m_tiles * block_m * n <= _MAX_PART and m_tiles * (n // block_n) <= _MAX_TILES\n p, cnt = _workspace(a.device, torch.cuda.current_stream(a.device).cuda_stream)\n _splitk_kernel[(n // block_n, split, m_tiles)](\n a, b, out, p, cnt, m, N=n, K=k, BLOCK_M=block_m, BLOCK_N=block_n, BLOCK_K=block_k, SPLIT=split,\n num_warps=warps, num_stages=2,\n )\n\n\ndef run(*, a, b, trans_b, bias, out_dtype, out):\n m, k = a.shape\n n = b.shape[0]\n table = _CONFIGS.get((n, k))\n if not trans_b or bias is not None or table is None or m > max(table):\n torch.matmul(a, b.t() if trans_b else b, out=out)\n if bias is not None:\n out.add_(bias)\n return\n launch(a, b, out, table[min(x for x in table if m <= x)])\n" |
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.
zhenhuang12
added a commit
that referenced
this pull request
Nov 17, 2026
A schema file now carries `models`, right after `op_type`: the models whose serving calls it, sorted, each once, lowercase (`kimi-k3`, `deepseek-v4-pro`, `glm-5.2`). The file shows at a glance which models it is for. The uuid does not hash it, so no file moves; the schema_version stays 5. A file 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` takes `models`; a workload names none. `python -m aklr export` takes `--model`: a new file carries it, and a committed file the calls reach is listed with a note when its `models` lack it. All 705 committed schemas are labelled. A file takes the models named by the commits that added its workloads, 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. 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 files 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 files (qkv_dim 4608) also name qwen3-next, whose TP2 route falls through to that op (#78). #212's seven GEMM files are glm-5.2. The models are per file, not per workload: of the 705 files, one (fp8_paged_mqa_logits_page_size64_n_heads64) holds workloads of different models (deepseek-v4-flash alone, and with deepseek-v4-pro); it names both.
zhenhuang12
pushed a commit
that referenced
this pull request
Nov 18, 2026
* docs(kb): name the kernel files main holds now, after #168 and #220 renamed them #168 (kernel.requires) and #220 (aiter in kernel.requires) renamed every kernel file they touched without changing its code, so the case pages' sources: lines and their text named files main no longer has (kb_reconcile: 0 covered, 100 gone). Each gone file is replaced by the file in its directory whose kernel (entry point and sources) is byte-identical; where #212 added a second schema of the same kernel, by the one with the same workloads. The withdrawn 4ea93103 is left for a separate edit. * docs(kb): mark fused_moe 4ea93103 withdrawn #153 withdrew it (1.043 over aiter, under the 5% bar). Its sources: line goes, the Points table says so, and S8 pins the source to the revision before #153 so the citation still resolves. * docs(kb): GEMM: nt at K=512, bounded-wait fold, ring barrier, cached fold workspace - small_m.md §6: E134's nt cost at K=512 holds for that forge kernel only; #188's direct-to-LDS B stream at the same shape pays 1.66-1.69x with nt (E147). The shape does not decide the policy. - wait_free_fold.md: a waiting fold is safe with a bounded wait, hand-off on timeout and a per-call workspace, as #159's FOLD 4/5 (exact under contention, two streams and concurrent graphs). Cost and risk: a workspace cached per (device, stream), as in #212's Triton n32_k6144, is shared by every graph captured on that stream (wrong outputs). - datapath.md §4: a ring barrier before a DMA refill must also wait lgkmcnt(0); #110's n4096_k8192 races under contention without it. correctness.md and flydsl/gemm.md point there. * docs(kb): mHC 4096 Gram form without a clamp; aiter's stage 2 drops b_nt - cases/mhc_fused_post_pre.md: the hidden-4096 kernel returns NaN when the residual streams cancel; clamp the form at 0 like the hidden-7168 kernel. - moe/grouped_sorted_tokens.md §4, flydsl/moe.md §4: aiter's mixed stage-2 builder discards b_nt, so a _bnt2 row loads w2 cached; restoring it took #122's fused MoE from 256.8 to 217.5 us at 512 tokens. * docs(kb): pitfalls: degenerate Points, eager host time, in-place state - degenerate_points.md (new): Points whose inputs all take a kernel's fast path (#201's FlashMLA q8: every request 8 KV rows) score a speedup that realistic lengths reverse. attention/measurement.md §8 points there. - eager_call_host_time.md (new): the graph-replay speedup leaves out a @flyc.jit launcher's per-call host time; #134's top-k is 2.8-7.1x in replays and 0.18-0.68x of aiter called eagerly. - state_kept_across_calls.md: form 3, a kernel that skips unchanged state stores timed on state replayed in place (#75's GDN decode: 2.40x in place, 1.62x with fresh state). triton/gdn.md points there. * docs(kb): mHC case: the hidden-7168 HIP file #168 renamed, and #202's FlyDSL kernel beside it * docs(kb): evidence counts from the runs' logs; R2 at batch 4 and 8; aiter's top-k fails the reference at 16384
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 MXFP4 keeps its attention, indexer and router projections in bf16. With EAGLE 5/1/6 the target verifies 6 tokens per request, so at verify and draft extend these GEMMs see 6·bs rows: 6–30 at TP8 (1–5 running requests) and 6–96 at TP4 (up to 16). Both of the
[email protected]routes reach these calls (tgemm.mm, and aiter's Tritongemm_a16w16, which sglang calls for at most 64 rows when K ≤ 2048). The committed workloads cover only powers of two, so every verify call falls back. This PR adds schemas that serve those row counts.Scope
Seven new
[email protected]schemas. The committed ones are unchanged.flydsl/gemm_n2048_k2048/4d9208dbq_b_proj340a6d0c), unchangedtriton/gemm_n6144_k2048/0774cef6o_proj8307d207), unchangedflydsl/gemm_n4096_k2048/a18601ceq_b_proj, indexerwq_b(both TP)1e5f6ad3) plus one configuration for 65–96 rowsflydsl/gemm_n6144_k4096/02add52ao_projc735728b) with its row split fixedtriton/gemm_n32_k6144/65f19013weights_projflydsl/gemm_n256_k6144/9bc59fe95b35f66b), unchangedtriton/gemm_n2624_k6144/041f29d9q_a/kv_a7511d8bb), unchangedTILE_M) instead of atm / 2. Whenm / 2is not a multiple of 16, the rows of the first half pastm / 2are never written: 34–48 and 66–84 rows come out wrong. Its committed workloads (powers of two) are not affected. The copy here starts the second half atm / 2and masks the first half's store atm / 2.wk(n128 k6144) and the router above 6 rows: aiter's asm GEMM already runs these in about 5 µs, and neither the committed kernels nor a split-K kernel beat it.q_a/kv_aGEMM outside 48–60 rows.Tradeoffs
gemm_a16w16, not the tuned GEMM that is this op's baseline. A cold-cache microbench on the same image against that Triton path:Verification
Environment: CI run 43603051404 on this head:
validationpassed, 62/62 accurate, 1.06x – 1.96x (lower bound);unittest-aklrpassed. The tables and log below are a local run on MI355X,lmsysorg/sglang:v0.5.22-rocm10-mi35x, ROCm 7.15, torch 2.11.0+rocm10.0.0, Triton 3.8.0, FlyDSL 0.3.2, AITER asci.yaml'sAKLR_BASELINE_AITER. The run was on head37183081, which has the same seven files; the branch has since been rebased onto main91e0370e, whereexport check,validate --stages audit,test_contracts.pyand pre-commit pass again.Gate overrides: none
Kernels
[email protected](7 schemas)gemm_a16w16Validation log
Code
No code changes.
python -m aklr export check,python -m aklr validate --base origin/main --stages audit,pytest tests/ops/test_contracts.pyandpre-commit run --from-ref origin/main --to-ref HEADpass on the rebased head.Serving check (not end to end): GLM-5.2 MXFP4 (
amd/GLM-5.2-MXFP4) on MI355X with the InferenceX agentic recipe's server arguments (EAGLE 5/1/6, triton DSA, fp8 KV cache), acceptance not simulated, this PR's schemas with the speedups above (AKLR_MEASURED_DIR),AKLR_EXPORT=1:TP4/EP4 with HiCache (
--cuda-graph-max-bs-decode 32):[email protected]served n32 k6144, n4096 k2048 and n6144 k4096 at every verify row count captured up to 96 (6–48, 60, 72, 84, 96; batch sizes 9, 11, 13 and 15 are padded to the next graph), plus n256 k6144 at 6 and n2624 k6144 at 48 and 60.TP8/EP1 (
--cuda-graph-max-bs-decode 8): n2048 k2048 and n6144 k2048 served at 6–30; n4096 k2048 and n32 k6144 at 6–48; n256 k6144 at 6; n2624 k6144 at 48, 54 and 60.GSM8K (400 questions, zero-shot chat, thinking off):
Not run
Risk
Affects: bf16 GEMMs of these seven (n, k) shapes at the listed row counts: GLM-5.2 MXFP4's attention, indexer and router projections at verify and draft extend. Any other model with the same shapes at those row counts also gets the new schemas.
If wrong: wrong projection output, or slower verify steps at those row counts.
Undo:
[email protected](this turns off everygemmschema), orgit revert.🤖 Generated with Claude Code