Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical alignment and head-exchange integration issues remain, along with required coverage and separation changes.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Adds opt-in M3 sequence-parallel communication kernels and tiled MoE sorting for gfx950 workloads.
Changes:
- Adds QuickReduce reduce-scatter and head-exchange kernels.
- Adds stable, configured tiled MoE sorting with tests and benchmarks.
- Propagates
use_tiled_sortthrough fused MoE APIs.
Outstanding findings include staged-buffer alignment validation, missing head-exchange build/API registration, absent AITER reduce-scatter coverage, and the requested separation of MoE sorting from collective changes.
| File | Reviewed change |
|---|---|
op_tests/triton_tests/moe/test_moe_sorting_tiled.py |
Tiled sorting correctness and dispatch tests |
op_tests/op_benchmarks/triton/bench_moe_sorting_tiled.py |
Native-versus-tiled sorting benchmark |
csrc/pybind/sp_head_exchange_pybind.cu |
Head-exchange bindings |
csrc/pybind/quick_reduce_scatter_pybind.cu |
Reduce-scatter bindings |
csrc/kernels/sp_head_exchange.cu |
Head-exchange implementation |
csrc/kernels/quick_reduce_scatter.cu |
QuickReduce implementation |
aiter/ops/triton/moe/moe_sorting_tiled.py |
Tiled sorter wrapper and dispatch guard |
aiter/ops/triton/configs/gfx950/triton/moe/sorting_tiled/DEFAULT.json |
Tiled sorter launch configuration |
aiter/ops/triton/_triton_kernels/moe/moe_sorting_tiled.py |
Histogram, prefix, and scatter kernels |
aiter/ops/quick_reduce_scatter.py |
Public reduce-scatter API |
aiter/jit/optCompilerConfig.json |
Reduce-scatter build registration |
aiter/fused_moe.py |
Tiled-sort API propagation |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| AITER_CHECK(stage || reinterpret_cast<uintptr_t>(input.data_ptr()) % 16 == 0, | ||
| "registered head exchange input requires 16-byte alignment"); |
| PYBIND11_MODULE(AITER_EXTENSION_NAME, m) | ||
| { | ||
| AITER_SET_STREAM_PYBIND; | ||
| m.def("sp_head_exchange", &aiter::sp_head_exchange); |
|
Could you provide more context on this change as compared to existing moe sorting codebase? We already have moe routing/sorting kernels in aiter triton. How is your different/better? Is it meant to be used with aiter triton moe gemms or some other backend? |
hi @lburzawa, thanks for the review. This change targets large-prefill sorting in aiter.fused_moe. The measured workload uses FlyDSL MXFP4 two-stage GEMMs. It replaces the existing Opus/HIP sorting stage while preserving the packed token IDs, expert padding, weights, and optional auxiliary mappings expected by that pipeline. GEMM dispatch remains unchanged. The tiled implementation uses per-tile histograms, prefix sums, and parallel stable scatter to avoid Opus’s dense expert–token mesh and parallelize its long per-expert scan. Existing Triton routing implementations produce different routing metadata and gather/scatter indices, so reusing them here requires an adapter. Histogram/prefix/scatter itself is not a new algorithm. For the measured 32,768-token workload, sorting latency decreased from 72.79 µs to 42.49 µs versus Opus, with about 0.25% lower full-MoE latency. I haven't compared with existing triton sorter yet, and will provide detailed data after comparing locally. |
|
@lburzawa I have posted comparing results in PR description. |
| @@ -0,0 +1,232 @@ | |||
| # SPDX-License-Identifier: MIT | |||
| # Copyright (C) 2026, Advanced Micro Devices, Inc. All rights reserved. | |||
| """Stable MoE sorting for the M3 prefill contract selected by the caller. | |||
There was a problem hiding this comment.
Let's add a note here that the kernel is meant to be used with Flydsl MOE pipeline.
|
@whx-sjtu thanks for explanation. Let's add a comment that the kernel is meant for Flydsl MOE stack otherwise should be good to go on triton side. |
| # Explicit call-site opt-in; metadata/kernel selection is unchanged. | ||
| use_tiled_sort = ( |
There was a problem hiding this comment.
it does E==129 and model_dim==6144 check in try_m3_tiled_sort. This is redundant and can be removed
|
@coderfeli can you also review. I think this is trying to use Triton routing with FlyDSL MoE |
lburzawa
left a comment
There was a problem hiding this comment.
Good on triton side but needs a HIP/Flydsl reviewer since it's meant to be used with Flydsl MOE.
|
This PR should be split into 2. One for each each backend ie Triton/Gluon and HIP |
rahulbatra85
left a comment
There was a problem hiding this comment.
Split into 2 PRs. One for just Triton/Gluon and other for any hip/flydsl/ck related changes.
sure, will do. |
Keep the Triton tiled sorter, fused-MoE integration, configuration, tests, and benchmark in this PR. Move the unchanged QuickReduce reduce-scatter and head-exchange kernels, bindings, public wrappers, JIT registrations, and multi-GPU tests to hexwang/m3-sp-hip-collectives.
|
@rahulbatra85 Splited. Another PR is #6031 |
Fixes: - Pass token counts to the SP pack and FP8 transport Triton kernels at run time; as constexprs every new prefill length recompiled them. - Drop the MegaMoE block's placeholder scale when the next layer does not consume per-token FP8 input. - Import CacheCompiledArtifact only on torch 2.10+, where it exists. - Small batches skip the fused MegaMoE prefix and run the native MoE directly, instead of a prefix, extra copies and a routing gather. - Reset the shared MegaMoE runtime before its int32 launch epochs wrap. - Resolve the optional QuickRS op once at import. Removed: - The MegaMoE benchmark, the non-fused MegaMoE paths only it reached, MXFP8 activation and the diagnostic activation override. - Tiled MoE sort selection, which needs the unmerged ROCm/aiter#5822. - The MegaMoE experiment scripts, manifest and handoff notes. - A redundant compile-hash factor and an unrelated import reorder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| use_tiled_sort = ( | ||
| use_tiled_sort |
| @@ -0,0 +1,459 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
Lets put this file under op_tests/triton_tests/moe/moe_routing folder.
|
We will need to resolve conflict before merge. Please also check any unresolved copilot comments. |
|
No activity for 15 days, so this is now labelled |
|
Closing due to inactivity, please reopen/resubmit if still relevant. |


Summary
Add opt-in Triton tiled MoE sorting for large M3 MXFP4 prefill batches in the existing FlyDSL MoE pipeline. Per-tile histograms, prefix sums, and stable scatter produce the packed token IDs, expert padding, weights, and optional auxiliary mappings consumed by
aiter.fused_moe.use_tiled_sortdefaults toFalsefor generic callers. The eligible M3 path uses gfx950, at least 8,192 tokens, 129 experts, top-k 5, hidden size 6,144, intermediate size 768, and block size 64 with the supported MXFP4 layout. Unsupported contracts fall back through the existing dispatcher, including tuned block-128 layouts and caller-provided output buffers. ATOM selects the opt-in for supported native M3 SP layers.This PR contains six files implementing the Triton sorter and its integration. The HIP sequence-parallel collectives are in #6031; both PRs target
mainand can be reviewed and merged independently. The downstream consumer is ROCm/ATOM#2364.Evidence
After: the tiled sorter takes 41.94–42.24 µs, or 1.72–1.78× faster, while preserving the stable packed-output contract. These are the historical
67405e7fdmeasurements documented below.3.8.0+amd.rocm7.2.0.git7cb7b059, FlyDSL0.3.4.1, and pytest8.3.4. Coverage includes shape/distribution variants, dispatch boundaries, changed-input graph replay, optional auxiliary maps, and bitwise M3 MoE comparisons at 8,192, 32,768, and 65,537 tokens. The integration test accepts the tuned block-128 fallback.a70f4fef9071f8b9b2bf25884b38bb6184b4d207. Combining it with the HIP patch reconstructs that source tree exactly. Black, Ruff, andgit diff --checkpass.python -m pytest -q op_tests/triton_tests/moe/test_moe_sorting_tiled.py # 88 passedPrefill threshold and routing-distribution validation
The tiled-sort dispatch now accepts
8192 <= T < 2**24with the existing M3 contract (int32[T, 5]IDs,float32[T, 5]weights, 129 experts, hidden size 6,144, block size 64, contiguous gfx950 inputs, and no accumulation buffer).2**24is the packed token-ID format limit. The lower cutoff keeps a margin over the actual Opus fallback, including partial token tiles. The existing dtype, layout, quantization and caller-eligibility checks still apply.For more than 32 token tiles, prefix computation runs independently per expert, followed by a small expert-offset prefix. This avoids concentrating the whole expert-by-tile prefix in one GPU block and removes the regressions observed at non-power-of-two and larger token counts. The switch uses the existing JSON configuration; no environment variable is added.
Historical validation at
67405e7fd: 55 GPU tests passed, including dispatch/fallback boundaries, packed-token limits, optional auxiliary mappings, changed-input graph replay, and exact M3 MoE output comparisons at 8,192, 32,768, and 65,537 tokens. The performance matrix covers 15 token counts × 6 routing distributions × 3 seeds = 270 inputs, all passing stable-order, weight and padding checks for both sorters before and after timing. The existing Triton core is also checked and measured on the same 18 inputs at 32,768 tokens.Distributions are balanced/shuffled, balanced/clustered (identical paired expert histograms), uniform, Zipf sampling proportional to rank⁻¹·⁵ without replacement, hot-eight, and collapsed-four. Every token has four distinct routed experts from 128 plus shared expert 128. Seeds are 7, 19, and 73; expert labels are permuted per seed, routed weights are normalized, and the shared weight is 1.
Timing on gfx950, implementation
67405e7fd1f4: mean GPU latency, three trials × 16 graph replays per seed, 32 sequential calls per replay; input generation, allocation and capture are excluded. Opus and tiled receive identical inputs and emit the legacy packed output without optional auxiliary maps. Each range below spans six distribution means, each averaged over three seeds. Opus includes its internal workspace clearing.Three-way comparison at 32,768 tokens
The existing Triton column measures
sort_tokensonly; bitmatrix preparation, scratch reset, and conversion to legacy packed output are excluded. Each native call uses separate scratch, cleared before the timed interval. Values are means over the same three seeds.sort_tokensonly (µs)Merge Danger
Door: two-way
Blast Radius: sorting
The optimized dispatch is opt-in and restricted to the supported M3 contract. The standalone sorter supports additional shapes, but the production gate remains limited to the validated M3 layout. This changes the sorting stage used by the existing GEMM pipeline, so packed IDs, padding, and auxiliary mappings must remain compatible with its consumers.