Skip to content

[ASM] Tune conc 256 and 128 for qwen3.8-flash - #7901

Merged
yifehuan merged 4 commits into
mainfrom
qwen38-tune-conc128_256
Nov 23, 2026
Merged

yifehuan merged 4 commits into
mainfrom
qwen38-tune-conc128_256

Conversation

@JohnNikolay84

@JohnNikolay84 JohnNikolay84 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tune conc 128 and 256 for qwn38-flash.
This is a non-monokernel path for moe on TP2.

Motivation

It seems that prev results for conc128 on e2e were not giving any uplift. This kernel makes further 20% improvement to the kernel.

Changes

New stk emsort kernel for conc128 and con 256.

Performance (if applicable)

Data from moe traces for qwen38-flash

Tokens Batches orig avg (µs) new kernel avg (µs) Speedup (geomean) Min Max
64 10 57.8 38.8 1.48x 1.35x 1.56x
70 1 66.1 43.4 1.52x    
96 1 70.6 46.7 1.51x    
97 1 73.1 49.6 1.47x    
98 1 72.1 48.6 1.48x    
99 1 73.5 50.0 1.47x    
123 1 71.2 48.2 1.48x    
126 1 72.0 46.9 1.54x    
128 9 70.3 45.4 1.55x 1.51x 1.62x
255 2 98.7 68.2 1.44x 1.39x 1.50x
256 9 89.0 62.8 1.42x 1.39x 1.47x
450 1 162.8 100.8 1.62x    
512 1 165.6 98.9 1.67x    

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

PR Self-Review

Reviewed revision

151074d

Behavior and intent

Previously committed asm kernels did not show improvement on concurrencies 128 and above.
This new stk kernel will cover concurrencies 64 through 512 delivering an uplift.

Validation and unverified scope

aiter op_tests/test_moe_2stage.py has been used to verify correctness.
python3 -u op_tests/test_moe_2stage.py -t 64 128 256 512 -d bf16 -dim 2560,320 -q 4 -a silu -e 512 -k 10 -s f --no-flydsl-csv --ref-dtype fp32

| dtype          |   token |   model_dim |   inter_dim |   E |   topk |   actType | gateMode   |   qType | AQDType                | WQDType                | use_g1u1   | doweight_stage1   | strict_accuracy   | check_aot_cache   | swiglu_limit   | preshuffle   |   hidden_pad |   intermediate_pad | disable_stage1_bias   | disable_stage2_bias   | kernel_bench   | ref_dtype   | beta   | linear_beta   | gate_up_layout   | expected_kernel1   |     us |   logits_diff | model   |
|:---------------|--------:|------------:|------------:|----:|-------:|----------:|:-----------|--------:|:-----------------------|:-----------------------|:-----------|:------------------|:------------------|:------------------|:---------------|:-------------|-------------:|-------------------:|:----------------------|:----------------------|:---------------|:------------|:-------|:--------------|:-----------------|:-------------------|-------:|--------------:|:--------|
| torch.bfloat16 |      64 |        2560 |         320 | 512 |     10 |         0 | separated  |       3 | torch.float4_e2m1fn_x2 | torch.float4_e2m1fn_x2 | True       | False             | False             | False             |                | True         |            0 |                  0 | False                 | False                 | False          | fp32        |        |               |                  |                    |  92.77 |   1.15738e-05 | legacy  |
| torch.bfloat16 |     128 |        2560 |         320 | 512 |     10 |         0 | separated  |       3 | torch.float4_e2m1fn_x2 | torch.float4_e2m1fn_x2 | True       | False             | False             | False             |                | True         |            0 |                  0 | False                 | False                 | False          | fp32        |        |               |                  |                    | 111.98 |   1.07861e-05 | legacy  |
| torch.bfloat16 |     256 |        2560 |         320 | 512 |     10 |         0 | separated  |       3 | torch.float4_e2m1fn_x2 | torch.float4_e2m1fn_x2 | True       | False             | False             | False             |                | True         |            0 |                  0 | False                 | False                 | False          | fp32        |        |               |                  |                    | 123.88 |   1.09373e-05 | legacy  |
| torch.bfloat16 |     512 |        2560 |         320 | 512 |     10 |         0 | separated  |       3 | torch.float4_e2m1fn_x2 | torch.float4_e2m1fn_x2 | True       | False             | False             | False             |                | True         |            0 |                  0 | False                 | False                 | False          | fp32        |        |               |                  |                    | 141.62 |   1.13023e-05 | legacy  |

