Skip to content

[FlyDSL] [MoE] gfx950 a8w4 routed-experts op for H5120/I2304 top-6/top-3 - #8381

Closed
Fangzhou-Ai wants to merge 2 commits into
ROCm:mainfrom
Fangzhou-Ai:fai/dsv41f-moe-a8w4-experts
Closed

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

Conversation

@Fangzhou-Ai

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

Copy link
Copy Markdown
Contributor

Summary

This PR adds a FlyDSL op for the routed experts of one expert-parallel rank. It uses MXFP8 activations and MXFP4 weights (a8w4) and runs on gfx950. It covers hidden 5120 and intermediate 2304 with two routings:

  • top-6 with 48 local experts, an EP8 shard of 384;
  • top-3 with 16 local experts, an EP8 shard of 128.

Each call is two launches:

  1. A sort launch. It also quantizes a bf16 input to MXFP8.
  2. One fused launch:
    • GEMM1 + clamp-SwiGLU + MXFP8 requant workgroups write the intermediate in the operand layout GEMM2 loads. Each one then counts itself in its row block's ready counter.
    • GEMM2 workgroups issue their weight loads first, then wait for their block's counter. Each writes bf16(route weight * y) to its own (token, slot) row.
    • Combine workgroups sum each token's slots in slot order (fp32, one rounding).

There are no output atomics: every output element has one writer. Outputs are bitwise repeatable, and graph replay gives the same bits as eager.

Motivation

At decode token counts this layer is bound by weight streaming: one call reads 0.9 GB of MXFP4 weights and scales for 48 experts. The current a8w4 fused_moe path runs the sort, stage 1 and an atomic stage 2 as separate launches. The fused launch overlaps the end of GEMM1 with the start of GEMM2. It also keeps the requantized intermediate in GEMM2's layout and drops the atomics.

The callers this op is meant for are the ones that do not run MegaMoE at this shape:

  • non-MegaMoE callers of fused_moe (a8w4, swiglu_limit=10) at this shape, through flydsl_moe_a8w4_experts;
  • an expert-parallel dispatch other than MegaMoE that hands over its receive buffer already sorted by expert, through flydsl_moe_a8w4_experts_rows.

It does not replace MegaMoE (see Related).

Changes

  • aiter/ops/flydsl/kernels/moe_a8w4_experts.py holds the kernels: sort / block table, GEMM1, GEMM2, combine, and the fused GEMM1 + GEMM2 + combine launch.

  • aiter/ops/flydsl/moe_a8w4_experts.py is the op wrapper:

    • the token-count dispatch;
    • the eligibility check moe_a8w4_experts_supported;
    • a warm-up;
    • the ready-counter workspace flydsl_moe_a8w4_experts_workspace.

    Everything is exported lazily from aiter.ops.flydsl.

  • op_tests/flydsl_tests/test_flydsl_moe_a8w4_experts.py has two parts. The pytest correctness suite is added to the CI file lists in .github/scripts/{split_tests,aiter_test}.sh. The @benchmark sweep runs as python3 <file>.

  • op_tests/flydsl_tests/bench_flydsl_moe_a8w4_experts.py is a graph-replay A/B against aiter.fused_moe. It is not collected by pytest.

API:

from aiter.ops.flydsl.moe_a8w4_experts import (
    A8W4ExpertWeights, flydsl_moe_a8w4_experts, flydsl_moe_a8w4_experts_rows,
    flydsl_moe_a8w4_experts_warmup, flydsl_moe_a8w4_experts_workspace,
    moe_a8w4_experts_supported)

# The tensors fused_moe's a8w4 path holds, wrapped without a copy:
# shuffle_weight_a16w4(w13, 16, True), shuffle_scale_a16w4(s13, E, True),
# shuffle_weight_a16w4(w2, 16, False), shuffle_scale_a16w4(s2, E, False).
w = A8W4ExpertWeights.from_shuffled(w13, w13_scale, w2, w2_scale)
# or: A8W4ExpertWeights.from_row_major(w13, w13_scale, w2, w2_scale)  (checkpoint layouts)

flydsl_moe_a8w4_experts_warmup(w, topk)   # once per mode, before CUDA-graph capture
out = flydsl_moe_a8w4_experts(x, x_scales, w, topk_weights, topk_ids)   # bf16 [n, 5120]
  • Input x. Either MXFP8 (e4m3 [n, 5120] plus row-major e8m0 x_scales [n, 160]) or bf16 [n, 5120] with x_scales=None. Other dtypes (int8, fnuz) are rejected.
  • Routing ids. topk_ids holds local expert ids. An id outside [0, E), such as -1 padding or another rank's expert, contributes zero.
  • return_slots=True. Returns the weighted slots [n, topk, 5120] instead of their sum.
  • Rows entry. flydsl_moe_a8w4_experts_rows(x, x_scales, w, row_weights, expert_offsets, topk) takes rows already sorted by expert. Row r < expert_offsets[-1] is bf16(row_weights[r] * expert(x[r])). The rows from expert_offsets[-1] on are undefined: they are not written, and the output is allocated uninitialized.
  • Empty input. n == 0 (or R == 0) returns an empty tensor and launches nothing.
  • ready_counters=. Takes a workspace from flydsl_moe_a8w4_experts_workspace(); see Breaking Changes / limitations.

Supported shapes and dispatch rule. moe_a8w4_experts_supported(hidden, inter, num_local_experts, topk, num_tokens=None, swiglu_limit=10.0) returns True only when all of these hold:

  • the GPU is gfx950 (get_gfx_runtime());
  • hidden is 5120 and inter is 2304;
  • topk is 3 or 6;
  • there are 1 to 63 local experts, so EPLB redundant experts fit;
  • there are 1 to 1024 tokens;
  • swiglu_limit is 10, i.e. silu(min(gate, 10)) * clamp(up, -10, 10).

Callers fall back to fused_moe otherwise. Within the range, the token count picks one of four tile tiers per top-k (16-, 32-, 64- or 128-row blocks; _DISPATCH in the wrapper).

Performance (if applicable)

Setup:

  • Hardware. MI355X (gfx950), one GPU of an 8-GPU node that other jobs share.
  • Graph. Each graph holds 100 calls on distinct activations and routes. Rounds run A B B A (5 rounds x 5 replays), and the median us per call is reported. The round-to-round spread was < 1 % except where noted.
  • Inputs. MXFP8 activations (codes + e8m0). Random MXFP4 weights with scales over 6 binades. E48 uses one 0.9 GB set, which is larger than the LLC. E16 cycles four 0.3 GB sets.
  • Routing. Uniform, or skewed: odds ~ 1/(rank+1), so the hottest expert gets about 6.5x the mean rows.
  • Before. aiter.fused_moe on upstream main at this PR's base (9569fb31a): a8w4, QuantType.per_1x32, swiglu_limit=10, quant_dtype_a=fp8. It uses its own dispatch, i.e. the tuned rows in model_configs/dsv41_fp8fp4_tuned_fmoe.csv, and reads identical weight bytes. Between the base and current main there are 9 commits, and none of them touches fused_moe, the a8w4 kernels or that CSV.
  • Best tuned pair. The "best" column is, per token count, the fastest of 40 FlyDSL stage-1 / stage-2 pairs, installed as the tuned row (--baseline best).

E = 48, top-6 (bench_flydsl_moe_a8w4_experts.py --experts 48 --topk 6 --baseline default best)

Hardware Workload/configuration Before: fused_moe default (us) After: this op (us) Change fused_moe best tuned pair (us)
MI355X uniform, 16 tokens 138.2 122.7 -11.2 % 131.5
MI355X uniform, 32 tokens 147.9 132.4 -10.5 % 143.6
MI355X uniform, 64 tokens 150.1 143.9 -4.1 % 148.3
MI355X uniform, 128 tokens 160.1 143.3 -10.5 % 157.5
MI355X uniform, 192 tokens 157.0 151.0 -3.8 % 156.3
MI355X uniform, 384 tokens 286.1 170.4 -40.4 % 175.0
MI355X uniform, 768 tokens 446.6 221.2 -50.5 % 269.5
MI355X skewed, 16 tokens 113.2 100.5 -11.2 % 108.2
MI355X skewed, 32 tokens 133.2 125.3 -5.9 % 133.0
MI355X skewed, 64 tokens 153.6 141.9 -7.6 % 152.5
MI355X skewed, 128 tokens 181.9 160.4 -11.8 % 178.7
MI355X skewed, 192 tokens 192.4 179.0 -7.0 % 180.3
MI355X skewed, 384 tokens 264.6 204.1 -22.9 % 214.4
MI355X skewed, 768 tokens 440.7 268.5 -39.1 % 287.6

E = 16, top-3, 4 weight sets (--experts 16 --topk 3 --layers 4 --tokens 16 40 80 160 320 640 1024 --baseline default best)

Hardware Workload/configuration Before: fused_moe default (us) After: this op (us) Change fused_moe best tuned pair (us)
MI355X uniform, 16 tokens raises (1) 50.4 - 60.9
MI355X uniform, 40 tokens 68.2 53.3 -21.8 % 64.1
MI355X uniform, 80 tokens 67.7 60.6 -10.5 % 67.5
MI355X uniform, 160 tokens 93.5 74.8 -20.0 % 86.3
MI355X uniform, 320 tokens 144.6 85.2 -41.1 % 112.8
MI355X uniform, 640 tokens 184.0 118.5 -35.6 % 132.5
MI355X uniform, 1024 tokens 261.9 166.0 -36.6 % 173.0
MI355X skewed, 16 tokens raises (1) 47.5 - 55.9
MI355X skewed, 40 tokens 68.4 54.5 -20.3 % 63.9
MI355X skewed, 80 tokens 72.5 63.5 -12.4 % 71.8
MI355X skewed, 160 tokens 97.9 75.3 -23.1 % 90.7
MI355X skewed, 320 tokens 145.5 90.5 -37.8 % 113.3
MI355X skewed, 640 tokens 184.5 122.0 -33.9 % 133.1
MI355X skewed, 1024 tokens 259.5 164.3 -36.7 % 176.0

(1) With no tuned row for E=16/top-3 at padded M=16, fused_moe falls back to a CK stage 1, which raises NotImplementedError: CK MoE stage1 cannot apply swiglu_limit=10.0 for QuantType.per_1x32 with weight dtype torch.float4_e2m1fn_x2.

Spot check at this revision (3662841e9). The final ISA of all kernels is unchanged; the re-run is on another GPU of the shared node. Here the agreement with fused_moe is the worst cosine over all 100 calls of each graph.

Workload Before: fused_moe default (us) After: this op (us) worst cosine vs fused_moe
E48 uniform 16 / 128 / 384 / 768 140.9 / 162.4 / 288.1 / 448.0 123.6 / 149.4 / 171.6 / 230.9 >= 0.999984
E48 skewed 16 / 128 / 384 / 768 114.3 / 185.0 / 265.8 / 442.1 101.3 / 161.1 / 206.5 / 271.4 >= 0.999982
E16 uniform 40 / 320 / 1024 68.5 / 140.4 / 262.0 54.1 / 85.5 / 174.7 >= 0.999992
E16 skewed 40 / 320 / 1024 69.0 / 141.8 / 262.4 55.2 / 91.4 / 169.9 >= 0.999990

Both sides moved by up to about 4 % between the two sessions; the ordering and gaps are the same.

Roofline / limit (E = 48, uniform). The bytes per call count:

  • the weights of the touched experts: 18.8 MB each with e8m0 scales, with expected touched experts = 48 * (1 - (1 - 6/48)^T);
  • the activations in and out.

The intermediate and slot traffic is not counted because it mostly stays in L2/MALL, so these fractions are conservative. The ceiling is the 7.15 TB/s HBM read rate this machine reaches with a non-temporal dwordx4 stream (8 TB/s peak).

tokens 16 32 64 128 192 384 768
MB read 796 890 903 904 905 908 914
achieved TB/s 6.49 6.72 6.28 6.31 6.00 5.33 4.13
% of 7.15 TB/s 91 94 88 88 84 75 58
  • Up to 192 tokens the op runs at 84-94 % of the measured HBM read ceiling.
  • At 384-768 tokens the 128-row tiles are limited by MFMA issue, not HBM. The scaled FP8 x FP4 MFMA runs at the FP8 rate, and one wave per SIMD carries more than 256 VGPRs. This is the remaining headroom.

Cold start. flydsl_moe_a8w4_experts_warmup compiles 13 (top-6) or 14 (top-3) token counts per mode. Measured in sequence on one process:

Mode E48 top-6, empty FlyDSL cache E48 top-6, disk cache E16 top-3, empty cache E16 top-3, disk cache
MXFP8 tokens 9.5 s 2.6 s 7.0 s 1.9 s
bf16 tokens (after the MXFP8 mode) 2.0 s 0.6 s 1.6 s 0.5 s
rows 8.4 s 2.2 s 6.8 s 1.8 s

There is no AOT prebuild entry yet (aiter/aot/flydsl/); it is left to a follow-up. The expert count is a compile-time constant, so the entry needs the deployed counts (48, 16 and the EPLB counts).

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X: not applicable, the op is gfx950-only and moe_a8w4_experts_supported declines other archs
  • Tested on MI300X: not applicable, as above

Documentation

  • Docstrings updated: module docstrings give the numerics contract, the dispatch rule, the counter workspace and the remaining raw ops.
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below: this is a new op behind an explicit eligibility check; no existing op or guide changes.

Dependencies

  • No new third-party dependencies added. The op uses FlyDSL 0.5.0, the version requirements.txt pins.
  • New dependencies are listed and justified below

Breaking Changes

None. The op is new, and no existing op, config or dispatch changes.

Known limitations:

  • Shape coverage. Hidden 5120, inter 2304, top-3 or top-6, at most 63 local experts, at most 1024 tokens, gfx950 only.
  • Concurrent calls. The fused launch orders its work through a counter workspace that is zero between calls. Without ready_counters=, all calls on a device share one workspace. Two calls that run at the same time on one workspace (e.g. from two streams) add into the same counters. A consumer can then pass its wait early, giving silent wrong outputs. The counters can also be left non-zero, which corrupts or hangs every later call on that workspace, not only the overlapping ones. To avoid this, give each stream that may overlap another its own workspace: ready_counters=flydsl_moe_a8w4_experts_workspace(), allocated before capture. AITER_FLYDSL_MOE_A8W4_CHECK=1 synchronizes around each eager call and raises on a non-zero workspace. Sequential calls on one stream are fine, for example all layers of a forward pass, or a target model followed by its draft model.
  • Warm-up before graph capture. A mode's first call compiles its kernels; the first call on a device allocates the default workspace. A mode is MXFP8 or bf16 input, sum or slots, tokens or rows. Call flydsl_moe_a8w4_experts_warmup before capturing a graph.
  • Remaining raw ops (listed in the self-review below).
  • Numerical differences from fused_moe. Outputs differ only through rounding order: this op sums the bf16 slots in a fixed order instead of with atomics.

PR Self-Review

Reviewed revision

3662841

Behavior and intent

The PR adds a new, opt-in op. Nothing calls it until a caller checks moe_a8w4_experts_supported and switches to it.

  • What it serves. The single-rank routed-experts compute of DeepSeek-V4.1-Flash at hidden 5120 / inter 2304, top-6 (48 local experts) or top-3 (16), with a8w4 and swiglu_limit=10, on gfx950.
  • Why the existing path is not enough. The current a8w4 fused_moe path runs sort, stage 1 and an atomic stage 2 as separate launches. At these shapes this op takes 4-50 % less time per call (tables above), and at E16/top-3 with 16 tokens fused_moe raises without a tuned row.
  • What it is not. It is not a MegaMoE replacement. MegaMoE ([FlyDSL] MegaMoE small-M: DeepSeek-V4.1-Flash, any experts per rank / top-k, fused shared-expert slots #8358) fuses dispatch, experts and combine across ranks; this op is the per-rank compute for callers that do not use it.

Validation and unverified scope

All runs used MI355X (gfx950), FlyDSL 0.5.0, and PYTHONPATH=<worktree>:<flydsl 0.5.0>.

Tests and benchmarks

  • python3 -m pytest -q op_tests/flydsl_tests/test_flydsl_moe_a8w4_experts.py: 153 passed in 39 s. The suite covers:

    • every dispatch tier;
    • uniform and skewed routing;
    • graph replays with new activations, ids, weights and offsets copied into the captured buffers (top-6 and top-3, token and rows entries, bf16 input), equal to eager bit for bit and checked against the reference;
    • one graph alternating E48/top-6 and E16/top-3 calls;
    • all ids invalid (n = 1, 16, 300): zero output, zero counters;
    • duplicate ids / int64 ids / bf16 weights;
    • two streams with their own workspaces;
    • the debug counter check;
    • the sort alone;
    • GEMM1 alone over 10 tile configs;
    • the weight layouts against shuffle_weight_a16w4;
    • from_shuffled on the tensors fused_moe holds: no copy, cosine >= 0.9999 against fused_moe itself;
    • EPLB with E = 52 and 56;
    • zero-size inputs and rejected dtypes.

    Outputs are graded three ways: checkAllclose (atol scaled per row; at most 0.1 % of elements and 5 % of any row outside it), whole-output cosine >= 0.99999, and per-row cosine >= 0.9999. For scale, one zeroed output row puts 98 % of that row outside the tolerance.

  • python3 op_tests/flydsl_tests/test_flydsl_moe_a8w4_experts.py: the @benchmark sweep (tokens x {E48/top-6, E16/top-3} x {mxfp8, bf16} x {uniform, skew}). It prints the markdown table with us, TFLOPS, TB/s and the checkAllclose error.

  • bench_flydsl_moe_a8w4_experts.py: the tables above.

  • The review's adversarial script ran too: 33 checks of replay with new inputs, counters, bf16 and rows replays, invalid ids and mixed graphs. All passed.

ISA identity

The kernels now use fx.atomic_*, typed LDS pointers with fx.generic_load/generic_store, fx.rocdl.cvt_scalef32_pk_fp8_f32 and fx.rocdl.update_dpp. A CPU-only compile (COMPILE_ONLY=1, FLYDSL_COMPILE_ARCH=gfx950, FLYDSL_DUMP_IR=1) of all 63 kernels the op dispatches gives the same final ISA as before the change. Those kernels are the sort and block-table tiers, GEMM1, GEMM2, combine, and the 16 fused launches.

Not verified / remaining

  • No end-to-end model run yet.
  • No per-rank comparison against MegaMoE was measured.
  • Not tested on any arch other than gfx950.
  • No AOT entry.
  • Raw ops that remain, each with a comment at its helper:
    • the inline-asm scaled MFMA and its wait states (_mfma, _hold): the accumulators must stay in AGPRs, and LLVM's hazard recognizer does not see the inline asm;
    • the i32 buffer atomic of _poll: at the 0.5.0 pin the ROCDL dialect has no i32 buffer atomic add, and BufferAtomicAdd is an fx.copy atom without a return value;
    • the legacy buffer_ops global loads / stores and the async LDS DMA (_load8, _dma): these are gathered by token with a per-load cache policy. Moving them to fx.make_buffer_tensor + fx.copy (BufferCopy128b, BufferLoadAsyncLDS128b) is not done in this PR. It needs the same ISA-identity check, or a benchmark showing no loss.
  • The branch is 9 commits behind upstream main; it will be rebased before it is marked ready.

PR-specific question

What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?

The CI change only adds this PR's test file to two existing file lists:

  • the shard list in .github/scripts/split_tests.sh;
  • the case in .github/scripts/aiter_test.sh that runs a file with python3 -m pytest -q instead of python3 <file>.

It adds no workflow, job, secret, token, permission or label trigger. It reads no PR title, body or branch name. The file it names already runs inside the existing aiter test job with that job's permissions. So no fork PR code or text reaches a more privileged path than the test job already gives every PR's op tests.

Changed op tests

  • op_tests/flydsl_tests/test_flydsl_moe_a8w4_experts.py (new). This is the only test of this op; no canonical test covers it. Each group would fail on a specific bug:

    • the reference comparisons fail on wrong numerics, routing or tiers;
    • the new-input replays fail if the sort output, the block table or a counter went stale between replays;
    • the zero-counter checks fail if the last-consumer reset broke;
    • the fused_moe comparison fails if from_shuffled misread fused_moe's layout;
    • the stream test fails if a workspace were shared.

    CI runs it with pytest (as test_gemm2_valid_token_count.py is run). Its main() is the perf sweep for manual runs.

  • op_tests/flydsl_tests/bench_flydsl_moe_a8w4_experts.py (new). This is the graph-replay A/B against fused_moe (default dispatch or the best of 40 tuned pairs) behind the tables above. It is not collected by pytest.

Related

E2E status

End-to-end DeepSeek-V4.1-Flash DEP8 AgentX results pending.

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

🤖 Generated with Claude Code

…-3 (gfx950)

Add flydsl_moe_a8w4_experts: the routed experts of one expert-parallel
rank with MXFP8 activations and MXFP4 weights, hidden 5120, intermediate
2304, top-6 (e.g. 48 local experts of 384) or top-3 (16 of 128), up to
63 local experts and 1024 tokens per call.

Two launches per call: a sort launch (with the bf16 -> MXFP8 quant when
the input is bf16) and one fused launch in which GEMM1 + clamp-SwiGLU +
MXFP8 requant, GEMM2 + route weight and the slot-ordered top-k combine
are ordered by per-block ready counters. Every output element has one
writer (no atomics), so outputs are bitwise repeatable.

- aiter/ops/flydsl/kernels/moe_a8w4_experts.py: kernels
- aiter/ops/flydsl/moe_a8w4_experts.py: op wrapper, token-count dispatch,
  moe_a8w4_experts_supported() eligibility check, warm-up, an entry for
  rows already sorted by expert (flydsl_moe_a8w4_experts_rows)
- op_tests/flydsl_tests/test_flydsl_moe_a8w4_experts.py: pytest against a
  torch reference (added to the CI file lists)
- op_tests/flydsl_tests/bench_flydsl_moe_a8w4_experts.py: graph-replay
  A/B against aiter.fused_moe a8w4

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Fangzhou Ai <[email protected]>
@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 8381 --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.

…sts with new inputs, fx atomics / LDS pointers

Op wrapper:
- ready_counters= (flydsl_moe_a8w4_experts_workspace) lets calls that may
  overlap on one device use their own counter workspace; the docstring states
  that sharing one corrupts every later call on it, and
  AITER_FLYDSL_MOE_A8W4_CHECK=1 raises on a non-zero workspace before or
  after an eager call.
- Validate x / x_scales dtypes and the weights' device; assert the combine
  covers every token; zero tokens or rows return an empty tensor.
- The block-expert table gets one more entry: a tile also reads the next
  block's expert, which read one int32 past the end at a sort tier's count.
- Rows entry: rows from expert_offsets[-1] on are documented as undefined.

Kernels: the counters use fx.atomic_add / fx.atomic_xchg, the LDS typed fx
pointers with fx.generic_load / generic_store, the requant
fx.rocdl.cvt_scalef32_pk_fp8_f32 and the sort's scan fx.rocdl.update_dpp.
The final gfx950 ISA of all 63 kernels the op dispatches (sort, block table,
GEMM1, GEMM2, combine and the 16 fused launches) is unchanged. Each remaining
raw op has a comment at its helper.

Tests: graph replays with new activations, ids, weights and offsets copied
into the captured buffers (top-6 and top-3, token and rows entries, bf16
input), one graph alternating both layer shapes, all ids invalid, duplicate
ids / int64 ids / bf16 weights, two streams with their own workspaces, the
counter check, the sort alone, GEMM1 alone over 13 configs, the weight layouts
against shuffle_weight_a16w4, and from_shuffled on the tensors fused_moe holds
compared with fused_moe. Outputs are also graded with checkAllclose (overall
and per row); a @benchmark sweep with a markdown table runs as python3 <file>.

Benchmark: the fused_moe tuned-row key comes from get_gfx_runtime() and
get_cu_num(); agreement with fused_moe is the worst cosine over all calls.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Fangzhou Ai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant