Skip to content

[Config] [MoE] Qwen3.8-Flash-Next MXFP4: FlyDSL rows at M=32768 for inter_dim 384/256/640 - #8867

Draft
mjkvaak-amd wants to merge 1 commit into
ROCm:mainfrom
mjkvaak-amd:qwen3-8-flash-fp4-fmoe-m32768
Draft

mjkvaak-amd wants to merge 1 commit into
ROCm:mainfrom
mjkvaak-amd:qwen3-8-flash-fp4-fmoe-m32768

Conversation

@mjkvaak-amd

Copy link
Copy Markdown
Contributor

Summary

Adds tuned FlyDSL 2-stage rows at M=32768 for the Qwen3.8-Flash-Next MXFP4 MoE in the shapes vLLM passes at TP2 (inter_dim=384, intermediate_pad=64), TP4 (inter_dim=256, pad 64) and TP1 (inter_dim=640). These rows serve prefill batches of 16385–32768 tokens, which happen whenever --max-num-batched-tokens is above 16384. Against main, TP2 serving at --max-num-batched-tokens 32768 gains +5.1% output throughput on 60k and 128k prompts and +1.5% on 8k prompts.

Motivation

#8123 added rows up to M=16384. get_padded_M buckets 16385..32768 tokens to 32768, and get_2stage_cfgs only falls back to a lower tier above 32768. As a result, this bucket gets no tuned row and no fallback: main logs using 2stage default and runs the heuristic FlyDSL kernel, which is 1.6–1.7× slower than the tuned pair (table below). vLLM's default max_num_batched_tokens on MI355X is 16384, so the bucket is reached only when that is raised. That is common for long-context serving.

Not a duplicate: I searched open PRs for Qwen3.8-Flash-Next, 2560,384, 2560,256, 2560,640 and 32768. #8044 adds ASM producer rows at M=32768 for 384 and 640, but not 256. Those producers are about 5–8% faster than these rows at that size, and end to end they lead by about 1% on long prompts. With both PRs' rows, test_config_shape_collision.py::test_fmoe fails on those two keys. Whichever PR lands second drops them; if #8044 lands first, this PR shrinks to the inter 256 row.

Changes

  • aiter/configs/model_configs/qwen3_8_flash_fp4_tuned_fmoe.csv and qwen3_8_flash_fp4_untuned_fmoe.csv: one row per inter_dim at M=32768. They were tuned with gemm_moe_tune.py --mxfp4-flydsl (with [CK] [Tune][MoE] Clear inherited rocprofiler env before the MXFP4 FlyDSL tuner spawns shape workers #8121's fix) on MI355X, and the us column is the tuner's. Winners:
    • 384: flydsl_mxmoe_g1_a4w4_128x256x256_xcd2 + flydsl_moe2_layout_afp4_wfp4_bf16_t128x256x128_scatter_sbm128
    • 256: flydsl_mxmoe_g1_a4w4_128x256x256_xcd4 + flydsl_moe2_layout_afp4_wfp4_bf16_t128x256x256_scatter_nt_sbm128
    • 640: flydsl_mxmoe_g1_a4w4_128x256x256_xcd2 + flydsl_moe2_layout_afp4_wfp4_bf16_t128x256x128_scatter_sbm128

All three are BM128 and not inline-sort, so the padding rejection in _mxfp4_inline_sort_unsupported does not apply. Batches of up to 16384 tokens keep #8123's rows. Decode is unaffected.

Performance (if applicable)

Kernel. fmoe_pad_bench.py (from #8123) times one whole fused_moe call with CUDA-graph replay, set up the way vLLM calls it. Weights are random bf16 at the true width (320 / 160 / 640), zero-padded to 384 / 256 the way vLLM stores them, and quantized per 1x32 to fp4x2. intermediate_pad is 64 / 64 / 0, routing is uniform random through fused_topk, and AITER_USE_FLYDSL_MOE_SORTING=1 as in the server.

Hardware Workload/configuration Before (µs) After (µs) Change
MI355X inter 384 (TP2), 16384 tokens (control) 818 820 flat
MI355X inter 384 (TP2), 24576 tokens 2051 1206 −41%
MI355X inter 384 (TP2), 32768 tokens 2476 1524 −38%
MI355X inter 256 (TP4), 16384 tokens (control) 637 635 flat
MI355X inter 256 (TP4), 24576 tokens 1538 942 −39%
MI355X inter 256 (TP4), 32768 tokens 2017 1206 −40%
MI355X inter 640 (TP1), 16384 tokens (control) 1001 997 flat
MI355X inter 640 (TP1), 24576 tokens 2648 1467 −45%
MI355X inter 640 (TP1), 32768 tokens 3172 1882 −41%

The relative L2 error against an fp32 MoE at the true width is 0.289 in both arms at every size. That is the W4A4 quantization error.

Serving, TP2. Same image, before = #8123's files, after = #8123 + this PR. Both arms are otherwise identical. They ran side by side on two GPU pairs and swapped pairs between 2 passes; each cell is the mean of the passes.

AITER_USE_FLYDSL_MOE_SORTING=1 VLLM_ROCM_USE_AITER=1 VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=1 \
VLLM_ROCM_QUICK_REDUCE_QUANTIZATION=INT4 \
vllm serve amd/Qwen3.8-Flash-Next-Quark-MXFP4 --tensor-parallel-size 2 --max-model-len 262144 \
  --max-num-seqs 256 --max-num-batched-tokens 32768 --gpu-memory-utilization 0.9 --no-enable-prefix-caching \
  --gdn-prefill-backend aiter_flydsl --speculative-config '{"method": "mtp", "num_speculative_tokens": 3}' \
  --default-chat-template-kwargs '{"enable_thinking":false}'
# Random dataset, range ratio 0.8; 8k/1k at c4-c256, 60k/600 at c4/16/64, 128k/1k at c4.
ISL / OSL / conc Output tok/s Mean TTFT ms Mean TPOT ms After ahead in both passes (tok/s, TTFT)
8k / 1k / 4 1,039 → 1,060 (+2.0%) 249 → 193 (−22.5%) 3.41 → 3.46 (+1.6%) yes, yes
8k / 1k / 8 1,649 → 1,645 (−0.3%) 254 → 247 (−2.6%) 4.39 → 4.42 (+0.7%) no, yes
8k / 1k / 16 2,184 → 2,221 (+1.7%) 397 → 374 (−5.8%) 6.62 → 6.50 (−1.7%) yes, yes
8k / 1k / 32 2,919 → 2,989 (+2.4%) 846 → 757 (−10.6%) 9.58 → 9.48 (−1.0%) yes, yes
8k / 1k / 64 3,675 → 3,597 (−2.1%) 1,359 → 1,287 (−5.3%) 15.17 → 15.09 (−0.6%) no, yes
8k / 1k / 128 4,208 → 4,387 (+4.3%) 3,256 → 3,066 (−5.8%) 24.81 → 24.49 (−1.3%) yes, yes
8k / 1k / 256 4,448 → 4,556 (+2.4%) 6,354 → 6,018 (−5.3%) 47.73 → 46.94 (−1.7%) yes, yes
60k / 600 / 4 379 → 400 (+5.6%) 1,500 → 1,489 (−0.8%) 7.75 → 7.24 (−6.5%) yes, no
60k / 600 / 16 462 → 486 (+5.3%) 3,319 → 3,091 (−6.9%) 28.30 → 27.02 (−4.5%) yes, yes
60k / 600 / 64 496 → 526 (+5.9%) 11,390 → 10,859 (−4.7%) 107 → 101 (−5.9%) yes, yes
128k / 1k / 4 312 → 323 (+3.5%) 3,366 → 3,197 (−5.0%) 9.14 → 8.79 (−3.8%) yes, yes

The geomeans are +1.5% output tok/s and −8.5% mean TTFT for 8k, and +5.1% and −4.4% for 60k/128k.

  • The gain is in steps that carry more than 16384 tokens. Those are 60k and 128k prefill chunks, and 8k steps that batch several prompts. TPOT falls at 60k because decode rows share those steps.
  • 8k c8 and c64 are flat on throughput, within the ±2% pass-to-pass spread.
  • 8k c4 is the first cell after server start, so its −22.5% TTFT is warm-up noise and not a result.
  • MTP acceptance is 3.55–3.59 in all four runs.

Accuracy, TP2. Same servers and flags, run side by side.

Eval Before After Fixed / broken Exact McNemar p
GSM8K 5-shot chat, flexible-extract (n = 1319) 0.9598 0.9644 22 / 16 0.42
GSM8K 5-shot chat, strict-match 0.9591 0.9621 21 / 17 0.63
NIAH single_2, 64k 1.0 1.0 — —
NIAH single_2, 128k 1.0 1.0 — —

91% of GSM8K generations differ textually, with symmetric flips, which is churn from a kernel change. NIAH at 64k/128k runs 32k-token prefill chunks, so the new 384 row ran during it; the candidate's server log shows its kernel names at the 32768 bucket.

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

Config rows only.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

905a08e

Behavior and intent

Flash-Next MXFP4 MoE calls with 16385–32768 tokens at inter_dim 384, 256 or 640 now run a tuned FlyDSL 2-stage pair. Before this PR they ran the heuristic FlyDSL default, because #8123's rows stop at 16384 and get_2stage_cfgs does not tier down at 32768. Every other key is unchanged.

Validation and unverified scope

  • python3 -m pytest -q op_tests/tuning_tests/test_config_shape_collision.py passes (34 tests), run in the image above against this branch on main 1a191f8.
  • The kernel A/B is TRUE_INTER=320 INTER=384 PAD=64, TRUE_INTER=160 INTER=256 PAD=64 and TRUE_INTER=640 INTER=640 PAD=0 with TOKENS=16384,24576,32768 AITER_USE_FLYDSL_MOE_SORTING=1 python3 fmoe_pad_bench.py <tag>. It ran with and without this PR's rows in 2 GPU-swapped rounds.
  • TP2 serving and accuracy are as listed above.

Remaining and unverified:

fmoe_pad_bench.py
"""Graph-replayed AITER fused_moe for Flash-Next TP2 as vLLM calls it.

    python3 fmoe_pad_bench.py <tag>

The true per-rank intermediate width is TRUE_INTER (TP2: 320, TP4: 160). Weights
are zero-padded to INTER (384, 256) the way vLLM stores them (gate and up halves
each padded, w2 K tail padded) and fused_moe gets intermediate_pad=PAD, by
default INTER - TRUE_INTER. vLLM's aiter_moe_pads rounds the pad down to a
multiple of 64, so it passes 64 at both TP2 and TP4. Each output is compared against an fp32 MoE computed from the
unpadded bf16 weights at width TRUE_INTER. Which tuned rows apply is decided by the
CSV and aux gate installed in the container, not here.
"""

import json
import os
import sys

import torch
import torch.nn.functional as F

import aiter
from aiter import QuantType, dtypes, get_torch_quant
from aiter.fused_moe import fused_moe, fused_topk
from aiter.ops.shuffle import shuffle_weight
from aiter.utility import fp4_utils

tag = sys.argv[1]
H, E, TOPK = 2560, 513, 11
TRUE = int(os.environ.get("TRUE_INTER", "320"))
INTER = int(os.environ.get("INTER", "384"))
PAD = int(os.environ.get("PAD", INTER - TRUE))
TOKENS = [int(t) for t in os.environ.get("TOKENS", "512,1024,2048,4096,8192,16384").split(",")]
torch.manual_seed(0)
g1 = torch.randn(E, TRUE, H, dtype=torch.bfloat16, device="cuda") / 16
u1 = torch.randn(E, TRUE, H, dtype=torch.bfloat16, device="cuda") / 16
w2t = torch.randn(E, H, TRUE, dtype=torch.bfloat16, device="cuda") / 16
w1 = torch.zeros(E, 2 * INTER, H, dtype=torch.bfloat16, device="cuda")
w1[:, :TRUE], w1[:, INTER : INTER + TRUE] = g1, u1
w2 = torch.zeros(E, H, INTER, dtype=torch.bfloat16, device="cuda")
w2[:, :, :TRUE] = w2t
tq = get_torch_quant(QuantType.per_1x32)
w1q, w1s = tq(w1, quant_dtype=dtypes.fp4x2)
w2q, w2s = tq(w2, quant_dtype=dtypes.fp4x2)
del w1, w2
w1q = shuffle_weight(w1q.view(E, 2 * INTER, H // 2), layout=(16, 16))
w2q = shuffle_weight(w2q.view(E, H, INTER // 2), layout=(16, 16))
w1s, w2s = fp4_utils.e8m0_shuffle(w1s), fp4_utils.e8m0_shuffle(w2s)
kw = dict(w1_scale=w1s, w2_scale=w2s, quant_type=QuantType.per_1x32,
          activation=aiter.ActivationType.Silu, intermediate_pad=PAD)


def reference(x, tw, ti):
    ref = torch.zeros(x.shape[0], H, dtype=torch.float32, device="cuda")
    xf = x.float()
    for e in torch.unique(ti).tolist():
        tok, slot = (ti == e).nonzero(as_tuple=True)
        y = (F.silu(xf[tok] @ g1[e].float().t()) * (xf[tok] @ u1[e].float().t())) @ w2t[e].float().t()
        ref.index_add_(0, tok, y * tw[tok, slot].float().unsqueeze(1))
    return ref


res = {}
for M in TOKENS:
    g = torch.Generator(device="cuda").manual_seed(M)
    x = torch.randn(M, H, dtype=torch.bfloat16, device="cuda", generator=g)
    score = torch.randn(M, E, dtype=torch.bfloat16, device="cuda", generator=g)
    tw, ti = fused_topk(x, score, TOPK, True)
    fn = lambda: fused_moe(x, w1q, w2q, tw, ti, **kw)
    out = fn().float()
    torch.cuda.synchronize()
    ref = reference(x, tw, ti)
    rel = ((out - ref).norm() / ref.norm()).item()
    finite = bool(torch.isfinite(out).all())
    reps = max(4, min(50, 20000 // M))
    s = torch.cuda.Stream()
    s.wait_stream(torch.cuda.current_stream())
    with torch.cuda.stream(s):
        for _ in range(2):
            fn()
    torch.cuda.current_stream().wait_stream(s)
    graph = torch.cuda.CUDAGraph()
    with torch.cuda.graph(graph):
        for _ in range(reps):
            fn()
    graph.replay()
    torch.cuda.synchronize()
    times = []
    for _ in range(9):
        a, b = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)
        a.record()
        graph.replay()
        b.record()
        b.synchronize()
        times.append(a.elapsed_time(b) * 1e3 / reps)
    times.sort()
    res[M] = {"us": times[len(times) // 2], "us_min": times[0], "rel_l2": rel, "finite": finite}
    print(f"{tag} M={M:6d} {res[M]['us']:9.1f} us  rel_l2 {rel:.4f}  finite {finite}", flush=True)
    del graph

json.dump(res, open(f"/work/bench/pad_{tag}.json", "w"), indent=1)

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

  • Selection. Only the exact tuned-row key reaches the new rows: (gfx950, cu_num=256, token 32768, 2560, inter_dim 384/256/640, 513, 11, Silu, bf16, fp4x2, fp4x2, per_1x32, g1u1, doweight_stage1=0). get_padded_M maps 16385..32768 tokens to 32768.
  • Above 32768 tokens. Calls with more than 32768 tokens pad to the 131072 tier, which has no row. The tier fallback in get_2stage_cfgs then tries 32768, so those calls now also take this PR's row, where before they ran the heuristic. That case is not measured here. vLLM reaches it only with --max-num-batched-tokens above 32768.
  • Gates. [HIP] [MoE] Qwen3.8-Flash-Next MXFP4 TP2/TP4: aux shape gates and FlyDSL rows for padded inter_dim, M>=1024 #8123 gates the aux shapes (513, 2560, 512, 11) and (513, 2560, 256, 11). For 640, main already has a FlyDSL row at 16384. The kernel A/B's dispatch log shows this PR's kernel names at 32768 for all three widths.
  • Invariant. get_2stage_cfgs still validates each MXMOE row and falls back on failure. It checks the sort block_m against GEMM1 BM and GEMM2, the registered aux shape, the input dtype for inline_quant, stage-2 bias, and EP expert_mask. None of the rows is inline-sort.

Changed op tests

None.

Co-authored-by: Cursor [email protected]

…ter_dim 384/256/640

The Flash-Next MXFP4 MoE rows stop at M=16384, and get_2stage_cfgs only
falls back to a lower tier above 32768 tokens, so batches of 16385..32768
tokens (reached with max_num_batched_tokens > 16384) ran the heuristic
FlyDSL default. Add tuned FlyDSL 2-stage rows at M=32768 for TP2 (384,
intermediate_pad 64), TP4 (256, pad 64) and TP1 (640), tuned with
gemm_moe_tune.py --mxfp4-flydsl.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd requested a review from a team November 27, 2026 17:52
@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 8867 --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 changed the title [Config][MoE] Qwen3.8-Flash-Next MXFP4: FlyDSL rows at M=32768 for inter_dim 384/256/640 [Config] [MoE] Qwen3.8-Flash-Next MXFP4: FlyDSL rows at M=32768 for inter_dim 384/256/640 Nov 27, 2026
@mjkvaak-amd
mjkvaak-amd marked this pull request as draft November 27, 2026 19:21
@aiter-bot

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision 905a08e4cf10 · 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.

This branch has not been deployed

No deployments
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.

2 participants