Plus @mjkvaak-amd has helped to verify performance uplift on qwen38-flash mxfp4

Nothing is unverified. This PR touches only Qwen38-flash shapes for TP2.

PR-specific question

Changed op tests

@JohnNikolay84
JohnNikolay84 requested a review from a team November 12, 2026 23:00
@github-actions github-actions Bot changed the title Tune conc 256 and 128 for qwen3.8-flash [ASM] Tune conc 256 and 128 for qwen3.8-flash Nov 12, 2026
@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 7901 --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.

@github-actions github-actions Bot added the ASM label Nov 12, 2026
@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision a039fb5b45be · 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
  • FAIL — PR-specific question has no substantive answer

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

@JohnNikolay84

Copy link
Copy Markdown
Contributor Author

@mjkvaak-amd do you have time to run qwen3.8-flash with this PR ?

@mjkvaak-amd

Copy link
Copy Markdown
Contributor

E2E validation of #7901 on Flash-Next TP2 on vLLM

Setup

Serving (8k/1k and 1k/1k, range ratio 0, N = 4C, two rounds swapping HIP pairs)

ISL/OSL Conc Output tok/s ctrl → cand Per round Mean TPOT ms
1k/1k 32 2624.5 → 2606.5 (−0.7%) −0.2%, −1.2% 11.02 → 11.11
1k/1k 64 3522.2 → 3552.1 (+0.8%) +0.8%, +0.9% 16.53 → 16.31
1k/1k 128 4503.0 → 4627.3 (+2.8%) +2.9%, +2.7% 25.86 → 25.15
1k/1k 192 5152.7 → 5180.6 (+0.5%) +0.7%, +0.4% 34.33 → 34.10
1k/1k 256 5699.8 → 5726.1 (+0.5%) +0.8%, +0.2% 41.54 → 41.32
8k/1k 64 1608.1 → 1610.8 (+0.2%) −0.0%, +0.4% 34.17 → 34.09
8k/1k 128 1782.0 → 1798.8 (+0.9%) +0.9%, +1.0% 62.96 → 62.31
8k/1k 256 1947.6 → 1945.9 (−0.1%) −0.2%, +0.0% 115.89 → 115.87

The rows with conc=32-64 are flat, as expected. Conc=128 sees a small boost. Conc=256 seems to be on the noise level.

@JohnNikolay84
JohnNikolay84 marked this pull request as draft November 19, 2026 09:22
@JohnNikolay84
JohnNikolay84 marked this pull request as ready for review November 19, 2026 17:01
@JohnNikolay84
JohnNikolay84 force-pushed the qwen38-tune-conc128_256 branch 2 times, most recently from ddfe619 to f5d8594 Compare November 20, 2026 10:45
@mjkvaak-amd

mjkvaak-amd commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Not a blocker, but worth a guard while this kernel is open: emsort_silu_16x320_stk hits an HSA memory fault when routing repeats an expert within a row and one expert gets about 2.5K assignments. The existing emsort_silu_16x320 has the same limit. Fix for the root cause here #8385 .

MI355X, E = 513, top-11, model_dim 2560, inter_dim 320 (unpadded), MXFP4 SiLU, random weights. With this PR's 128/256 rows the call runs _stk:

M Expert 0 repeats per row Expert-0 assignments Result
256 2 512 ok
256 4 1024 ok
256 6 1536 ok
128 10 1280 ok
256 10 2560 memory fault

The padded Flash-Next layout from #7611 (stored 384, pad 64) gives the same results. For comparison, emsort_silu_16x320 at M = 512 passes 2048 and faults at 2560 and above. Values don't matter: NaN activations with distinct ids pass, and finite activations with these ids fault.

Suggestions, either would do:

  • Kernel: bound the per-expert queue writes, so out-of-contract routing gives wrong numbers instead of a fault.
  • Launcher (fmoe_g1u1 or the EMSORT row selection): state that ids must be distinct within a row, and route calls that can exceed the per-expert capacity to the 2-stage path. Duplicate ids can't be detected cheaply on the host, so this would mostly be documentation plus a debug-mode check.

Repro (one GPU):

import torch
from aiter import ActivationType, QuantType, dtypes
from aiter.fused_moe import fused_moe

E, K, D, I, M = 513, 11, 2560, 320, 256
dev = "cuda"
w1 = torch.randint(0, 256, (E, 2 * I, D // 2), dtype=torch.uint8, device=dev).view(dtypes.fp4x2)
w2 = torch.randint(0, 256, (E, D, I // 2), dtype=torch.uint8, device=dev).view(dtypes.fp4x2)
w1s = torch.full((E, 2 * I, D // 32), 127, dtype=torch.uint8, device=dev).view(dtypes.fp8_e8m0)
w2s = torch.full((E, D, I // 32), 127, dtype=torch.uint8, device=dev).view(dtypes.fp8_e8m0)
hs = torch.randn(M, D, device=dev, dtype=torch.bfloat16)
w = torch.rand(M, K, device=dev)
ids = torch.stack([torch.randperm(E - 2, device=dev)[: K - 1] + 1 for _ in range(M)])
ids = torch.cat([ids, torch.full((M, 1), E - 1, device=dev)], 1).to(torch.int32)
ids[:, :10] = 0  # what topk_gating returns for an all-NaN row; [:, :6] at M=256 passes
fused_moe(hs, w1, w2, w, ids, None, ActivationType.Silu, QuantType.per_1x32, False,
          w1s, w2s, None, None, dtype=torch.bfloat16)
torch.cuda.synchronize()

@JohnNikolay84

Copy link
Copy Markdown
Contributor Author

Not a blocker, but worth a guard while this kernel is open: emsort_silu_16x320_stk hits an HSA memory fault when routing repeats an expert within a row and one expert gets about 2.5K assignments. The existing emsort_silu_16x320 has the same limit. Fix for the root cause here #8385 .

MI355X, E = 513, top-11, model_dim 2560, inter_dim 320 (unpadded), MXFP4 SiLU, random weights. With this PR's 128/256 rows the call runs _stk:

M Expert 0 repeats per row Expert-0 assignments Result
256 2 512 ok
256 4 1024 ok
256 6 1536 ok
128 10 1280 ok
256 10 2560 memory fault
The padded Flash-Next layout from #7611 (stored 384, pad 64) gives the same results. For comparison, emsort_silu_16x320 at M = 512 passes 2048 and faults at 2560 and above. Values don't matter: NaN activations with distinct ids pass, and finite activations with these ids fault.

Suggestions, either would do:

  • Kernel: bound the per-expert queue writes, so out-of-contract routing gives wrong numbers instead of a fault.
  • Launcher (fmoe_g1u1 or the EMSORT row selection): state that ids must be distinct within a row, and route calls that can exceed the per-expert capacity to the 2-stage path. Duplicate ids can't be detected cheaply on the host, so this would mostly be documentation plus a debug-mode check.

Repro (one GPU):

import torch
from aiter import ActivationType, QuantType, dtypes
from aiter.fused_moe import fused_moe

E, K, D, I, M = 513, 11, 2560, 320, 256
dev = "cuda"
w1 = torch.randint(0, 256, (E, 2 * I, D // 2), dtype=torch.uint8, device=dev).view(dtypes.fp4x2)
w2 = torch.randint(0, 256, (E, D, I // 2), dtype=torch.uint8, device=dev).view(dtypes.fp4x2)
w1s = torch.full((E, 2 * I, D // 32), 127, dtype=torch.uint8, device=dev).view(dtypes.fp8_e8m0)
w2s = torch.full((E, D, I // 32), 127, dtype=torch.uint8, device=dev).view(dtypes.fp8_e8m0)
hs = torch.randn(M, D, device=dev, dtype=torch.bfloat16)
w = torch.rand(M, K, device=dev)
ids = torch.stack([torch.randperm(E - 2, device=dev)[: K - 1] + 1 for _ in range(M)])
ids = torch.cat([ids, torch.full((M, 1), E - 1, device=dev)], 1).to(torch.int32)
ids[:, :10] = 0  # what topk_gating returns for an all-NaN row; [:, :6] at M=256 passes
fused_moe(hs, w1, w2, w, ids, None, ActivationType.Silu, QuantType.per_1x32, False,
          w1s, w2s, None, None, dtype=torch.bfloat16)
torch.cuda.synchronize()

Thanks @mjkvaak-amd . I have fixed the kernel to truncate sorting that fails topk contract instead of faulting. But these kernels are not designed for topk output being repetative.

@mjkvaak-amd

Copy link
Copy Markdown
Contributor

Thanks @mjkvaak-amd . I have fixed the kernel to truncate sorting that fails topk contract instead of faulting. But these kernels are not designed for topk output being repetative.

Thanks for the topk fix. A separate issue arised: emsort_silu_16x320_stk sometimes writes NaN / inf into output rows with finite input and valid routing (distinct ids). It looks like a race in the kernel: replaying the same call on one GPU fails on some launches only, in different rows each time. emsort_silu_16x320 never does it.

Qwen3.8-Flash-Next MXFP4, TP2, MI355X, vLLM nightly 8ca76632 + vllm#64025, AITER v0.1.29 + #7611 (stored 384, pad 64) + this PR. Eager server with every 33-512-token fused_moe call checked, 1k/1k at c64 (decode M = 64):

Kernel First NaN output from finite input
emsort_silu_16x320 none in 720K calls
stk @ da83cb7 call ~229K (another run ~420K)
stk @ 151074d call ~680, also with only VLLM_ROCM_USE_AITER=1 set

From there the NaN propagates through later layers and the router turns those rows into duplicate ids. Replaying one failing call (real layer weights, routing, activations) on one GPU: 151074d gives NaN/inf on 10 / 300 launches, da83cb7 and emsort_silu_16x320 on 0 / 300. Random weights and routing never triggered it in ~1M launches, so the real queue lengths / timing seem to matter.

Possibly related, from the disassembly: since da83cb7 the 8 producers (tgy 504-511 of a fixed 512-WG grid) write ready flags {s96, 0xdeadc0de} past the rows. s96 is the queue / pipe / ME id, so it doesn't change between launches, and nothing clears the flags. A launch reusing the same buffer address skips the wait. With NaN-prefilled rows and stale flags some launches kept NaN, but clearing the flags before every launch still left 2 / 3000, so that's not all of it. Also, Python allocates 8 flag bytes for what are now 64, which only works thanks to the allocator's 512-byte rounding.

Replay script:

import sys, torch
from aiter.fused_moe import fused_moe

d = torch.load(sys.argv[1], weights_only=False)  # args / kw of the server's fused_moe call
args = [a.cuda() if torch.is_tensor(a) else a for a in d["args"]]
kw = {k: (v.cuda() if torch.is_tensor(v) else v) for k, v in d["kw"].items()}
bad = 0
for _ in range(300):
    out = fused_moe(*args, **kw)
    torch.cuda.synchronize()
    bad += int(not torch.isfinite(out).all())
print("launches with NaN/inf:", bad)

@JohnNikolay84
JohnNikolay84 force-pushed the qwen38-tune-conc128_256 branch from 151074d to a039fb5 Compare November 21, 2026 10:19

@yifehuan yifehuan 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.

LGTM

@yifehuan
yifehuan merged commit bf59948 into main Nov 23, 2026
61 checks passed
@yifehuan
yifehuan deleted the qwen38-tune-conc128_256 branch November 23, 2026 06:50
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 23, 2026
Conflicts in the SiLU/GELU MXFP4 manifests, where ROCm#7901 appended the
emsort 16x320_stk rows: keep this branch's dim_align column and give the
new rows 512, as for the other EMSORT rows.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
JohnNikolay84 pushed a commit that referenced this pull request Nov 24, 2026
mjkvaak-amd added a commit to mjkvaak-amd/aiter that referenced this pull request Nov 24, 2026
Conflicts in the SiLU/GELU MXFP4 manifests from the ROCm#7901 revert (ROCm#8489):
drop the emsort 16x320_stk rows it removes, keeping this branch's
dim_align column on the rest.

Signed-off-by: Mikko Tukiainen <[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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants