Skip to content

[HIP] Perf/opus moe sort latency - #8316

Merged
Bernard-Liu merged 10 commits into
mainfrom
perf/opus-moe-sort-latency
Nov 30, 2026
Merged

Bernard-Liu merged 10 commits into
mainfrom
perf/opus-moe-sort-latency

Conversation

@Bernard-Liu

@Bernard-Liu Bernard-Liu commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

From a token capacity of 2048 upward, the Opus MoE sort now runs as a two-launch chunked counting sort instead of four launches around an [expert, token] mesh. For routing produced by a top-k router (distinct expert ids per token) every output is unchanged bit for bit; the sort kernels' GPU time drops by a median of 42% (best 83%) across the 682 tuned fused-MoE configs on MI355X, with none slower. A token that names one expert twice keeps one route, as before. Top-k above 256, which the sorted ids cannot encode, is now rejected with an error.

 moe_sorting_opus_fwd, token capacity >= 2048
-  ClearWorkspace   zero the [expert, token] mesh
-  P0_v1            write each route into the mesh
-  P1               count the routes of each expert
-  P23              prefix-sum the experts, place routes, zero moe_buf
+  Count            one block per token group: routes per expert -> [expert, group] table
+  Place            one block per token group: expert starts from the table,
+                   place the group's routes (one per repeated expert),
+                   fill pad slots, zero moe_buf

Motivation

Fused MoE sorts routes by expert on every call. With 896 experts, top-k 16 and 4096 tokens the four sort kernels took about 26 µs, against about 105 µs for GEMM1 + GEMM2, and most of that was not work: a kernel with nothing to do still cost 3–5 µs, and each dependent round of loads from cold memory cost another 1–3 µs. The mesh path paid for four launches and several such rounds regardless of how many routes there were. This path serves nearly every tuned config at 2048 tokens and above, so the cost was shared by almost all large-batch MoE inference.

Changes

  • csrc/include/moe_sorting_opus.h: add MoeSortingChunkCountKernel and MoeSortingChunkPlaceKernel and dispatch to them when the token capacity is at least 2048 and Place's LDS ((68 + 4 * E) * 4 bytes) fits 64 KB, i.e. E ≤ 4079; otherwise the existing P0_v2 + P23 pair is used.
    • Tokens are cut into groups of 64-token chunks (at most 64 groups below 16384 tokens, 128 from there). Count writes, per expert, how many of a group's tokens route to it. Place derives every expert's padded start and its routes in earlier groups from that table, then places its own routes.
    • Within a chunk a per-expert 64-bit token bitmask in LDS gives a route's rank, so routes of one expert stay in token order.
    • A token that names one expert twice keeps one route, as in the mesh path: in Place, the route whose LDS atomic first sets the token's bit takes the slot; the others write reverse_sorted = -1 and no sorted output. Bucket padding (comm_fused_moe_runtime.py) writes rows of expert 0, so such rows do reach the sort.
    • The early weight loads in Place cover the valid tokens only: callers may pass a weights tensor shorter than the ids.
    • moe_sorting_opus() returns -1 for top-k > 256 before the chunk kernels, since the sorted ids keep the top-k slot in 8 bits.
  • csrc/py_itfs_cu/moe_sorting_opus_kernels.cu: raise for top-k > 256 (the mesh path printed a message and returned for top-k ≥ 255 from 512 tokens, which the binding ignored), and enter with AiterThrowGuard so that a failed AITER_CHECK raises a Python RuntimeError instead of aborting the process.
  • Remove MoeSortingClearWorkspaceKernel, MoeSortingMultiPhaseKernel_P0_v1, MoeSortingMultiPhaseKernel_P1, their dispatch macros, and the clear_workspace_inside_api trait flag. Also remove MoeSortingMultiPhaseKernel_P01, which nothing dispatched (on main either), with MOE_SORTING_FUSE_MP_01 and its workspace semaphore. The path below 2048 tokens and the one-shot kernel are untouched.
  • moe_sorting_opus_get_workspace_size returns the size of the count table for the chunk path, e.g. 57 KB instead of 3.67 MB at 4096 tokens / 896 experts. Below 2048 tokens it is 128 bytes smaller, without the semaphore. It is still non-zero wherever the multi-phase path is taken.
  • No change to the Python or C++ signatures, to fused_moe.py, to any GEMM, or to any tuned config.

Performance (if applicable)

Metric: sum of the GPU execution time of the Opus sort kernels inside one fused_moe call, from the per-kernel table of AITER_LOG_MORE=1. Each config row is 5 independent processes per side, base and head alternating on the same GPU, medians compared. Base is main at 120f57ea7, head is 7203b5dae, hardware is MI355X (gfx950, 256 CU). The later commits (one route per repeated expert, the top-k checks, the removal of the never-dispatched P01 kernel) are not in these runs; the overhead of the first is measured separately below.

A row counts as faster or slower only when the two sides' ranges do not overlap; otherwise it is reported as overlap, whatever the medians say.

Tuned configs with token capacity >= 2048

op_tests/test_moe_2stage.py, one single-case command per tuned row (cu_num 256, 41 config files), each with the model's own quantization type, activation and tuned kernels. 682 of the 683 rows have a result; the test itself skips the remaining one on both sides.

Hardware Workload/configuration Before After Change
MI355X (gfx950, 256 CU) 682 tuned rows, token capacity 2048–131072 — — mean −42.6%, median −42.3%, best −83.4%; 669 faster, 13 overlap, 0 slower

93 rows overlapped in the first pass and were measured a second time, which replaces the first: 80 separated, 13 overlapped again. In those 13 the head median is 13% to 52% below the base median and the overlap comes from one or two high head samples out of five; such high samples are as frequent on base as on head (about 6% of each side's samples), cause not investigated.

Per model and shape. A line covers every tuned row of that shape across the model's config files (its quantization variants); "Change" is the change of the sort time over those rows.

Model Experts / top-k Config rows Token capacity Change: mean Change: best
Beam 32 / 8 4 2048–16384 −42.8% −44.4%
DeepSeek V3 32 / 8 3 2048–32768 −41.4% −43.5%
DeepSeek V3 33 / 8 3 4096–32768 −41.8% −43.9%
DeepSeek V3 64 / 8 1 32768 −28.0% −28.0%
DeepSeek V3 128 / 8 9 2048–32768 −34.0% −42.3%
DeepSeek V3 256 / 8 10 (1 overlap) 2048–32768 −35.9% −49.1%
DeepSeek V3 257 / 9 18 2048–32768 −47.4% −61.7%
DeepSeek V4 24 / 6 6 2048–65536 −36.0% −43.4%
DeepSeek V4 48 / 6 6 2048–131072 −35.2% −47.7%
DeepSeek V4 49 / 6 4 2048–16384 −53.2% −61.1%
DeepSeek V4 256 / 6 11 2048–131072 −42.3% −61.0%
DeepSeek V4 384 / 6 16 2048–131072 −40.0% −57.9%
DeepSeek V4 385 / 7 20 2048–32768 −49.3% −62.2%
DeepSeek V4.1 16 / 3 8 (1 overlap) 2048–32768 −40.5% −45.4%
DeepSeek V4.1 24 / 6 6 2048–131072 −40.2% −51.9%
DeepSeek V4.1 25 / 7 6 2048–131072 −56.9% −83.4%
DeepSeek V4.1 32 / 2 5 2048–32768 −37.7% −52.4%
DeepSeek V4.1 32 / 3 5 2048–32768 −39.8% −48.1%
DeepSeek V4.1 48 / 6 10 2048–32768 −36.5% −44.5%
DeepSeek V4.1 96 / 6 9 2048–32768 −34.2% −46.8%
DeepSeek V4.1 128 / 3 20 2048–32768 −43.6% −50.4%
DeepSeek V4.1 384 / 6 20 (2 overlap) 2048–32768 −34.2% −42.5%
DeepSeek V4.1 385 / 7 4 2048–16384 −50.3% −63.1%
GLM-4.7 40 / 8 5 2048–32768 −49.4% −51.8%
GLM-4.7 41 / 10 5 2048–32768 −49.9% −53.8%
GLM-4.7 161 / 9 10 2048–32768 −47.1% −49.2%
GLM-5 65 / 9 2 16384–32768 −46.9% −49.0%
GLM-5 257 / 9 35 (1 overlap) 2048–32768 −49.9% −64.6%
GLM-5.3 288 / 8 5 2048–32768 −41.1% −43.5%
GLM-5.3 Flash 37 / 10 4 2048–16384 −49.4% −54.1%
GLM-5.3 Flash 72 / 8 4 2048–16384 −45.3% −49.3%
GLM-5.3 Flash 73 / 10 4 2048–16384 −46.4% −48.9%
GLM-5.3 Flash 145 / 10 4 2048–16384 −47.8% −50.0%
GLM-5.3 Flash 288 / 8 20 (1 overlap) 2048–16384 −41.2% −51.0%
GLM-5.3 Flash 289 / 9 24 2048–16384 −42.2% −59.6%
gpt-oss 128 / 4 20 2048–32768 −38.1% −47.3%
K2 Horizon 375B 192 / 8 12 2048–65536 −30.4% −38.7%
Kimi K2 384 / 8 39 2048–131072 −33.6% −52.3%
Kimi K2 385 / 9 36 (1 overlap) 2048–131072 −47.1% −71.9%
Kimi K3 56 / 16 6 2048–131072 −51.5% −62.3%
Kimi K3 112 / 16 5 2048–32768 −45.6% −52.3%
Kimi K3 112 / 17 5 2048–32768 −44.4% −50.3%
Kimi K3 896 / 16 23 (3 overlap) 2048–32768 −30.6% −45.2%
MiMo v2.5 Pro 384 / 8 7 (1 overlap) 2048–131072 −42.0% −56.5%
MiniMax M2.5 64 / 8 5 2048–32768 −36.3% −40.3%
MiniMax M2.5 256 / 8 35 (1 overlap) 2048–32768 −36.0% −50.4%
MiniMax M3 128 / 4 10 2048–32768 −37.6% −40.2%
MiniMax M3 129 / 5 25 2048–32768 −52.9% −66.0%
Mistral Large 4 128 / 4 12 2048–8192 −41.9% −59.0%
Muse Spark 32 / 1 1 2048 −42.0% −42.0%
Muse Spark 32 / 2 5 2048–32768 −37.3% −43.7%
Muse Spark 256 / 1 5 2048–32768 −42.1% −45.3%
Qwen3-235B 16 / 8 5 2048–32768 −49.4% −54.2%
Qwen3-235B 128 / 8 6 2048–32768 −34.8% −41.0%
Qwen3-Next 80B 512 / 10 15 2048–32768 −45.9% −53.3%
Qwen3-Next 80B 513 / 11 15 2048–32768 −53.2% −60.9%
Qwen3-VL 16 / 7 5 2048–32768 −50.7% −54.2%
Qwen3-VL 32 / 7 5 2048–32768 −50.6% −53.3%
Qwen3-VL 64 / 7 5 2048–32768 −46.2% −48.2%
Qwen3-VL 128 / 8 5 (1 overlap) 2048–32768 −31.7% −40.5%
Qwen3.5-397B 512 / 10 10 2048–32768 −46.1% −51.4%
Qwen3.5-397B 513 / 11 13 2048–32768 −53.5% −66.2%
Qwen3.8 2400B 512 / 10 4 2048–16384 −44.9% −50.9%
Qwen3.8 2400B 513 / 11 5 2048–32768 −53.3% −61.4%
Qwen3.8 Flash 513 / 11 12 2048–16384 −49.6% −58.2%
All 682 −42.6% −83.4%

The rest of the call (every non-sort kernel) changed by a median of +0.04%: 679 rows overlap, 2 are faster and 1 is slower (MiniMax M3 fp4, 129 / 5 at 16384 tokens: +0.8% and +2.5% in the two passes, about 6 and 20 µs, next to a sort saving of 22 µs; not investigated).

Expert-parallel calls (expert mask, valid token count below the capacity)

op_tests/test_moe_ep.py in the version of the EP32 branch (it adds -a/--activation), cases g1u1_a8w4_mxfp4 and g1u1_a4w4_mxfp4, one command per EP row of the tuned configs with token capacity >= 2048: 157 rows, same protocol. To hit a tuned row the command uses the row's local expert count times the EP degree as the global expert count, so these are the tuned shapes, not the models' real routing.

128 rows dispatched to their tuned kernel and ran the new sort kernels: mean −38.6%, median −41.0%, best −56.4%; 126 faster, 2 overlap (in both passes), 0 slower. The other 29 are not counted: 21 fell back to a default kernel and 9 rows at 2048 tokens were rounded below 2048 by the script and ran the unchanged path (1 row is in both groups). The rest of the call changed by a median of −0.01%, with no row slower.

Model Local experts / top-k Config rows Token capacity Change: mean Change: best
DeepSeek V3 32 / 8 1 2048 −45.7% −45.7%
DeepSeek V3 33 / 8 2 4096–32768 −48.2% −48.8%
DeepSeek V4 24 / 6 6 2048–65536 −30.3% −44.0%
DeepSeek V4 48 / 6 6 2048–131072 −34.0% −44.8%
DeepSeek V4 49 / 6 4 2048–16384 −49.4% −50.4%
DeepSeek V4.1 16 / 3 6 (1 overlap) 4096–32768 −23.7% −41.0%
DeepSeek V4.1 24 / 6 6 2048–131072 −33.0% −47.2%
DeepSeek V4.1 25 / 7 4 4096–32768 −46.5% −53.3%
DeepSeek V4.1 32 / 2 4 (1 overlap) 4096–32768 −26.4% −43.2%
DeepSeek V4.1 32 / 3 4 4096–32768 −26.9% −42.5%
DeepSeek V4.1 48 / 6 10 2048–32768 −36.0% −45.4%
DeepSeek V4.1 96 / 6 9 2048–32768 −40.7% −45.2%
DeepSeek V4.1 128 / 3 12 4096–32768 −34.1% −44.6%
GLM-5 65 / 9 2 16384–32768 −50.9% −51.4%
GLM-5.3 Flash 37 / 10 4 2048–16384 −54.1% −56.4%
GLM-5.3 Flash 72 / 8 4 2048–16384 −45.9% −48.2%
GLM-5.3 Flash 73 / 10 4 2048–16384 −52.6% −55.0%
GLM-5.3 Flash 145 / 10 4 2048–16384 −46.9% −48.0%
Kimi K3 56 / 16 6 2048–131072 −43.2% −47.0%
Kimi K3 112 / 16 5 2048–32768 −52.5% −53.8%
Kimi K3 112 / 17 5 2048–32768 −35.8% −42.4%
Muse Spark 32 / 2 5 2048–32768 −33.2% −49.2%
Qwen3-VL 16 / 7 5 2048–32768 −35.6% −41.8%
Qwen3-VL 32 / 7 5 2048–32768 −40.1% −41.9%
Qwen3-VL 64 / 7 5 2048–32768 −39.5% −43.6%
All 128 −38.6% −56.4%

Known weak spot: EP rows at 32768 tokens with top-k 2 or 3 gain little. The two overlapping rows are DeepSeek V4.1 rows of this kind (−1.4% and −3.8%); the other rows of this kind gain 4% to 8%. Where the remaining time goes has not been measured.

Overhead of keeping one route per repeated expert

Standalone HIP-graph replay of moe_sorting_opus() on MI355X, chunk path, router-like ids, 7203b5dae against the head, 5 + 5 processes alternating, medians:

Tokens / experts / top-k 7203b5dae (µs) Head (µs) Change
4096 / 256 / 8 14.857 14.929 +0.5%
16384 / 256 / 8 19.713 19.835 +0.6%
4096 / 896 / 16 17.145 17.152 +0.0%
32768 / 896 / 16 39.552 39.563 +0.0%
32768 / 112 / 17 31.748 32.313 +1.8%

The ranges overlap on every row. The top-k checks are host-side integer comparisons.

Known limitations

  • E ≥ 4080 from 2048 tokens falls back to P0_v2 + P23, where each expert's block scans every route. This is slower than main's P0_v1 + P1 + P23: at E = 4096, top-k 8, +21% to +27% at 4096 tokens and +61% to +106% at 16384 tokens (two measurements with different inputs and GPUs). No current model reaches this expert count.

Testing

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

Tested on MI355X (gfx950) only; see "Validation and unverified scope".

Documentation

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

The sort's interface and its outputs for valid routing are unchanged; the algorithm and the input contract are described in the header comment above the new kernels.

Dependencies

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

Breaking Changes

  • A token that names one expert twice still keeps one route. On the chunk path (token capacity ≥ 2048, E ≤ 4079) the kept one is the first route to set the token's bit; the mesh path kept whichever store landed last, so the top-k slot and weight in that sorted slot can differ from main. Neither choice was specified.
  • Top-k > 256 now raises a RuntimeError in moe_sorting_opus_fwd, and moe_sorting_opus() returns -1 on the chunk path. Before, depending on the token count, the sort wrote wrong top-k slots or printed a message and left its outputs unwritten.
  • Every failed check in moe_sorting_opus_fwd now raises a RuntimeError instead of aborting the process.
  • None for callers that size the workspace with moe_sorting_opus_get_workspace_size, as fused_moe.py does. The value it returns for a token capacity of 2048 and above is now much smaller, and 128 bytes smaller below; a caller that hard-codes the old size still works (the buffer is larger than needed), one that asserts on the exact value does not.

PR Self-Review

Reviewed revision

e4a52065542ace2f5970ae0b4b05a2ffc1554299

Behavior and intent

For router output (distinct expert ids per token), behavior visible to callers does not change: sorted token ids, weights, expert ids, the valid counts, the zeroed range of moe_buf, rank-local expert ids and both auxiliary outputs are bit-identical to main. A token that names one expert twice keeps one route as before, possibly a different one of the repeats. What changes is how the sort is computed from 2048 tokens upward (two launches, no mesh), how large its workspace is, and that top-k > 256 is rejected with an error. The existing path spent most of its time on per-launch cost and cold loads rather than on routes.

Validation and unverified scope

Hardware: MI355X, gfx950, 256 CU. Base main at 120f57ea7.

Verified:

  • Outputs vs main: 480 cases (15 shapes × no mask / contiguous mask / random mask / empty mask × full, equal, smaller and zero valid token count × with and without invalid expert ids), every output hashed in separate processes for base and head: 0 differ. Run at 7203b5dae.
  • python op_tests/test_moe_sorting.py (default matrix) at 7203b5dae: exit code 0, 386 summary rows, cuda-graph capture/replay passes for both FlyDSL and Opus.
  • Accuracy in full calls: logits_diff from test_moe_2stage.py is identical between base and head on 445 of the 682 rows and differs below the printed precision on most others; 6 rows differ by more than 0.1% relative, not investigated. 20 mxfp8 rows exceed 1e-3 on both sides equally. From test_moe_ep.py, logits_diff is identical on all 157 EP rows.
  • Out-of-bounds read fixed in 7203b5dae: with a weights tensor shorter than the ids, the previous revision faulted on 3 of 5 inputs; the head passes all 5, and the contract test now uses such a tensor.
  • Repeated experts, standalone HIP check at the head: chunk path at 4096 tokens / 256 experts / top-k 8 with and without an expert mask, at 32768 tokens / 112 experts / top-k 17, and the mesh path at 1024 tokens; inputs with plain repeats, three routes of one expert, and trailing rows of expert 0 as bucket padding writes them. Every routed (token, expert) keeps exactly one route, whose slot holds its token, top-k slot and weight; the others have reverse_sorted = -1; the token field of every sorted slot, the valid counts and the sorted expert ids are identical to main. The same check fails on 7203b5dae (two routes in one slot).
  • Top-k limit, at the head: moe_sorting_opus() returns -1 for top-k 257 at 2048 tokens; calling moe_sorting_opus_fwd from C++ with top-k 257 throws and restores the throw mode afterwards; top-k 255 and 256 at 2048 tokens run and write their outputs.

Not verified:

  • Any architecture other than gfx950. The LDS layout reserves room for wave32 targets, by reading only.
  • 8 Kimi K3 a16w4 rows (SiTUv2 with bf16 activations is not runnable from test_moe_2stage.py); they ran a fallback kernel and are included in the 682 only as sort timings. 1 Qwen3.8 2400B row at 32768 tokens is skipped by the test itself on both sides.
  • 29 of the 157 EP rows did not exercise the new kernels: 21 fell back to a default kernel and 9 rows at 2048 tokens were rounded below 2048 by the script (1 row is in both groups).
  • Rows below 2048 tokens were not re-measured; that path is not changed. The 2048 threshold is unchanged.
  • Top-k 255 and 256 from 2048 tokens run and write their outputs, but the outputs were not compared with a reference.
  • The two new op tests were not run (no PyTorch on the validation machine); they pass black and ruff 0.16.0, and the standalone checks above cover the same behavior.
  • Whole-call time: on 59 of the 682 rows the whole-call median is higher on the head, in every case with overlapping ranges, where run-to-run variation of the GEMMs (hundreds of µs on calls of 10 ms and more) exceeds the sort's saving.
  • The performance runs predate the handling of repeated experts and top-k, and the removal of the P01 kernel (see Performance).

PR-specific question

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

The host selects the chunk kernels per call when all of the following hold:

  • int32 topk_ids and fp32 topk_weights (the binding checks the weights; the dispatch handles only this pair);
  • the multi-phase path is taken, i.e. moe_sorting_opus_get_workspace_size(...) is non-zero (dispatch policy 2, or 0 when the automatic policy prefers multi-phase);
  • token capacity topk_ids.shape[0] ≥ 2048. num_local_tokens does not enter the choice, so a captured CUDA graph keeps its path on replay;
  • Place's LDS, (68 + 4 * E) * 4 bytes, fits 64 KB, the host-side opus::get_smem_size() on every target: E ≤ 4079.

There is no architecture-specific code in the new kernels; they were validated on gfx950 only. Below 2048 tokens the unchanged P0_v2 + P23 pair runs; from E = 4080 the same pair runs as a fallback (slower, see Known limitations).

Unsupported inputs:

  • Top-k > 256 is rejected before any launch: moe_sorting_opus_fwd raises, moe_sorting_opus() returns -1 ahead of the chunk kernels. This also bounds Place's per-thread owner mask to 16 routes per chunk.
  • A token naming one expert twice keeps one route. Count counts the token once per expert; in Place, the repeats fall in one 64-token chunk, the first LDS atomic on the token's bit takes the slot, and the others write reverse_sorted = -1 and no sorted output, so slot counts and slots agree.
  • Expert ids outside [0, E) and rows at or past num_local_tokens are not routed (-1 in reverse_sorted and local_topk_ids), as before; weights are read for valid tokens only.
  • Count's per-group counters cannot overflow: entries are 8-bit only while a group holds at most 3 chunks (192 tokens), 16-bit otherwise, and a group holds at most 1023 chunks (65472 tokens).

Changed op tests

op_tests/test_moe_sorting.py:

  • test_moe_sorting_opus_contract (new): calls the binding directly on shapes real models use (896 experts / top-k 16 / tile height 96 with a rank's contiguous share of the experts, among others) and checks every output bit for bit, including what no existing test looked at: the zeroed range of moe_buf, zero pad weights, rank-local ids and both auxiliary outputs. It passes a weights tensor holding the valid tokens only, which catches reads past it. It passes on main as well, so it pins the behavior the rewrite keeps.
  • test_moe_sorting_cuda_graph_capture (was test_moe_sorting_flydsl_cuda_graph_capture): takes a backend argument and the main loop now runs it for Opus too. Not redundant: the Opus sort reads the valid token count on the device, and nothing checked that a replay with a different count than the captured one gives the right result.
  • test_moe_sorting_opus_repeated_experts (new): rows that repeat an expert, rows of expert 0 as bucket padding writes them, and repeats of experts outside the rank's mask, at 4096 tokens (chunk path) and 1024 tokens (mesh path). Checks that each routed (token, expert) keeps one route, that its slot holds its token, top-k slot and weight, and that the sorted tokens equal a sort of the ids without the repeats. Not redundant: every other test draws ids with topk, which never repeats an expert.
  • test_moe_sorting_opus_topk_limit (new): top-k 257 raises a RuntimeError from the binding. Not redundant: no test covered the top-k limit.
  • Two comments that named the removed kernels are updated.

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

@Bernard-Liu
Bernard-Liu force-pushed the perf/opus-moe-sort-latency branch from 8534125 to eb3ff25 Compare November 20, 2026 06:49
@Bernard-Liu
Bernard-Liu marked this pull request as ready for review November 23, 2026 08:55
@Bernard-Liu
Bernard-Liu requested review from a team and a balanced review from Copilot November 23, 2026 08:55
@github-actions github-actions Bot changed the title Perf/opus moe sort latency [HIP] Perf/opus moe sort latency Nov 23, 2026
@github-actions github-actions Bot added the HIP label Nov 23, 2026
@aiter-bot

aiter-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 7a937974ae54 · 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.

Copilot AI 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.

🟡 Changes recommended

The chunk path has critical correctness issues: duplicate expert IDs cause write races and double-counted output, while topk values above 256 bypass validation and produce incorrect packed route slots.

2 open issues
What changed in this PR

This PR reduces Opus MoE sorting overhead in fused-MoE inference by replacing the large-token mesh path with a two-launch chunked counting sort, without changing public call signatures.

Changes:

  • Add Count and Place kernels for token capacities of at least 2048 when shared memory permits, retaining a mesh fallback.
  • Reduce workspace requirements and remove obsolete sorting kernels and the workspace-clear trait flag.
  • Add output-contract tests, including shorter weight tensors, and extend graph capture/replay coverage to Opus.
File Description
op_tests/​test_moe_sorting.py Adds contract checks and Opus graph replay coverage; updates comments naming removed kernels.
csrc/​py_itfs_cu/​moe_sorting_opus_kernels.cu Removes the obsolete workspace-clear flag from binding arguments.
csrc/​include/​moe_sorting_opus.h Implements chunked sorting, updates dispatch and workspace sizing, and removes the superseded mesh stages.

Review effort: Balanced

Comment thread csrc/include/moe_sorting_opus.h Resolved
Comment thread csrc/include/moe_sorting_opus.h Resolved
@yzhou103

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

ci green.

Comment thread csrc/include/moe_sorting_opus.h Resolved
Comment thread csrc/include/moe_sorting_opus.h Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:21
@github-actions github-actions Bot changed the title [HIP] Perf/opus moe sort latency [HIP] [CK] Perf/opus moe sort latency Nov 25, 2026
@github-actions github-actions Bot added the CK label Nov 25, 2026

Copilot AI 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.

🔵 Needs a closer look

Critical unresolved bugs cause duplicate expert routes to race and be counted twice during reduction, while top-k values above 256 overflow the packed slot field and select incorrect route data.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:33

Copilot AI 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.

🟡 Changes recommended

A permitted all-NaN router output can trigger a device trap in the sorter, and the new top-k boundaries lack regression coverage despite fallback paths that leave outputs unwritten.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread csrc/include/moe_sorting_opus.h Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 08:12

Copilot AI 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.

🟡 Changes recommended

Missing top-k 255/256 tests for chunk and mesh-fallback paths leave the advertised supported range unverified, particularly because the binding discards fallback failures.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread csrc/include/moe_sorting_opus.h Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 09:09
@github-actions github-actions Bot changed the title [HIP] [CK] Perf/opus moe sort latency [HIP] Perf/opus moe sort latency Nov 25, 2026
@github-actions github-actions Bot removed the CK label Nov 25, 2026

Copilot AI 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.

🟡 Changes recommended

Accepted fallback inputs at top-k 255–256 can silently return unwritten outputs because the binding ignores dispatch failure.

3 open issues

Review effort: Balanced

Comment thread csrc/include/moe_sorting_opus.h Resolved
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:21

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because newly accepted top-k 255/256 outputs can produce negative input-row offsets in downstream consumers, while rejection-only boundary tests leave successful-path correctness unverified.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@Bernard-Liu
Bernard-Liu force-pushed the perf/opus-moe-sort-latency branch from 5324143 to 7a93797 Compare November 26, 2026 07:50
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:50

Copilot AI 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.

🟡 Changes recommended

Newly accepted top-k 255/256 configurations cause signed-ID decoding to select negative or incorrect MXFP scale rows, and successful boundary and scale-gather regression tests are missing.

2 open issues

Review effort: Balanced

Comment thread csrc/include/moe_sorting_opus.h Resolved
Comment thread csrc/include/moe_sorting_opus.h Resolved
@Bernard-Liu
Bernard-Liu merged commit b835334 into main Nov 30, 2026
66 checks passed
@Bernard-Liu
Bernard-Liu deleted the perf/opus-moe-sort-latency branch November 30, 2026 01:49
charlieguo1106 added a commit that referenced this pull request Nov 30, 2026
- fused_moe.py takes main's version: main moved the sort helpers to
  aiter/moev2/segments/sort.py, which now allocates the persist-es expert
  table (AITER_MXFP4_G2_ES=1) and passes it to the Opus sort.
- moe_sorting_opus.h: from 2048 tokens main sorts with the chunk kernels
  (#8316), which did not write the expert table. The chunk Place kernel now
  writes it from one more workgroup, after the groups' ones. The counting
  sort is shared with the multi-phase P23 kernel
  (impl::moe_sorting_write_expert_info).
- mxmoe_dispatcher.py: main launches the GEMM2 through the AOT cache
  (#8600), so the launcher has no _cf after a launch. The persist-es grid
  takes its blocks per CU from a compile-only flyc.compile, before the
  first launch.

Sort outputs and expert table (GLM-5.2 routing, 512 to 16384 tokens) match
the previous commit. Persist-es route rows byte-identical to the previous
persist-es; fused_moe outputs with and without AITER_MXFP4_G2_ES
byte-identical (2k, 4k). GLM-5.2 GEMM2, MI355X, one GPU, cold, us, mean of
3 rounds, against the previous commit:

                          2k     4k
  fp4 route rows   prev 101.3  134.6
                   new  100.5  134.3
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.

6 participants