Skip to content

[ROCm][DSv4.1] Opt-in AITER FlyDSL a8w4 experts op for the MXFP4 MoE (aiter backend) - #68995

Draft
Fangzhou-Ai wants to merge 2 commits into
vllm-project:mainfrom
Fangzhou-Ai:fai/dsv41f-moe-a8w4-experts-callsite
Draft

Fangzhou-Ai wants to merge 2 commits into
vllm-project:mainfrom
Fangzhou-Ai:fai/dsv41f-moe-a8w4-experts-callsite

Conversation

@Fangzhou-Ai

@Fangzhou-Ai Fangzhou-Ai commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Adds an opt-in call site, VLLM_ROCM_USE_AITER_FLYDSL_MOE_A8W4=1 (default off), for AITER's new FlyDSL a8w4 routed-experts op. With the flag on, AiterMxfp4Experts (the --moe-backend aiter MXFP4 path) sends the calls the op supports to aiter.ops.flydsl.moe_a8w4_experts instead of aiter.fused_moe. These calls are the DeepSeek-V4.1-Flash routed experts of the target model and of the DSpark draft.

Depends on ROCm/aiter#8381 (not merged or released yet). The op is imported lazily, so on any AITER without it nothing changes and aiter.fused_moe keeps running.

Who runs this path. Only deployments that serve DeepSeek-V4.1-Flash's MXFP4 experts with --moe-backend aiter use it: TP or EP with the default all-gather / reduce-scatter dispatch (for example DP8 + EP8 with --moe-backend aiter), or a single GPU. The DSv4.1-Flash DEP8 recipe that uses --moe-backend aiter_mega_moe (MegaMoE) does not reach this code. The sibling PRs #68998 (AITER FusedEPMoE for aiter_mega_moe small batches) and #68997 (FlyDSL MoE router) cover that deployment. Under EP8 this PR only takes calls up to 160 (top-6) or 96 (top-3) gathered rows. With DSpark (6 rows per request, every DP rank padded to the same count) that is at most 3 target requests per rank, so it helps low-concurrency decode.

Claims

  • Scope. The flag routes a call only when all of these hold:

    • MXFP4 W4A16 config with the default a8w4 activations (not VLLM_ROCM_USE_AITER_MOE_A4W4_DSV4), and AITER_BF16_FP8_MOE_BOUND <= tokens. That is the condition under which aiter.fused_moe runs a8w4. The DeepSeek-V4 weight conversion sets the bound to 0.
    • SiLU with a SwiGLU limit of 10.
    • No bias, bf16 input, no prequantized input or expert_tokens_meta, no DBO.
    • Hidden 5120, intermediate 2304, top-3 or top-6, at most 63 local experts, 1-1024 tokens, gfx950.
    • Under EP (an expert mask): only EP8 (global experts = 8 x local), and at most 160 tokens (top-6) or 96 tokens (top-3).

    All other calls keep aiter.fused_moe.

  • Same weights, same math. The op reads the tensors AiterMxfp4Experts already holds, without a copy (shuffle_weight_a16w4 / shuffle_scale_a16w4 layouts). Its numerics are the a8w4 math that aiter.fused_moe runs here: MXFP8 input, silu(min(gate, 10)) * clamp(up, -10, 10), MXFP8 intermediate. It sums the top-k slots in a fixed order, without atomics, so its outputs are bitwise repeatable.

  • Speed at the call site. These are microbenchmarks with graph replay on MI355X, with 8 layers' weights rotated (tables below):

    • EP8 target layers (top-6): 1.5-20 % less time per MoE call from 1 to 160 rows, except 5-8 rows, where it is 3-10 % slower.
    • EP8 draft layers (top-3): 4.9-31 % less time from 1 to 96 rows.
    • All experts local: 10-45 % less time from 16 to 1024 tokens.
    • Above the caps, aiter.fused_moe ties or wins, which is why the caps exist.
  • End to end: not measured yet, see E2E status. No end-to-end speedup or accuracy result is claimed.

Validation

Hardware and stack:

  • MI355X (gfx950). The 8-GPU node is shared; each benchmark ran on one GPU.
  • This branch at 04f7a4b42, on vLLM main 8e45c458f. The vLLM Python tree was imported over the compiled extensions of a ROCm build of vLLM 0.34.0rc1.dev897.
  • AITER at the [FlyDSL] [MoE] gfx950 a8w4 routed-experts op for H5120/I2304 top-6/top-3 ROCm/aiter#8381 head 3662841e9, based on ROCm/aiter 9569fb31a, with FlyDSL 0.5.0 (the version AITER and vLLM main pin). Between that base and current ROCm/aiter main 044e23329, aiter/fused_moe.py, MoE sorting and the shuffle ops are unchanged. The only MoE config changes are fp4-activation (a4w4) rows in dsv41_fp4_tuned_fmoe.csv and gfx1250 rows in tuned_grouped_fmoe.csv, and the a8w4 path reads neither. So the aiter.fused_moe baseline below is the same as on current AITER main for these shapes.

Lint. pre-commit run --files <the 4 changed files>: all hooks pass, including mypy.

New tests (in tests/kernels/moe/test_rocm_aiter_moe.py, which already runs in the AMD kernels CI step):

pytest -v tests/kernels/moe/test_rocm_aiter_moe.py -k "flydsl_a8w4 or flydsl_moe_a8w4"
# AITER with ROCm/aiter#8381:
=============== 10 passed, 95 deselected, 17 warnings in 12.29s ================
# installed AITER without the op (the 9 real-op cases skip):
1 passed, 9 skipped, 95 deselected, 17 warnings in 2.01s
  • test_aiter_flydsl_moe_a8w4_off_by_default_and_needs_the_op: the flag is off by default, and with the flag on, an AITER whose op module does not import gives no op, so aiter.fused_moe runs.
  • test_aiter_mxfp4_experts_flydsl_a8w4_matches_fused_moe (9 cases, gfx950, skips without the op) runs real weights through the production conversion (convert_weight_to_mxfp4_moe_kernel_format(AITER_MXFP4_BF16)) and the real op. No stand-ins or mocks.
    • Dispatch. The output must equal the op's own output, computed from the local ids that determine_expert_map gives, bit for bit, exactly when the call should take the op. The cases cover:
      • EP8 384/top-6 at 1 and 160 rows (op) and 161 rows (fallback);
      • EP8 128/top-3 at 96 (op) and 97 (fallback);
      • EP4 128/top-3 (fallback, since the caps are EP8-only);
      • all-local 48/top-6 at 1024 and 16/top-3 at 640 (op);
      • no SwiGLU limit (fallback).
    • Accuracy. Cosine >= 0.9998 against aiter.fused_moe (flag off), no NaN, and zero rows for tokens with no local expert.
    • Op cases. Bitwise repeatability (_assert_deterministic), and a CUDA graph captured after the first eager call replays new inputs to the op's result, bit for bit.

On the 0.9998 bound: both paths quantize to MXFP8, and each is at cosine about 0.9988 from an fp32 reference with dequantized weights. They agree with each other to >= 0.99999 from 16 tokens, and to >= 0.99985 below that, where aiter.fused_moe picks other stage kernels.

Whole file, no regressions. pytest tests/kernels/moe/test_rocm_aiter_moe.py:

branch (105 tests): 29 failed, 76 passed, 20 warnings in 223.21s (0:03:43)
main 8e45c458f (95): 29 failed, 66 passed, 20 warnings in 215.70s (0:03:35)

The 29 failures are the same set on both. They are CK-based tests whose JIT modules cannot build in this AITER source checkout (ck_tile/core.hpp not found), so they are environment failures, not caused by this change.

Call-site performance

AiterMxfp4Experts.apply was timed with the flag off (aiter.fused_moe) and with the flag on, on the same AITER. Method:

  • 8 layers, each with its own weights and its own AiterMxfp4Experts. Each layer is called once eagerly before capture.
  • One CUDA graph holds 24 calls that rotate through the 8 layers, on distinct inputs. So no layer's weights stay in the 256 MB MALL between its calls, as in a real forward pass.
  • Rounds run A B B A, 7 rounds, and the median us per call is reported. "Spread" is the largest (max - min) / median of the two columns.
  • Routing is uniform over the global experts.
  • EP8 rows use rank 2's expert mask, with the gathered rows handed to the experts, as the DP all-gather does.

Noise: rows above a cap run aiter.fused_moe in both columns, and they agree to 0.0-0.4 %. Two back-to-back runs of the EP8 rows agreed to within 1 %. An earlier version of this benchmark reused one layer's weights for every call, which flattered the op by up to about 4 points at 64-192 rows.

EP8, as shipped (_FLYDSL_A8W4_EP8_MAX_TOKENS = {6: 160, 3: 96}):

layout top-k gathered rows aiter.fused_moe (us) FlyDSL a8w4 (us) change spread
48 of 384 local 6 1 22.8 18.2 -20.3 % 3 %
6 4 36.5 29.7 -18.5 % 2 %
6 5 30.6 33.7 +10.1 % 2 %
6 6 32.8 34.5 +5.3 % 2 %
6 8 32.1 34.1 +6.3 % 3 %
6 12 44.4 42.9 -3.4 % 3 %
6 16 56.3 49.0 -13.0 % 2 %
6 24 64.5 60.1 -6.8 % 1 %
6 32 74.0 68.0 -8.1 % 1 %
6 48 89.4 82.6 -7.6 % 3 %
6 64 106.2 104.7 -1.5 % 3 %
6 96 129.5 126.3 -2.4 % 4 %
6 128 142.0 138.7 -2.4 % 3 %
6 144 146.3 142.8 -2.4 % 3 %
6 160 152.3 150.1 -1.5 % 3 %
6 192 (above cap: both aiter.fused_moe) 154.2 154.5 +0.2 % 4 %
16 of 128 local (draft) 3 1 19.7 13.6 -30.6 % 2 %
3 8 36.8 26.8 -27.2 % 2 %
3 16 41.3 36.6 -11.5 % 2 %
3 24 43.6 40.1 -8.1 % 2 %
3 32 48.9 43.8 -10.4 % 2 %
3 40 48.3 45.5 -5.7 % 2 %
3 48 51.6 47.3 -8.4 % 2 %
3 64 55.4 51.7 -6.6 % 2 %
3 96 61.1 58.1 -4.9 % 2 %
3 128 (above cap: both aiter.fused_moe) 65.2 65.1 -0.2 % 4 %

The rows at 5-7, 24, 40, 48 and 144 come from two follow-up runs in the same session, on the same code. With CUDA graphs, vLLM pads every DP rank to the same token count, so under DP8 the gathered rows are a multiple of 8. Of the slow window, only 8 rows (one token per rank, decode without speculation) occurs there.

Why the caps exist. These rows were measured with the caps lifted, so the op takes every call. Add rocm_aiter_moe._FLYDSL_A8W4_EP8_MAX_TOKENS = {6: 1024, 3: 1024} before running the script, or pass lift to it:

layout top-k gathered rows aiter.fused_moe (us) FlyDSL a8w4 (us) change spread
48 of 384 local 6 192 153.8 153.3 -0.3 % 4 %
6 224 155.0 165.3 +6.6 % 3 %
6 256 156.5 167.7 +7.2 % 3 %
6 512 164.3 199.5 +21.4 % 2 %
6 1024 172.9 208.4 +20.5 % 3 %
16 of 128 local (draft) 3 128 65.1 73.0 +12.2 % 3 %
3 256 65.6 77.9 +18.9 % 4 %

Under DP+EP with the all-gather dispatch, every rank's experts see all gathered rows, but only about 1/8 of the routes are local. The op sizes its sort and blocks by token count, while aiter.fused_moe's cost follows the local routes. So the op stops winning at 192 rows (top-6) and 128 rows (top-3), and top-6 is a tie at 192. The caps sit at the last measured win.

All experts local (no expert mask):

layout top-k tokens aiter.fused_moe (us) FlyDSL a8w4 (us) change spread
48 local 6 16 150.9 134.2 -11.1 % 4 %
6 128 174.8 156.7 -10.4 % 3 %
6 384 304.0 180.0 -40.8 % 2 %
6 1024 577.0 314.9 -45.4 % 4 %
16 local 3 40 69.8 54.5 -21.9 % 1 %
3 320 142.9 89.3 -37.5 % 4 %
3 1024 268.8 178.2 -33.7 % 10 %

Kernel-level numbers and the roofline are in ROCm/aiter#8381.

Benchmark script (run from the repo root on one gfx950 GPU with ROCm/aiter#8381 installed)
# Graph-replay A/B of AiterMxfp4Experts.apply: aiter.fused_moe (flag off) vs the
# FlyDSL a8w4 experts op (flag on), DeepSeek-V4.1-Flash shapes, weights of
# LAYERS layers rotated so no layer's weights stay in the MALL.
#   python bench.py '<json [[local, global, topk, [tokens...]], ...]>' [lift]
# "lift" raises the EP8 token caps to 1024 (to show why they exist).
import json
import os
import statistics
import sys

import torch

os.environ["AITER_BF16_FP8_MOE_BOUND"] = "0"
os.environ["VLLM_ROCM_USE_AITER"] = "1"

from tests.kernels.moe import test_rocm_aiter_moe as T  # noqa: E402
from tests.kernels.moe.utils import make_dummy_moe_config  # noqa: E402
from vllm import envs  # noqa: E402
from vllm._aiter_ops import rocm_aiter_ops  # noqa: E402
from vllm.model_executor.layers.fused_moe.config import (  # noqa: E402
    mxfp4_w4a16_moe_quant_config,
)
from vllm.model_executor.layers.fused_moe.expert_map_manager import (  # noqa: E402
    determine_expert_map,
)
from vllm.model_executor.layers.fused_moe.experts import rocm_aiter_moe  # noqa: E402

LAYERS, CALLS, ROUNDS = 8, 24, 7


def set_flag(on):
    os.environ["VLLM_ROCM_USE_AITER_FLYDSL_MOE_A8W4"] = str(int(on))
    import importlib

    importlib.reload(envs)
    rocm_aiter_ops.refresh_env_variables()


def bench(local, glob, topk, tokens):
    layers = []
    for layer in range(LAYERS):
        w13, w2, s13, s2 = T._dsv41_flash_expert_weights(local, seed=100 * topk + layer)
        mc = make_dummy_moe_config(
            num_experts=glob,
            num_local_experts=local,
            experts_per_token=topk,
            hidden_dim=5120,
            intermediate_size=2304,
        )
        mc.swiglu_limit = 10.0
        qc = mxfp4_w4a16_moe_quant_config(w1_scale=s13, w2_scale=s2)
        layers.append((rocm_aiter_moe.AiterMxfp4Experts(mc, qc), w13, w2))
    mask = None
    if glob != local:
        _, _, mask = determine_expert_map(glob // local, 2, glob, return_expert_mask=True)
        mask = mask.cuda()
    rows = []
    for n in tokens:
        ins = []
        for c in range(CALLS):
            g = torch.Generator(device="cuda").manual_seed(1000 * n + c)
            x = torch.randn(n, 5120, device="cuda", generator=g, dtype=torch.bfloat16)
            lg = torch.randn(n, glob, device="cuda", generator=g)
            w, i = torch.topk(torch.softmax(lg, -1), topk, -1)
            ins.append((x, w, i.int()))

        def run(c):
            ex, w13, w2 = layers[c % LAYERS]
            return T._apply(ex, w13, w2, *ins[c], expert_map=mask,
                            global_num_experts=glob)

        graphs = {}
        for flag in (False, True):
            set_flag(flag)
            for c in range(LAYERS):
                run(c)  # eager first call per layer (compiles, allocates)
            torch.accelerator.synchronize()
            graph = torch.cuda.CUDAGraph()
            with torch.cuda.graph(graph):
                for c in range(CALLS):
                    run(c)
            graphs[flag] = graph
        times = {False: [], True: []}
        for _ in range(ROUNDS):
            for flag in (False, True, True, False):
                graphs[flag].replay()
                torch.accelerator.synchronize()
                st = torch.cuda.Event(enable_timing=True)
                en = torch.cuda.Event(enable_timing=True)
                st.record()
                graphs[flag].replay()
                en.record()
                en.synchronize()
                times[flag].append(st.elapsed_time(en) * 1000 / CALLS)
        base, new = statistics.median(times[False]), statistics.median(times[True])
        spread = max((max(t) - min(t)) / statistics.median(t) for t in times.values())
        rows.append((local, glob, topk, n, base, new, spread))
        print(f"E{local}/{glob} top{topk} n={n}: fused_moe {base:.1f} us, flydsl "
              f"{new:.1f} us ({(new / base - 1) * 100:+.1f}%), spread {spread:.1%}",
              flush=True)
    del layers
    torch.cuda.empty_cache()
    return rows


if __name__ == "__main__":
    if len(sys.argv) > 2 and sys.argv[2] == "lift":
        rocm_aiter_moe._FLYDSL_A8W4_EP8_MAX_TOKENS = {6: 1024, 3: 1024}
    torch.set_grad_enabled(False)
    r = []
    with torch.inference_mode():
        for local, glob, topk, ns in json.loads(sys.argv[1]):
            r += bench(local, glob, topk, ns)
    print("| local / global | top-k | tokens | fused_moe (us) | FlyDSL a8w4 (us) "
          "| change | spread |")
    print("|---|---|---|---|---|---|---|")
    for le, gl, k, n, b, f, s in r:
        print(f"| {le} / {gl} | {k} | {n} | {b:.1f} | {f:.1f} | "
              f"{(f / b - 1) * 100:+.1f} % | {s:.0%} |")

Commands used:

python bench.py '[[48,384,6,[1,4,8,12,16,32,64,96,128,160,192]],[16,128,3,[1,8,16,32,48,64,96,128]]]'
python bench.py '[[48,384,6,[192,224,256,512,1024]],[16,128,3,[128,256]]]' lift
python bench.py '[[48,48,6,[16,128,384,1024]],[16,16,3,[40,320,1024]]]'

Details

Why this is not a duplicate. Searching vllm-project/vllm PRs for "a8w4 experts flydsl", "moe_a8w4", "AiterMxfp4Experts flydsl" and "DeepSeek-V4.1 MoE flydsl rocm" finds no PR that calls this op. The AITER op itself is new in ROCm/aiter#8381.

Where the call site is. AiterExperts.apply gains a small _fast_path_experts hook, tried for calls with unquantized input. The base class returns None, and AiterMxfp4Experts overrides it. rocm_aiter_ops.flydsl_moe_a8w4() holds the flag and the lazy import, following the existing FlyDSL sparse-MLA hook.

Graph safety. The gate reads only host metadata: shapes, configs, the flag, the AITER bound and dbo_enabled(). The decision is therefore fixed per captured token count, and adds no host-device sync.

  • First call. The first eager call for a (device, local experts, top-k) runs flydsl_moe_a8w4_experts_warmup, which compiles every token tier of the op and takes seconds. It also allocates the layer's ready-counter workspace (112 KB), and under EP its global-to-local id table. vLLM's CUDA-graph warm-up runs an eager pass per batch size before capturing it, so this happens before serving. With --enforce-eager, the first eligible decode step stalls for the compile, and the other DP ranks wait for it at the all-gather.
  • Capture. If a call reaches capture before that setup, the graph stays on aiter.fused_moe, with a warning. The check comes before any kernel is enqueued.
  • EP id mapping. Under EP, the AITER experts get global ids and AITER's 0/1 expert mask. Each call adds one gather kernel (index_select), which is included in the timings above.

Concurrency. Each layer passes its own counter workspace (ready_counters=) to the op, so calls of different layers, including the target and draft models, never share counters. DBO stays excluded, because its two micro-batches can run the same layer at the same time. The op has no collectives, so a per-rank decision cannot desynchronize DP/EP ranks. Under the DP all-gather dispatch, all ranks see the same token count anyway.

Not covered:

Why an env flag. The op is not in a released AITER, and DeepSeek-V4.1-Flash end-to-end accuracy and throughput with it are still pending. When AITER ships it and the e2e results confirm it, the flag can become the default for these shapes, or be removed.

Known limitations:

  • gfx950 only.
  • The EP caps are tuned at EP8 with uniform routing. Other EP sizes keep aiter.fused_moe.
  • At EP8 top-6, 5-8 gathered rows are 3-10 % slower than aiter.fused_moe, which has a fast tuned kernel there. Under DP8 only the 8-row point occurs.
  • There is no end-to-end accuracy (lm_eval gsm8k) or vllm bench serve result yet, flag off vs on with --moe-backend aiter. That run is needed before this leaves draft.
  • The real-op test skips in CI until the pinned AITER includes [FlyDSL] [MoE] gfx950 a8w4 routed-experts op for H5120/I2304 top-6/top-3 ROCm/aiter#8381.

Related:

E2E status

End-to-end DSv4.1-Flash DEP8 AgentX results pending. In particular, gsm8k lm_eval and a low-concurrency vllm bench serve run with --moe-backend aiter, flag off vs on, have not been run yet. They will be added here, with full commands and commit IDs, before review is requested.

AI assistance (Claude Code) was used to write this change; Fangzhou Ai is the human owner and will review/defend it end-to-end.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide. (End-to-end serving and accuracy results are pending.)

🤖 Generated with Claude Code

…hind a flag

With VLLM_ROCM_USE_AITER_FLYDSL_MOE_A8W4=1 (default off), AiterMxfp4Experts
sends the calls that aiter.ops.flydsl.moe_a8w4_experts supports
(DeepSeek-V4.1-Flash routed experts: hidden 5120, intermediate 2304,
top-3/top-6, <= 63 local experts, 1-1024 tokens, SwiGLU limit 10, gfx950)
to that op instead of aiter.fused_moe. It reads the same preshuffled
weights without a copy. Under expert parallelism the global ids are mapped
to local ids with the expert mask, and the op is only used up to 192 (top-6)
/ 48 (top-3) tokens, where it was measured faster. The op is imported
lazily; AITER builds without it, other shapes, DBO, prequantized inputs and
uncompiled shapes under graph capture keep aiter.fused_moe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
@mergify mergify Bot added deepseek Related to DeepSeek models rocm Related to AMD ROCm labels Nov 20, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Nov 20, 2026
…, real-op tests

- Pass each layer's own ready-counter workspace (allocated on the first
  eager call, before capture) to the op instead of relying on the op's
  shared per-device workspace.
- Hook the op in through a small AiterExperts._fast_path_experts method
  instead of overriding apply().
- Apply the EP token caps only on EP8, where they were measured, and set
  them to 160 (top-6) and 96 (top-3) from layer-rotated measurements.
- Require AITER_BF16_FP8_MOE_BOUND <= tokens, i.e. the a8w4 path that
  aiter.fused_moe takes and the op matches.
- Check the graph-capture preconditions before enqueuing the id mapping.
- Replace the stand-in dispatch tests with a real-op parametrization
  (cap boundaries, EP4, no SwiGLU limit) that compares against the op's
  own output, and use _assert_deterministic; fixes the mypy errors.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>

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

deepseek Related to DeepSeek models rocm Related to AMD ROCm

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant