Skip to content

[ASM] [gfx1250]mla decode qh32 version4 - #6350

Closed
feifei14119 wants to merge 3 commits into
ROCm:mainfrom
feifei14119:fmla2
Closed

feifei14119 wants to merge 3 commits into
ROCm:mainfrom
feifei14119:fmla2

Conversation

@feifei14119

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

@feifei14119
feifei14119 requested review from a team and a balanced review from Copilot October 10, 2026 01:12
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ 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
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: 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 6350 --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.

@github-actions github-actions Bot changed the title [gfx1250]mla decode qh32 version4 [ASM] [gfx1250]mla decode qh32 version4 Oct 10, 2026
@github-actions github-actions Bot added the ASM label Oct 10, 2026

This comment was marked as outdated.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 01:22

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.

Comment thread aiter/ops/asm/asm_utils.py Resolved
Comment thread aiter/ops/asm/asm_utils.py Resolved
Comment thread op_tests/test_mla_v4_kargpreld.py Resolved
Comment thread op_tests/test_mla_v4_kargpreld.py Resolved
Copilot AI balanced review requested due to automatic review settings October 10, 2026 01:31

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.

🔵 Needs a closer look

The custom-op alias contract can break full-graph compilation, and qh32 correctness is not covered by collected tests.

6 open findings
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Mutable aliasing breaks single-split full-graph compilation

aiter/​ops/​asm/​mla_decode_v4.py:304

When num_kv_splits == 1, mla.py passes output.view(...) as splitData and also passes the same output tensor here. Declaring both aliases as independently mutable violates the alias contract used by custom-op auto-functionalization, so the advertised torch.compile(fullgraph=True) path can fail for every single-split launch. Expose only one mutable alias (the raw launcher never launches through output) or otherwise redesign the schema, and cover this case with a full-graph compile test.

🧠 Review effort: Balanced

@kaiyang-1
kaiyang-1 self-requested a review October 10, 2026 01:46

@kaiyang-1 kaiyang-1 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.

E2E test results: qh32 fp8 decode (DSv4-Pro, TP4, fp8 KV)

Setup: image rocm/fw-bringup:gfx1250-atom-20260930 (ATOM as shipped), aiter at this PR head (490d94b), serve_dsv4_tp4_kvcache_fp8.sh, FAKE_EPLB=0, OPUS prefill (ATOM_FORCE_V4_PREFILL_OPUS=1), gsm8k 3-shot.

Config gsm8k exact_match (flexible / strict)
fp8 KV, default KV pool (89169 blocks/rank) 0.00 / 0.00 (1319 q)
fp8 KV, KV pool capped below 2^24 rows (--gpu-memory-utilization 0.60 --max-num-seqs 96) 95.07 ± 0.60 / 95.15 (1319 q)
bf16 KV control, same aiter 96.4 / 96.0 (250 q)

With the default pool, the first token (from prefill) is correct and decode produces garbage right after it. This happens in both CUDA-graph and eager modes.

Root cause: KV row indices >= 2^24 break both qh32 kernels (mla_a8w8_qh32_1tg_32mx1_16nx4_sparse and fused_mla_a8w8_qh32_1tg_32mx1_16nx4_sparse). To show this, I placed the inputs from test_mla_v4_kargpreld.py (batch 4, kv_len 256) at different row offsets in a 40M-row KV pool:

Row offset Result (num_kv_splits = None / 1 / 4)
0, 7M, 9M, 16,776,191 correct (cos 0.999998)
16,777,217 to 33M GPU memory access fault
34M no fault, but wrong output (cos 0.893)

The boundary at exactly 2^24 rows, plus wrap-around past 2^32 bytes, looks like a signed 32-bit byte offset on the 128-B-row RoPE plane (row * 128). This is inferred from the boundary only; I did not inspect the asm. In e2e, each layer's KV view covers well over 100M rows, and the per-request SWA window slots sit at the top of the plane, so every decode step reads garbage without raising an error. The current op tests use small pools (and arange page indices), so they don't catch this. Please add a large-pool / high-row-index case.

Secondary issue: zero-length sequences in a batch (e.g. CUDA-graph padded slots with kv_len = 0). For lens = [20, 0, 0, 0]:

  • num_kv_splits=1: the real sequence's output is also wrong (cos ≈ 0; it looks like results are written to the wrong rows).
  • num_kv_splits = None / 2 / 4 / 16: the real sequence is correct, but the empty rows come out as NaN.

It didn't visibly hurt gsm8k with the capped pool, but it should be fixed or covered too.

Unrelated to this PR (FYI for anyone reproducing): on this branch's upstream base, the Qwen3.5 grouped-MoE model config (#6090) makes the pandas CSV merge emit floats like '128.0', and _as_int() in grouped_moe_gfx1250.py crashes during warmup. Workaround: AITER_CONFIG_GROUPED_FMOE=<aiter>/aiter/configs/tuned_grouped_fmoe.csv.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 07:50

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.

🔵 Needs a closer look

QH32 failures can be silently skipped, its benchmark includes allocator overhead, and module loading has a concurrency race.

2 open findings
4 resolved since last review

🧠 Review effort: Balanced

@feifei14119

Copy link
Copy Markdown
Contributor Author

E2E test results: qh32 fp8 decode (DSv4-Pro, TP4, fp8 KV)

Setup: image rocm/fw-bringup:gfx1250-atom-20260930 (ATOM as shipped), aiter at this PR head (490d94b), serve_dsv4_tp4_kvcache_fp8.sh, FAKE_EPLB=0, OPUS prefill (ATOM_FORCE_V4_PREFILL_OPUS=1), gsm8k 3-shot.

Config gsm8k exact_match (flexible / strict)
fp8 KV, default KV pool (89169 blocks/rank) 0.00 / 0.00 (1319 q)
fp8 KV, KV pool capped below 2^24 rows (--gpu-memory-utilization 0.60 --max-num-seqs 96) 95.07 ± 0.60 / 95.15 (1319 q)
bf16 KV control, same aiter 96.4 / 96.0 (250 q)
With the default pool, the first token (from prefill) is correct and decode produces garbage right after it. This happens in both CUDA-graph and eager modes.

Root cause: KV row indices >= 2^24 break both qh32 kernels (mla_a8w8_qh32_1tg_32mx1_16nx4_sparse and fused_mla_a8w8_qh32_1tg_32mx1_16nx4_sparse). To show this, I placed the inputs from test_mla_v4_kargpreld.py (batch 4, kv_len 256) at different row offsets in a 40M-row KV pool:

Row offset Result (num_kv_splits = None / 1 / 4)
0, 7M, 9M, 16,776,191 correct (cos 0.999998)
16,777,217 to 33M GPU memory access fault
34M no fault, but wrong output (cos 0.893)
The boundary at exactly 2^24 rows, plus wrap-around past 2^32 bytes, looks like a signed 32-bit byte offset on the 128-B-row RoPE plane (row * 128). This is inferred from the boundary only; I did not inspect the asm. In e2e, each layer's KV view covers well over 100M rows, and the per-request SWA window slots sit at the top of the plane, so every decode step reads garbage without raising an error. The current op tests use small pools (and arange page indices), so they don't catch this. Please add a large-pool / high-row-index case.

Secondary issue: zero-length sequences in a batch (e.g. CUDA-graph padded slots with kv_len = 0). For lens = [20, 0, 0, 0]:

  • num_kv_splits=1: the real sequence's output is also wrong (cos ≈ 0; it looks like results are written to the wrong rows).
  • num_kv_splits = None / 2 / 4 / 16: the real sequence is correct, but the empty rows come out as NaN.

It didn't visibly hurt gsm8k with the capped pool, but it should be fixed or covered too.

Unrelated to this PR (FYI for anyone reproducing): on this branch's upstream base, the Qwen3.5 grouped-MoE model config (#6090) makes the pandas CSV merge emit floats like '128.0', and _as_int() in grouped_moe_gfx1250.py crashes during warmup. Workaround: AITER_CONFIG_GROUPED_FMOE=<aiter>/aiter/configs/tuned_grouped_fmoe.csv.

fixed

@kaiyang-1
kaiyang-1 self-requested a review October 11, 2026 06:58

@kaiyang-1 kaiyang-1 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.

Re-test at 8ad88d9: large-KV and zero-length issues both fixed

E2E setup: same as my previous run (image rocm/fw-bringup:gfx1250-atom-20260930, ATOM as shipped, serve_dsv4_tp4_kvcache_fp8.sh, FAKE_EPLB=0, OPUS prefill via ATOM_FORCE_V4_PREFILL_OPUS=1, gsm8k 3-shot, 1319 q), with aiter at this PR head 8ad88d9 and the default KV pool, no capping.

aiter KV pool gsm8k exact_match (flexible / strict)
490d94b (previous) default (89169 blocks/rank) 0.00 / 0.00
490d94b (previous) capped below 2^24 rows 95.07 ± 0.60 / 95.15
8ad88d9 (this run) default (89875 blocks/rank) 94.77 ± 0.61 / 94.84

With the default pool, accuracy goes from 0 to the same level as the capped-pool run (the 0.3 pt gap is within one stderr). The server log had no errors during the eval.

Op-level check (standalone script reusing the op test's fp8 packing and torch reference; qh32, num_kv_splits = 1 / None / 2 / 4 / 16, covering the single-pass, fused, and stage1 + stage2 paths):

  • High row indices: batch 4 × kv_len 256 placed at row offsets from 0 up to 2^27 (134M) in a 140M-row pool, including just below/at/above 2^24 and 34M, plus rows scattered randomly over the whole pool. All cases match the reference (cos ≥ 0.999997) with no faults.
  • Zero-length sequences: lens [20,0,0,0], [0,0,0,20], [256,0,256,0], [0,300,0,1]. Real sequences match (cos ≥ 0.999997) and empty rows are written as 0 (no NaN) on every path, including num_kv_splits=1.

Remaining request: the op test itself still only builds a small pool (num_page = batch * kv_seq_lens) and has no zero-length case, so CI would not catch a regression of either bug. Please add a high-row-index case and a zero-length-sequence case.

FYI: the unrelated _as_int() crash from the Qwen3.5 grouped-MoE CSV merge is still present on this base; the e2e run used the same AITER_CONFIG_GROUPED_FMOE workaround.

@feifei14119
feifei14119 deleted the fmla2 branch October 15, 2026 05:02
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.

3 participants