Repository navigation
[FlyDSL] GLM-5 fused decode-layer MonoKernel - #7
amd-sriram wants to merge 5 commits into
Conversation
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.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
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.
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.
aiter/ops/flydsl/kernels/glm5_mono/aiter/ops/flydsl/glm5_mono.pyglm5_mono_launch_rows()op_tests/multigpu_tests/test_flydsl_glm5_mono.pyglm5_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)
prepare_glm5_weightsshuffle_weight(layout=(16, 16))+e8m0_shuffle), shared expert fused as the last physical expertpositionsint64,slot_mappingint64 (pad rows -1), CSRsparse_kv_indptrint32 and global sparse indicesTests
MI355X (gfx950), TP4,
op_tests/multigpu_tests/test_flydsl_glm5_mono.py, 4 layers in one HIP graph: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:block_tableentry locates its keys, and the new key is quantized with vLLM's ue8m0 rule.out_indicesat the row'ssparse_kv_indptroffset, so later layers can reuse them.index_k_bf16=Truereads a bf16 index-K projection.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: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-ratio0.8), 8192/1024 at concurrency 4 to 256 and 60000/600 at 4 to 32.VLLM_ROCM_GLM_MONO_DECODE=0ac68c308+ vllm-project/vllm#50535, #51309, #51314, #59280, #59420, #59421, #59422, amd-sriram/vllm#17, #18, ROCm#277bfe279d+ #7VLLM_ROCM_GLM_MONO_DECODE=15b2f7d1d+ #7 + #10The 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.
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%.
niah_single_2, 64K (lm_eval)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 asslicesexpert-shaped slices in the ATOM expert layout (sameshuffle_weight/e8m0_shuffleas MoE experts). Slice j holds intermediatesj * I / slicesonward, 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):After this change
test_flydsl_glm5_mono.py(1/2/4/8 rows and pad rows) andtest_flydsl_glm5_mono_paged_indexer.pystill 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.