Skip to content

[ASM] [HIP] Qwe38 flash mxfp4 asm - #5757

Merged
JohnNikolay84 merged 13 commits into
mainfrom
qwe38_flash_mxfp4_asm
Nov 7, 2026
Merged

JohnNikolay84 merged 13 commits into
mainfrom
qwe38_flash_mxfp4_asm

Conversation

@JohnNikolay84

@JohnNikolay84 JohnNikolay84 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

New asm kernels to support qwen 3.8-flash in PT2 and TP4 splt

Technical Details

Since moe_intermediatedimention for qwen3.8-flash is 640 it cannot use existing asm kernels with split by 128 or 256, we need new kernels besides 1x32 - 16x160 and 16x320. Also hidden_dim is 512 which means aiter requirements for these kernels should relax from dim % 1024 == 0 to dim % 512 == 0.

Test Plan

python3 -u op_tests/test_moe_2stage.py -t 1 2 4 8 16 -d bf16 -dim 2560,320 -q 4 -a silu -e 512 -k 10 -s f --no-flydsl-csv --ref-dtype fp32

Results:

tokens ASM us ASM kernel FlyDSL 512 us FlyDSL / ASM
1 10.21 FLAT 16×32 24.06 2.36×
2 11.27 FLAT 16×32 27.73 2.46×
4 14.46 FLAT 16×32 31.85 2.20×
8 23.95 FLAT 16×32 47.82 2.00×
16 34.18 FLAT 16×320 74.72 2.19×
32 89.06 EMSORT 16×320 122.74 1.38×
64 124.72 EMSORT 16×320 198.09 1.59×
128 126.99 EMSORT 16×320 204.44 1.61×
256 142.49 EMSORT 16×320 208.03 1.46×
512 167.57 EMSORT 16×320 212.31 1.27×
tokens ASM us ASM kernel FlyDSL 256 us FlyDSL / ASM
1 9.95 FLAT 16×32 23.85 2.40×
2 10.07 FLAT 16×32 24.29 2.41×
4 10.27 FLAT 16×32 29.26 2.85×
8 14.89 FLAT 16×32 32.05 2.15×
16 20.94 FLAT 16×160 50.34 2.40×
32 43.60 EMSORT 16×160 76.96 1.77×
64 54.19 EMSORT 16×160 109.07 2.01×
128 61.41 EMSORT 16×160 109.84 1.79×
256 75.68 EMSORT 16×160 110.78 1.46×
512 108.30 EMSORT 16×160 118.79 1.10×

PR Self-Review

Reviewed revision

a10f4be0bd32dd6959c56027f3c4705083db08d9

Behavior and intent

Qwen3.8-flash MXFP4 MoE intermediate widths are 640 at TP1, 320 at TP2 and 160 at TP4. The existing gfx950 MXFP4 SiLU assembly tiles are 128, 256 wide, so inter_dim 160 and 320 fail inter_dim % subGU_n == 0 and never launch. The default 2-stage path is also the wrong producer for these decode shapes, and two host bugs blocked the new tiles even after they were added: packed FP4 shuffling rejected K=160 because it grouped two 16-byte tiles, and the ASM heuristic hid FLAT rows by applying sorted-kernel subGU_m and vskip checks to them. This revision adds gfx950 FLAT novs tiles 16x32, 16x160 and 16x320 and EMSORT tiles 16x160 and 16x320, records them in hsa/gfx950/fmoe/silu/fmoe_bf16_pertokenMXfp4_g1u1_silu.csv, and adds tuned rows in aiter/configs/model_configs/qwen3_8_flash_fp4_tuned_fmoe.csv for hidden 2560, experts 512/topk 10 and fused-expert 513/topk 11, tokens 1 through 512. Tokens 1-16 use FLAT; tokens 32-512 use EMSORT. shuffle_weight now uses a 16-byte K tile for packed FP4, and kernel_fits accepts flat == NO_SORT. A sorted row with the same subGU_n still wins a tie.

Validation and unverified scope

On a gfx950 host reporting 256 CUs, op_tests/test_moe_2stage.py was run for bf16 SiLU, MXFP4, E=512, topk=10, model_dim=2560, inter_dim=160 and 320, tokens 1, 2, 4, 8 and 16, with --stage1-bias f --stage2-bias f --no-flydsl-csv --ref-dtype fp32. Dispatch logged the new symbols (flat_novs_silu_16x32 at token 1, and the wider FLAT tiles at larger tokens). Cosine difference versus the fp32 reference was 1.5e-5 to 4.2e-5 for inter_dim=160 and 1.5e-5 to 8.1e-5 for inter_dim=320. A host-side check of shuffle_weight on packed FP4 showed a 128-byte K width matches the previous 32-byte grouping and an 80-byte width (logical K=160) is accepted. Unverified on revision b2098866: the token 32-512 EMSORT rows were not in that sweep, token_cnt=512 was not launched against the manifest caps, and no vLLM or SGLang run was repeated on this head. The MI355X throughput numbers already in the thread include follow-up #7012 and are not a measurement of this SHA. gfx942, Gelu, and model_dim that is not a multiple of 512 were not run.

PR-specific question

The new path is gfx950 only: the code objects and manifest rows live under hsa/gfx950/fmoe/silu/, and get_heuristic_kernel prefixes the lookup with the runtime arch id, so a gfx942 process cannot select them. The dtype gate is bf16 output, per-token MXFP4 (torch.float4_e2m1fn_x2 weights, QuantType.per_1x32), SiLU, and gated G1U1. fmoe_g1u1 loads cfg_fmoe_bf16_pertokenMXfp4_g1u1_silu only for that combination; Gelu, fp16 output and other quant types use other manifests that do not contain these symbols. Tuned keys are model_dim=2560, inter_dim 160 or 320, experts 512 with topk 10 or 513 with topk 11, and the power-of-two token buckets from 1 to 512. An untuned call reaches a FLAT tile only when inter_dim % subGU_n == 0 after the shared smf, dim_align and persistent-grid checks. The invariant that keeps unsupported inputs out is enforced in the launcher, not only in the CSV. Every MXFP4 fmoe_g1u1 launch requires model_dim >= 512 and model_dim % 512 == 0, so a 256-wide remainder never reaches these tiles. EMSORT additionally requires inter_dim % sub_GU == 0, a resident persistent grid, token_cnt <= 512, token_cnt * topk <= 5632 and experts <= 1024, and launch_kernel rejects anything outside those manifest limits. Sorted rows still have to match vskip and subGU_m == block_size_M, so a 16-wide FLAT row does not replace a 32-wide sorted row of equal cost.

Changed op tests

op_tests/test_moe_2stage.py is the only changed op test. The net change versus main is --stage1-bias (default [True], same shape as the existing --stage2-bias switch). Default CLI cases still inject a random per-expert stage-1 bias, so existing sweeps keep their previous inputs. The flag is necessary because the new FLAT and EMSORT MXFP4 kernels do not apply a per-expert stage-1 bias, while the test reference does. Leaving the default bias on makes the Qwen 2560x160 and 2560x320 comparison report a cosine near 1 even when the GEMM matches. --stage1-bias f together with --stage2-bias f is what lets this file compare those kernels to a bias-free reference. No other op test builds this gfx950 MXFP4 SiLU shape and can turn stage-1 bias off, so the coverage is not redundant.

@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; main branch always runs both MI35X and MI300X
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 5757 --add-label <label>

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 opt this PR out.

@mjkvaak-amd

mjkvaak-amd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

I added a follow up #7012 and the vLLM consumer on top of this vllm-project/vllm#64025 . Here are some impact numbers, in case they help to expedite the PR

MI355X, amd/Qwen3.8-Flash-Next-Quark-MXFP4 TP4; stock → candidate (this PR + the earlier I mentioned)

ISL / OSL Conc Output tok/s (higher is better) Mean TPOT (ms, lower is better) Mean TTFT (ms, lower is better)
8192 / 1024 1 164.4 → 186.0 (+13.2%) 5.54 → 4.84 (−12.6%) 507 → 499
8192 / 1024 2 288.2 → 332.8 (+15.5%) 6.38 → 5.47 (−14.3%) 470 → 457
8192 / 1024 4 469.3 → 535.0 (+14.0%) 7.89 → 6.86 (−13.0%) 503 → 494
8192 / 1024 8 713.8 → 787.0 (+10.2%) 10.39 → 9.38 (−9.8%) 638 → 632
8192 / 1024 16 1005.2 → 1107.4 (+10.2%) 14.37 → 13.04 (−9.3%) 1015 → 945
8192 / 1024 32 1355.4 → 1358.5 (+0.2%) 20.82 → 20.80 (−0.1%) 2040 → 2056

@JohnNikolay84
JohnNikolay84 marked this pull request as ready for review October 29, 2026 13:44
@JohnNikolay84
JohnNikolay84 requested a review from a team October 29, 2026 13:44
@JohnNikolay84 JohnNikolay84 self-assigned this Oct 29, 2026
@github-actions github-actions Bot changed the title Qwe38 flash mxfp4 asm [ASM] [HIP] Qwe38 flash mxfp4 asm Oct 29, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@zufayu
zufayu self-requested a review October 30, 2026 01:29
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 2, 2026
…diate widths

vLLM stores the MoE intermediate width padded (Qwen3.8-Flash-Next: 320
stored as 384 at TP2, 160 as 256 at TP4) and passes the zero-filled delta
as intermediate_pad. The FLAT 16x32/16x160/16x320 tiles and the EMSORT
16x160 persistent tile from ROCm#5757 need the logical width, so a padded
call never reached them.

- fmoe_g1u1 takes intermediate_pad. The FLAT and EMSORT branches keep the
  stored inter_dim in KernelArgs (gate/up row offset, w1 scale offset, w2
  scale pitch) and size the grid, and the EMSORT ps_deno and total_tgs,
  from inter_dim - intermediate_pad.
- get_heuristic_kernel matches FLAT and EMSORT tiles on the logical width.
- get_2stage_cfgs falls back to the FLAT or EMSORT MXFP4 1-stage row
  tuned at inter_dim - intermediate_pad when the stored width has no row.
- The pertokenMXfp4 manifests gain a dim_align column. Kernels without the
  512-column tail drain declare 1024, and fmoe_g1u1 passes model_dim to
  the kernel picker, so the alignment applies per kernel.
- test_moe_2stage passes -hip through for a4w4.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 4, 2026
ROCm#7012's manifest predates ROCm#5757's "Extend TP4/TP2 kernels to conc512", so
taking it reset emsort_silu_16x160 and 16x320 to max_tokens 256 and
max_assignments 2816 while their .co files and the tuned rows are the
conc512 ones. A 512-token MoE call then failed in launch_kernel with
"EMSORT ... supports token_cnt <= 256; got 512".

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 4, 2026
…diate widths

vLLM stores the MoE intermediate width padded (Qwen3.8-Flash-Next: 320
stored as 384 at TP2, 160 as 256 at TP4) and passes the zero-filled delta
as intermediate_pad. The FLAT 16x32/16x160/16x320 tiles and the EMSORT
16x160 persistent tile from ROCm#5757 need the logical width, so a padded
call never reached them.

- fmoe_g1u1 takes intermediate_pad. The FLAT and EMSORT branches keep the
  stored inter_dim in KernelArgs (gate/up row offset, w1 scale offset, w2
  scale pitch) and size the grid, and the EMSORT ps_deno and total_tgs,
  from inter_dim - intermediate_pad.
- get_heuristic_kernel matches FLAT and EMSORT tiles on the logical width.
- get_2stage_cfgs falls back to the FLAT or EMSORT MXFP4 1-stage row
  tuned at inter_dim - intermediate_pad when the stored width has no row.
- The pertokenMXfp4 manifests gain a dim_align column. Kernels without the
  512-column tail drain declare 1024, and fmoe_g1u1 passes model_dim to
  the kernel picker, so the alignment applies per kernel.
- test_moe_2stage passes -hip through for a4w4.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@ROCm ROCm deleted a comment from aiter-bot Nov 4, 2026
@JohnNikolay84

Copy link
Copy Markdown
Contributor Author

@mjkvaak-amd if you have compute could you check again TP4/TP2 up to con512 ?

@aiter-bot

aiter-bot commented Nov 4, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 23a8106576f8 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Sergey SOlo and others added 6 commits November 6, 2026 14:18
Relax the small-tile dim check to a 512 multiple so 2560 hidden works, dispatch FLAT tiles for irregular inter_dim, and trim e8m0 shuffle padding in the 2-stage test so E=513 fused-expert can view scales.

Co-authored-by: Cursor <[email protected]>
valarLip
valarLip previously approved these changes Nov 6, 2026
@JohnNikolay84
JohnNikolay84 merged commit 581579a into main Nov 7, 2026
@JohnNikolay84
JohnNikolay84 deleted the qwe38_flash_mxfp4_asm branch November 7, 2026 15:33
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
* Add --fused-expert option to 2stage moe tests

* Add gfx950 FLAT MXFP4 fused-MoE 16x32/160/320 kernels.

Relax the small-tile dim check to a 512 multiple so 2560 hidden works, dispatch FLAT tiles for irregular inter_dim, and trim e8m0 shuffle padding in the 2-stage test so E=513 fused-expert can view scales.

Co-authored-by: Cursor <[email protected]>

* Add new kernels and tuned config

* Fix 16x320 kernel when h_dim/sub_gu > 1

* Remove redundant second loop scan

* Revert temp test changes

* Add test option to disable biases

* Extend asm 16x160 up to con 256 for TP4

* Add 16x320 kernel for TP2

* Extend TP4/TP2 kernels to conc512

* Upmerge to top of main

* Pass num_valid_tokens correctly for flat and emsort

---------

Co-authored-by: Sergey SOlo <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants