Skip to content

[FlyDSL] [CI] [JIT] comm fused moe - #4985

Merged
yifehuan merged 5 commits into
mainfrom
yifehuan/comm_fused_moe
Sep 8, 2026
Merged

yifehuan merged 5 commits into
mainfrom
yifehuan/comm_fused_moe

Conversation

@yifehuan

@yifehuan yifehuan commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Communication-fused MoE currently executes the Stage2 GEMM and TP reduction as
separate operations. For decode-sized batches, kernel launches, intermediate
workspace traffic, and cross-rank synchronization account for a significant
part of the end-to-end latency.

This PR adds a config-driven FlyDSL communication-fused Stage2 path for gfx950
A8W4 MXFP4 MoE workloads. The initial production target is DeepSeek-V4 TP8
decode. Unsupported shapes and token buckets continue to use the existing
ordinary Stage2 + TP AllReduce path.

Performance

Single-operator latency

Representative TP8 graph measurements collected during development are shown
below. Each value is the median of three rounds using the maximum latency across
all eight ranks. The fused path includes GEMM2 and the TP collective; the
ordinary path includes Stage2 followed by TP AllReduce.

M Routing Ordinary (us) Comm-fused (us) Latency reduction
1 uniform 22.187 15.549 29.92%
1 skew 22.195 15.380 30.71%
2 uniform 24.050 15.679 34.81%
2 skew 23.248 15.505 33.31%
4 uniform 25.173 18.147 27.91%
4 skew 28.175 25.742 8.64%
8 uniform 30.214 25.939 14.15%
8 skew 21.864 17.116 21.72%
16 uniform 42.309 37.232 12.00%
16 skew 25.671 23.215 9.57%

The production table enables the direct comm-fused megakernel only for
M = 1, 2, 4, 8, 16. Larger buckets remain explicit ordinary fallbacks unless
a fused candidate has been separately validated and selected.

End-to-end model performance

The end-to-end comparison used DeepSeek-V4-Pro with TP8/EP1, FULL CUDA graph,
ISL=8192, OSL=1024, random-range-ratio=0.8, and concurrency
1, 2, 4, 8, 16. Each arm started the model once and ran all five concurrency
levels. Results use three adjacent A/B pairs in the fixed order
A1 -> B1 -> A2 -> B2 -> A3 -> B3, where A enables comm-fused MoE and B sets
AITER_DISABLE_COMM_FUSED_MOE=1. The reported improvements are the median of
the three paired improvements.

Concurrency Fused total tok/s Ordinary total tok/s Throughput improvement Fused median TPOT Ordinary median TPOT TPOT improvement
1 605.215 579.768 +4.123% 14.576 ms 15.188 ms +4.089%
2 1193.275 1162.718 +2.628% 14.345 ms 14.744 ms +2.629%
4 2231.085 2108.697 +5.857% 15.454 ms 16.360 ms +5.582%
8 4079.240 3888.174 +4.427% 16.862 ms 17.591 ms +4.183%
16 6661.362 6536.340 +1.782% 20.863 ms 21.249 ms +1.653%

All five concurrency levels improved both TPOT and total-token throughput. The
observed paired-median TPOT improvement is 1.65% to 5.58%, while total-token
throughput improves by 1.78% to 5.86%.

