Skip to content

[FlyDSL] GLM-5 fused decode-layer MonoKernel - #7

Closed
amd-sriram wants to merge 5 commits into
mainfrom
glm5-mono-decode
Closed

amd-sriram wants to merge 5 commits into
mainfrom
glm5-mono-decode

Conversation

@amd-sriram

@amd-sriram amd-sriram commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the GLM-5 fused decode-layer MonoKernel to AITER so engines other than ATOM can use it. Device code is from ROCm/FlyDSL#1204 (@coderfeli); the host wrapper and the TP4, FP8-KV and native-FP4 paths are from ROCm/ATOM#2435 (@XiaobingSuper), at ATOM bdc157af. The kernel sources are carried over unchanged apart from their import paths.

One launch per MoE layer and rank covers input RMSNorm, the MLA projections, RoPE and KV-cache insert, sparse attention over precomputed indices, o_proj with an in-kernel all-reduce, the router, and the MXFP4 experts with an in-kernel all-reduce.

File What
aiter/ops/flydsl/kernels/glm5_mono/ Kernel, layouts, packing, IPC peer buffer, weight contracts
aiter/ops/flydsl/glm5_mono.py Public API plus glm5_mono_launch_rows()
op_tests/multigpu_tests/test_flydsl_glm5_mono.py 4-GPU runtime checks

glm5_mono_launch_rows() pads a one-row decode step to two rows, because a one-row launch never completes on gfx950 (seen at TP4 with both FP4 MFMA modes).

Storage contract (what a caller must provide)

Input Contract
Attention Block-FP8 (128x128) or per-channel FP8, repacked by prepare_glm5_weights
Experts AITER-shuffled MXFP4 (shuffle_weight(layout=(16, 16)) + e8m0_shuffle), shared expert fused as the last physical expert
KV cache FP8, one 576-byte row per global slot, no scale
Per row positions int64, slot_mapping int64 (pad rows -1), CSR sparse_kv_indptr int32 and global sparse indices

Tests

MI355X (gfx950), TP4, op_tests/multigpu_tests/test_flydsl_glm5_mono.py, 4 layers in one HIP graph:

Case Result
1 row (launched as 2) finite, real row unchanged when the pad row changes
2, 4, 8 rows finite, bit-identical across replays
16 rows (two 8-row chunks) finite, bit-identical across replays
2 real + 2 pad rows (slot -1, empty sparse range) finite, real rows unchanged when pad rows change

Per-layer latency, TP4, 75 layers with distinct random weights in one graph, block-FP8 attention: 65.8 us (2 rows), 84.8 us (4 rows), 144.7 us (8 rows). Per-channel FP8 attention: 64.9, 92.4, 157.5 us.

Fused indexer on a vLLM paged index cache (opt-in)

Glm5MonoKernel(..., with_indexer=True, index_paged=True, ...) runs the sparse indexer inside the launch:

  • Index keys live in vLLM's paged FP8 cache: E4M3 values (plain or 16x16-shuffled) plus one power-of-two scale per token.
  • Each row is its own request. The row's block_table entry locates its keys, and the new key is quantized with vLLM's ue8m0 rule.
  • The exact top-2048 is published as global slots to out_indices at the row's sparse_kv_indptr offset, so later layers can reuse them.
  • No LDS context limit: radix keys past the LDS capacity are re-read from the score mailbox.
  • index_k_bf16=True reads a bf16 index-K projection.
  • Kernels without the indexer only gain three unused pointer arguments.

Also fixes the original fused indexer: the picks are now stored to LDS (TP8 memory fault), and the TP4 q_b split passes the layout check.

op_tests/multigpu_tests/test_flydsl_glm5_mono_paged_indexer.py, MI355X, TP4 and TP8, all cases pass:

Case Contexts
4 rows, shuffled 1000, 8192, 30000, 70001
4 rows, plain layout 5, 2047, 2049, 120000
3 rows + 1 pad row 3000, 65536, 100
8 rows 1000 ... 200000
2 rows / 1 row + 1 pad row 8192, 60000 / 40000

Per case: new-key bytes and scale equal the ue8m0 reference, picks match a PyTorch top-2048 (overlap 1.0, one row 0.9995), and the layer output is bit-identical to the external-indices launch fed the same slots.

Top-k selection: one pass builds a 4096-bin histogram of the score keys; a second pass publishes every key above the threshold bin and moves the bin's keys into LDS, where the remaining radix digits and the tie gather run. A full radix over all keys is the fallback when the bin does not fit. The test also covers clustered keys and heavy ties.

Extra time per layer for the in-kernel indexer (75 layers, 2 / 4 / 8 rows): TP4 8K +26 / +38 / +57 us, 60K +82 / +109 / +169 us; TP8 8K +29 / +37 / +48 us, 60K +85 / +106 / +159 us.

End-to-end results in vLLM (TP8)

Served through amd-sriram/vllm#27, which uses the fused indexer on every indexer layer.

8x MI355X, amd/GLM-5.3-Quark-MXFP4-AttnFP8, TP=8, fp8 KV. Random dataset (random-range-ratio 0.8), 8192/1024 at concurrency 4 to 256 and 60000/600 at 4 to 32.

Run Fused decode vLLM AITER
Baseline VLLM_ROCM_GLM_MONO_DECODE=0 ac68c308 + vllm-project/vllm#50535, #51309, #51314, #59280, #59420, #59421, #59422, amd-sriram/vllm#17, #18, ROCm#27 7bfe279d + #7
Fused VLLM_ROCM_GLM_MONO_DECODE=1 same 5b2f7d1d + #7 + #10

The two builds use different AITER commits. TTFT and every point at concurrency 16 and above, where the fused path is off, agree within 0.7%, so the decode gains come from the fused path.

ISL/OSL Concurrency TPOT baseline TPOT fused TPOT change Output tok/s/GPU baseline Output tok/s/GPU fused Throughput change
8192/1024 4 13.10 ms 7.74 ms -40.9% 36.67 61.02 +66.4%
8192/1024 8 15.05 ms 10.92 ms -27.4% 62.31 85.72 +37.6%
8192/1024 16 (path off) 17.89 ms 17.84 ms -0.3% 105.16 106.11 +0.9%
60000/600 4 24.59 ms 20.07 ms -18.4% 16.62 19.62 +18.1%
60000/600 8 36.41 ms 33.46 ms -8.1% 23.13 24.88 +7.6%
60000/600 16 (path off) 62.53 ms 62.51 ms 0.0% 27.22 27.34 +0.4%

Geomean over the whole sweep: 8192/1024 TPOT -11.7%, output throughput +13.2%, TTFT +0.0%; 60000/600 TPOT -7.0%, output throughput +6.4%, TTFT -0.4%.

Eval Baseline Fused
NIAH niah_single_2, 64K (lm_eval) 1.000 1.000
GPQA Diamond, thinking on, temperature 1 (198 questions) 0.879 0.899

GPQA runs at temperature 1, so one question is 0.5 points.

Dense-MLP layers (dense_experts)

GLM-5's leading dense layers have a 12288-wide MLP, six times the expert width, so the kernel can run them too:

  • pack_dense_mlp(gate_up, gate_up_scale, down, down_scale, slices) stores a row-major MXFP4 dense MLP as slices expert-shaped slices in the ATOM expert layout (same shuffle_weight / e8m0_shuffle as MoE experts). Slice j holds intermediates j * I / slices onward, so the sum over slices is the dense MLP exactly.
  • Glm5MonoKernel(..., dense_experts=N) routes every row to slices 0..N-1 with weight 1 and skips the router GEMV; the router stage still produces the activation blocks the experts read. Spare slots have weight 0. It is a build-time option, so MoE layers compile as before.

op_tests/multigpu_tests/test_flydsl_glm5_mono_dense.py, MI355X, TP4 (TP8 not run yet):

Rows Finite, replay bit-identical Rel. error vs float32 MLP Rel. error vs reference with the kernel's MXFP8 and BF16 roundings
2 yes 0.047 0.0006
4 yes 0.046 0.0012
8 yes 0.046 0.0009

After this change test_flydsl_glm5_mono.py (1/2/4/8 rows and pad rows) and test_flydsl_glm5_mono_paged_indexer.py still pass at TP4. In vLLM (amd-sriram/vllm#27), all 78 GLM-5.3 layers in the kernel give TPOT -6.1% at concurrency 1 and -2.9% at 4 (TP4, 8K), with NIAH 15/15 and GSM8K 0.904.

Port of the GLM-5 MonoKernel from ROCm/ATOM#2435 (device code from
ROCm/FlyDSL#1204), with a host API and a 4-GPU op test.
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40797bde-eb76-43a0-ae5a-bf20378dd849
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the FlyDSL label Oct 4, 2026
build added 3 commits October 5, 2026 12:47
Per-row requests via block table, ue8m0 key insert, top-2048 published as global slots; no LDS context limit.
12-bit histogram, then winners and threshold-bin candidates in LDS; full radix only on overflow. Test covers clustered and tied keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant