Skip to content

[FlyDSL] [Perf] split-3 reduce + norm / RoPE + NVFP4 insert, QKV chain for 65-128 decode rows (TP4, -0.4..-0.5 ms/step in-step) - #8611

Closed
ganyi1996ppo wants to merge 9 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/qkv-chain-split-insert
Closed

ganyi1996ppo wants to merge 9 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/qkv-chain-split-insert

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Stacked on #8606, #8607 and the split-3 GEMM PR (this PR's own commit is the last one, +611 lines). The split-3 reduce + q/k/index RMSNorm + partial RoPE + NVFP4 K/V/index-K insert for the MiniMax-M3.1 TP4 QKV chain at 65-128 rows: sums the three fp32 slabs in the reduce's order, rounds to bf16 exactly as the unfused chain, then runs the norm / RoPE / insert arithmetic unchanged, one launch, with V workgroups that sum, quantize and pack runs through LDS (halo rows included). qkv_chain.py gets qkv_chain_insert (17-128 row dispatcher: the one-launch chain up to 64, split GEMM + reduce-insert above), code_rows and supported_split. Technique from amd-kernels' reduce_insert.py (attention/mxfp8_qkv_norm_rope_nvfp4_insert...), ported to aiter's insert helpers, no import.

Measured (graph replay, 8 rotated weights, us per layer of the whole sequence quant + GEMM + norm/RoPE/insert, MI355X, one GPU)

rows this PR amd-kernels entry public (quant + gemm_a8w8_blockscale + fused_qknorm insert) delta vs public
65 14.12 13.73 16.92 -2.8
72 13.92 13.93 17.35 -3.4
80 14.08 14.09 17.02 -2.9
81 14.59 14.40 17.05 -2.5
96 14.78 14.79 17.01 -2.2
97 15.57 15.58 18.44 -2.9
112 15.96 15.80 19.09 -3.1
128 16.09 16.15 19.79 -3.7

In-step (decode_bench --sim1, TP4 rank-0 shard on one GPU, ctx 100K, k=7, ATOM #3810 paired, flag ATOM_M3_QKV_CHAIN off vs on, ABAB x3, median step ms): B9 (72 rows) 12.474 -> 12.090 (-0.38), B12 (96 rows) 13.372 -> 12.943 (-0.43), B16 (128 rows) 14.810 -> 14.304 (-0.51); off-to-off spread 0.05-0.15 ms, on-to-on 0.1-0.28. Raw: off 12.474/12.480/12.474, 13.322/13.427/13.372, 14.724/14.930/14.810; on 12.090/11.915/12.197, 12.943/13.095/12.924, 14.311/14.304/14.198.

Combined gain of the QKV chain stack. Stage 1 (#8606, #8607, ATOM #3809, 17-64 rows) measured -0.24 to -0.69 ms per decode step at B3-B8 (in-step decode_bench --sim1, flag off/on ABAB). This stage (65-128 rows = B9-B16 at k=7) measures -0.38 to -0.51 ms per step (table below), so the chain covers B3-B16, the whole range that sets ITL p90. Not yet measured: a real 4-rank step or AgentX (sim1 has no all-reduce).

Numerics

Bit-equal to the amd-kernels chain entry: q_out, index_q, KV pages and index pages, 0 differing bytes, at 65, 72, 80, 81, 96, 97, 112, 128 rows with all slots valid and with every third request skipped (slot -1) at 65, 81, 97, 128.

Tests

op_tests/test_flydsl_qkv_chain.py extended to 17-128 rows plus graph replay at m = 40 / 72 / 112 (67 tests pass together with the GEMM and quantizer tests, GPU, MI355X). black and ruff clean.

Review

Run by hand against .claude/skills/review-pr: perf claim has numbers (kernel and in-step), shapes and repro; the reduce-insert has no counters or cross-workgroup state (V join is a workgroup barrier), so no graph-capture hazard; buffer resources are sized from the token count and strides with host asserts; amd-kernels credited in the file headers, no import; raw inline-asm helpers (LDS access, MFMA) are shared with qkv_chain_cooperative as in #8607; legacy buffer_ops kept consistent with the stack.

Repro: /shared_nfs/ygan/p1/070-decode-closers/gbin (t_g2.py, abab_g.sh).

Generated with Claude Code

ganyi1996ppo and others added 8 commits November 24, 2026 07:45
…Max-M3 TP4 prefill

Same bytes as the HIP kernel, 1.6-3.0x faster on device and 3.5x less host time per
call for calls of at least 1024 tokens (nvfp4 K/V/index-K, 16/1/1 heads, rotary 64,
gfx950). Ported from amd-kernels. AITER_FUSED_QKNORM_NVFP4_FLYDSL=0 keeps the HIP kernel.

Co-Authored-By: Claude <[email protected]>
…6) code layout + shuffled E8M0 scales

gfx950 FlyDSL quantizer: bf16 [M, K] -> fp8 e4m3 codes in the weight's (16, 16) preshuffled layout (rows padded to the row
tile, padding rows zero) plus E8M0 scales in AITER's shuffled layout, or row-major codes. One launch, a workgroup per
32-row x 256-K tile. Prerequisite of the one-launch QKV front chain (next PR): that kernel reads exactly these codes.

Technique source: amd-kernels gemm/mxfp8_common/mxfp8_quant.py and the scale/convert helpers of mxfp8_gemm_decode.py
(ported, no import). op_tests/test_flydsl_mxfp8_quant_shuffled.py compares codes and scales byte for byte against a torch
reference of the Triton MXFP8 rule (60 shape/magnitude cases).

Co-Authored-By: Claude <[email protected]>
…ode rows (TP4)

QKV MXFP8 GEMM (deferred split-3) + q/k/index-q/index-k RMSNorm + partial RoPE + NVFP4 K/V/index-K page inserts in ONE
launch: 240 five-wave workgroups, a head's 12 workgroups publish sc1 slabs and bump an epoch counter, the last roles reduce
and insert eight rows each. Replaces the three launches of the public decode path (quantize, GEMM, fused_qknorm_idxrqknorm)
for 17-64 rows. Host wrapper qkv_chain_cooperative_insert keeps counters per device/stream or HIP capture id.

Technique source: amd-kernels attention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128 (kernel_cooperative.py,
host.py) and the decode GEMM primitives of mxfp8_gemm_decode.py (ported, no import). Helpers come from the FlyDSL NVFP4
insert of ROCm#8576, activation codes from the quantizer of the previous commit.

Co-Authored-By: Claude <[email protected]>
…-128 rows, MiniMax-M3.1 TP4 QKV

One-wave workgroups over RT 16-row x NI 16-column tiles of one K third, both operands in the (16, 16) preshuffled layout,
W / A blocks issued ahead of the scaled MFMAs, odd-RT A scale re-pairing; writes the fp32 slabs a fused reduce-insert reads.
Bit-identical to the amd-kernels decode GEMM at 65..128 rows; graph replay 8.1-9.1 us vs 9.7-11.7 us for the public GEMM.

Technique source: amd-kernels gemm/mxfp8_common/mxfp8_gemm_decode.py (ported, no import).

Co-Authored-By: Claude <[email protected]>
…n for 65-128 decode rows (TP4)

Sums the three fp32 K-third slabs, rounds to bf16 and runs the norm / RoPE / NVFP4 K, V, index-K insert arithmetic of
fused_qknorm_idxr_nvfp4_insert in one launch (V in workgroups of its own through LDS); qkv_chain_insert serves 17-128 rows
(one launch to 64 rows, GEMM + reduce-insert above). Bit-identical to the amd-kernels chain at 65..128 rows; graph replay
13.7-16.3 us vs 16.9-20.0 us for quantize + public GEMM + fused_qknorm_idxrqknorm.

Technique source: amd-kernels attention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128 (reduce_insert.py, packing.py).

Co-Authored-By: Claude <[email protected]>
…er-device compiled handle + x.device stream, whole-tile rule for rpw>2, op test entry point

Co-Authored-By: Claude <[email protected]>
… extents), per-device handle + stream, stricter page checks, op test entry point

Co-Authored-By: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8611 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision 773f8736e4de · mode shadow

This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical defects can corrupt cache updates, write beyond output allocations, and incorrectly reuse compiled handles across GPUs.

6 open issues
What changed in this PR

Extends the gfx950 MiniMax-M3.1 TP4 QKV decode chain to 65–128 rows, building on the stacked activation-quantizer and cooperative-chain work. The new path combines split-3 reduction, normalization, RoPE, and NVFP4 cache insertion without writing an intermediate bf16 QKV tensor.

Changes:

  • Adds fused reduce-and-insert processing after the split-K GEMM.
  • Dispatches 17–64 rows to the cooperative chain and 65–128 rows to the two-launch path.
  • Extends numerical comparisons and graph-replay tests across the decode range.
File Description
op_tests/​test_fused_qknorm_nvfp4_flydsl.py Compares standalone inserts with HIP, including cache preservation.
op_tests/​test_flydsl_qkv_chain.py Tests the extended chain and graph replay.
op_tests/​test_flydsl_mxfp8_quant_shuffled.py Checks shuffled activation codes and scales.
op_tests/​test_flydsl_mxfp8_gemm_decode_splitk.py Tests split-K sums and graph replay.
aiter/​ops/​fused_qknorm_idxrqknorm.py Adds standalone FlyDSL NVFP4 insert dispatch.
aiter/​ops/​flydsl/​kernels/​qkv_reduce_insert.py Fuses slab reduction, normalization, RoPE, and cache insertion.
aiter/​ops/​flydsl/​kernels/​qkv_chain.py Provides chain launchers and row-count dispatch.
aiter/​ops/​flydsl/​kernels/​qkv_chain_cooperative.py Supplies the cooperative 17–64-row chain and shared helpers.
aiter/​ops/​flydsl/​kernels/​mxfp8_quant_shuffled.py Produces shuffled MXFP8 activations for the chain.
aiter/​ops/​flydsl/​kernels/​mxfp8_gemm_decode_splitk.py Produces three fp32 partial-sum slabs for 65–128 rows.
aiter/​ops/​flydsl/​kernels/​fused_qknorm_idxr_nvfp4_insert.py Supplies standalone inserts and shared quantization helpers.
aiter/​ops/​flydsl/​kernels/​fused_qknorm_idxr_nvfp4_insert_prefill.py Supplies the prefill-optimized standalone insert variant.

Review effort: Balanced

Comment on lines +263 to +268
assert q_out.dtype == torch.bfloat16 and q_out.is_contiguous()
assert (
index_q_out.dtype == torch.float8_e4m3fn
and index_q_out.stride(1) == 1
and index_q_out.stride(0) % 4 == 0
)
Comment thread aiter/ops/flydsl/kernels/qkv_chain.py Resolved
Comment on lines +365 to +367
n_run = fx.Int32(fx.math.ctpop(mine))
run_first = (prev < 0) | ((prev >> 3) != (slot >> 3))
go = live & (slot >= 0) & run_first
Comment thread aiter/ops/flydsl/kernels/qkv_chain.py Resolved
Comment thread op_tests/test_flydsl_qkv_chain.py Resolved
Comment thread op_tests/test_flydsl_qkv_chain.py Resolved
Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues allow out-of-bounds writes, reuse device-bound launch handles across GPUs, and misplace inserted values when slots are not consecutively ordered.

4 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Read m from keyword arguments when it is not positional

aiter/​ops/​flydsl/​kernels/​qkv_chain.py:369

The dispatcher accepts **kwargs, but reads m only from the fifth positional argument. Calling it with the first four tensors positional and m=72 (or with all arguments named) raises IndexError before reaching either implementation, even though both implementations accept that calling convention. Please obtain m from the keyword arguments when it is not positional.

Medium severity Add a pytest entry point so CI runs the split-K tests

op_tests/​test_flydsl_mxfp8_gemm_decode_splitk.py:100

This file has no script entry point, so Aiter CI imports it and exits successfully without running either test. .github/scripts/aiter_test.sh:97 defaults to python3 "$file", and this filename is not among its pytest exceptions. Please add the same pytest entry point used by the new quantizer and QKV-chain suites so the split-K numerical and graph-replay cases actually execute in CI.

Medium severity Check per-token insertion coverage and compare iq during replay

op_tests/​test_flydsl_qkv_chain.py:165

The batch-wide index-Q mean permits an entire row to be missing at m=128, and the page-wide 3% bounds likewise allow missing token inserts. The graph-replay test also omits iq from its snapshot and comparisons. Use an asserted FP32 checkAllclose result with justified per-element tolerances, check insertion coverage per token, and include iq in replay comparisons so a single missing row fails.

4 resolved since last review

Review effort: Balanced

and slot_mapping.numel() >= m
and index_slot_mapping.numel() >= m
)
assert q_out.dtype == torch.bfloat16 and q_out.is_contiguous()
and index_cache_dtype == "nvfp4"
and not skip_index_branch
and not asm_layout
and qkv.shape[0] >= _NVFP4_INSERT_FLYDSL_MIN_TOKENS
@ganyi1996ppo
ganyi1996ppo marked this pull request as draft November 25, 2026 02:56
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Closing: the split-3 reduce + norm / RoPE + NVFP4 insert (65-128 rows) is folded into the single QKV front PR #8607 (one op, tier by row count; the combined branch is being prepared there). The fork branch stays, so this can be reopened if needed.

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.

4 participants