Technical Details

  • Add gfx950 A8W4 comm-fused MoE kernels under
    aiter/ops/flydsl/kernels/comm_fused_moe/gfx950/a8w4/.

    • Compose the MXMoE GEMM2 tile emitter into one persistent direct megakernel.
    • Keep the collective, completion-ticket, epoch, and graph synchronization
      protocol inside the comm-fused shell.
    • Retain Atomic and Window implementations for continued tuning without
      selecting them in the current production CSV.
    • Support TP2/TP4 direct-kernel shapes in addition to the TP8 production path.
  • Add AITER runtime and config dispatch.

    • CommFusedMoeRuntime reuses the existing routing and Stage1 implementation,
      then replaces Stage2 + TP AllReduce with a prepared fused runner.
    • Synchronize the caller and Stage2 streams when a distinct Stage2 stream is
      supplied.
    • Select implementations by GPU, CU count, shape, TP degree, and token bucket.
    • Load model-specific rows from
      configs/model_configs/*tuned_comm_fused_moe*.csv.
    • Use explicit fallback rows for buckets without a validated fused winner.
  • Add dynamic MXFP8 TP partials.

    • FP8 partial payloads carry runtime E8M0 scales; the final output remains
      BF16.
    • A compile-time row resolver lets the MXMoE producer read the existing
      comm-fused Stage2 input layout without an extra reorder kernel or workspace.
    • JIT identities include the collective and layout ABI to prevent reuse of an
      incompatible cached code object.
  • Add peer-VMM workspace handling.

    • Symmetric workspaces are aligned to 2 MiB to avoid the ROCm 7.2.4
      small-allocation peer-VMM performance cliff.
    • Reuse the existing cross-device monotonic i64 wait primitive.
    • Synchronize ranks after peer-window registration before launching kernels
      that dereference peer mappings.

Correctness and Accuracy

The current source was validated on gfx950 TP8 with ROCm 7.2.4 using the full
production matrix:

  • M = 1, 2, 4, 8, 16;
  • uniform and skew routing;
  • eager execution and three CUDA graph replays;
  • runtime padding from M=3 to the M=4 bucket;
  • a distinct Stage2 CUDA stream in eager execution.

All cases were finite and passed the error thresholds. Direct-path relative L2
error ranged from 0.013351 to 0.014934; the complete M=3 to M=4 runtime path
reported rel_l2=0.021019.

Full GSM8K regression used 3-shot evaluation over all 1,319 examples with TP8,
FULL CUDA graph, concurrency 8, and the production small-M comm-fused path:

Metric Comm-fused Ordinary Difference
strict match 1258/1319 (95.3753%) 1253/1319 (94.9962%) +5 examples
flexible extract 1257/1319 (95.2995%) 1252/1319 (94.9204%) +5 examples

The difference is smaller than the single-run statistical uncertainty; the
result is treated as evidence of no observed accuracy regression, not as an
accuracy improvement claim. Both arms completed all requests without NaNs,
rank failures, or invalid server responses.

Test Plan and Results

  • Static validation:

    • Black: passed.
    • Ruff: passed.
    • git diff --check: passed.
  • TP8 production correctness:

    torchrun --standalone --nproc_per_node=8 \
      op_tests/multigpu_tests/test_comm_fused_moe.py \
      --full \
      --graph-replays 3

    Result: all 10 production route cases plus runtime padding, distinct-stream
    execution, and graph replay passed.

  • Additional retained-kernel validation:

    • Atomic M=2048: 321.584 us ordinary versus 265.063 us fused, with
      max_abs=0.75 and rel_l2=0.02998.
    • Window M=4096 compiled and passed correctness, but was slower in the latest
      short run and therefore remains outside the production CSV.

Submission Checklist

@yifehuan
yifehuan requested a review from a team August 25, 2026 08:24
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
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; main branch always runs both MI35X and MI300X
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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 4985 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

@github-actions github-actions Bot changed the title [flydsl] comm fused moe [FlyDSL] comm fused moe Aug 25, 2026
@yifehuan
yifehuan marked this pull request as draft August 25, 2026 08:26
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch 3 times, most recently from e98477f to a289fea Compare August 31, 2026 02:08

@github-actions github-actions Bot 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.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name case


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable metadata


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable case

sorted_weights=case.sorted_weights,


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name case

sorted_weights=case.sorted_weights,


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable baseline_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name baseline_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable baseline_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name baseline_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable baseline_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name baseline_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable shared


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name shared


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable baseline_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name baseline_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable candidate_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name candidate_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable shared


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name shared


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable candidate_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name candidate_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable candidate_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name candidate_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable shared


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name shared


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_partial


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_partial


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_ar


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_partial_base


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_state


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_state


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_state_base


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_output


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_output


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable flydsl_output


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name flydsl_output


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import argparse
import json
import statistics
import flydsl.expr as fx
import torch
import torch.distributed as dist
import torch.distributed._symmetric_memory as symm_mem
from mori.cco import Communicator
from aiter.dist.parallel_state import get_tp_group
from aiter.ops.flydsl.kernels.comm_fused_moe import small_m_allreduce
from aiter.ops.flydsl.kernels.comm_fused_moe.sync import FLAT_VA_RANK_STRIDE
from aiter.ops.flydsl.kernels.tensor_shim import ptr_arg
from aiter.ops.flydsl.moe_kernels import _run_compiled
from op_tests.multigpu_tests import moe_tp_stage2_test_utils as fixtures


⚠️ [ruff] <SIM117> reported by reviewdog 🐶
Use a single with statement with multiple contexts instead of nested with statements

with get_tp_group().graph_capture() as capture_context:
with torch.cuda.graph(graph, stream=capture_context.stream):


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable launcher


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable input_flat_base


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable state


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name state


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable state_flat_base


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name output


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable output


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name output


⚠️ [ruff] <B023> reported by reviewdog 🐶
Function definition does not bind loop variable custom_input

custom_input, use_new=True, open_fp8_quant=False


⚠️ [ruff] <F821> reported by reviewdog 🐶
Undefined name custom_input

custom_input, use_new=True, open_fp8_quant=False


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import os
from dataclasses import replace
from types import SimpleNamespace
import torch
import torch.distributed as dist
import flydsl.expr as fx
from aiter import ActivationType, QuantType, dtypes
from aiter.fused_moe import (
get_2stage_cfgs,
get_padded_M,
stage2_uses_route_reduce,
)
from aiter.dist.parallel_state import get_tp_group
from aiter.ops.flydsl.comm_fused_moe_host import _barrier
from aiter.ops.flydsl.comm_fused_moe_host import _stage2_args
from aiter.ops.flydsl.comm_fused_moe_host import create_flydsl_comm_fused_runners
from aiter.ops.flydsl.kernels.comm_fused_moe import atomic_compressed
from aiter.ops.flydsl.kernels.comm_fused_moe import persistent_window
from aiter.ops.flydsl.kernels.tensor_shim import ptr_arg
from aiter.ops.flydsl.moe_kernels import _run_compiled
from op_tests.multigpu_tests import moe_tp_stage2_test_utils as fixtures


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from aiter.jit.utils.chip_info import get_gfx_runtime
from aiter.ops.flydsl.comm_fused_moe_host import ShapeKey, winners_for
from aiter.ops.flydsl.comm_fused_moe_tuner import benchmark, kid


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from aiter.ops.flydsl.kernels.comm_fused_moe import full_width as k
from aiter.ops.opus.moe_stage2_a8w4 import (
opus_moe_stage2_a8w4_decode_fwd,
)
from aiter.ops.opus.moe_stage2_a8w4_meta import (
opus_a8w4_kid_from_name,
)


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

import csv
import statistics
from dataclasses import asdict, dataclass, fields
from itertools import product
from pathlib import Path
import torch
import torch.distributed as dist
from aiter.ops.flydsl.comm_fused_moe_host import (
PipelineConfig,
ShapeKey,
create_runner,
)
from aiter.ops.flydsl.kernels.comm_fused_moe import atomic_compressed
from aiter.ops.flydsl.kernels.comm_fused_moe import full_width
from aiter.ops.flydsl.kernels.comm_fused_moe import persistent_window
from aiter.ops.flydsl.kernels.comm_fused_moe import windowed


⚠️ [ruff] <SIM905> reported by reviewdog 🐶
Consider using a list literal instead of str.split

"gfx model_dim inter_dim experts topk tp m family tile_m tile_n tile_k "
"sort_block_m window local_workers reduce_scatter_grid all_gather_grid "
"service_grid producer_workers_per_n_tile producer_ctas_per_cu_limit".split()


⚠️ [ruff] <SIM117> reported by reviewdog 🐶
Use a single with statement with multiple contexts instead of nested with statements

with tp_group.graph_capture() as capture:
with torch.cuda.graph(graph, stream=capture.stream):

@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch 4 times, most recently from 6ef3d63 to ad9c031 Compare September 2, 2026 06:51
@yifehuan
yifehuan marked this pull request as ready for review September 2, 2026 06:57
@github-actions github-actions Bot changed the title [FlyDSL] comm fused moe [FlyDSL] [CI] [JIT] comm fused moe Sep 2, 2026
@zufayu
zufayu requested a review from yadaish September 3, 2026 01:17
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch 5 times, most recently from 408ec5f to 92f7f50 Compare September 7, 2026 07:24
@yifehuan yifehuan added ci:atom ci:multi-gpu Trigger multi-GPU op tests on PR labels Sep 7, 2026
@yifehuan
yifehuan requested a review from coderfeli September 7, 2026 08:03
@yifehuan yifehuan added multigpu and removed ci:multi-gpu Trigger multi-GPU op tests on PR multigpu labels Sep 7, 2026
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch from 92f7f50 to 338e9a1 Compare September 8, 2026 03:24
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch from 338e9a1 to e643300 Compare September 8, 2026 03:28
Dispatch configured token buckets through the communication-fused runners and package the DSV4 MXFP8 winners.

Compare tuned candidates with the ordinary graph baseline and write explicit fallback rows when the fused path does not win.
Exercise the production dispatch path against ordinary MoE for uniform and skewed routing in eager and graph modes.

Run the focused eight-GPU test from the multi-GPU CI entry point.
Compose the MXMoE GEMM2 producer with direct, atomic, and window TP services under the comm-fused kernel shell.\n\nPreserve dynamic-MXFP8 partials and the existing synchronization protocol, optimize tuned small-token direct reductions, support atomic shared BF16 partials, and size window services for independent reduce-scatter and all-gather grids.
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe branch from e643300 to 41217d3 Compare September 8, 2026 10:34
@yifehuan
yifehuan merged commit c6677e0 into main Sep 8, 2026
85 of 87 checks passed
@yifehuan
yifehuan deleted the yifehuan/comm_fused_moe branch September 8, 2026 23:27
xiaofei-zheng added a commit to xiaofei-zheng/aiter that referenced this pull request Sep 16, 2026
130 commits, no conflicts. Nine of them touch aiter/fused_moe.py, including the
MXFP4 fused-MoE work in ROCm#5300, ROCm#4526 and ROCm#4985, so the three things this guard
rests on were re-checked against the merge result:

* tuned_fmoe.csv still carries no mxfp4 row with a non-256-aligned inter_dim,
  so the tuned path cannot hand an affected shape to CK-Tile behind the guard.
* The CK-Tile stage-2 scale indexing is still unfixed (ROCm#5233 open), so the
  host-side guard is still needed.
* Dispatch is unchanged: inter_dim 128/384/640 to FlyDSL, 192/320 and the
  256-aligned values on CK-Tile, with _fused_moe_impl's validation firing on
  exactly the re-routed shapes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants