Skip to content

[FlyDSL] [JIT] comm fused moe stage2 reducescatter for dsv4 dpa - #5907

Merged
yifehuan merged 6 commits into
mainfrom
yifehuan/comm_fused_moe_stage2_reducescatter
Oct 13, 2026
Merged

yifehuan merged 6 commits into
mainfrom
yifehuan/comm_fused_moe_stage2_reducescatter

Conversation

@yifehuan

@yifehuan yifehuan commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The second MoE GEMM and its following collective form a critical serving path
for DeepSeek-V4. Executing GEMM2, all-reduce/reduce-scatter, and the
shared-expert add independently leaves avoidable launch, memory-traffic, and
synchronization overhead, while production DPA introduces ragged per-rank token
counts that fixed-layout kernels cannot represent efficiently.

This PR turns the comm-fused MoE Stage2 path into a production-ready Aiter
runtime. It provides tuned Mega, Direct, and Window collective families across
the serving token range; supports compact ragged reduce-scatter; unifies tuning
and runtime configuration; makes synchronization and backend capabilities
explicit; and preserves the existing Stage2 callback ABI for downstream users.

For the production DeepSeek-V4 shape, a clean-cache, skew-routing TP8 re-run
shows 19.88%–77.47% speedup for low-token Mega all-reduce,
41.79%–119.66% for Window all-reduce, and 24.10%–86.77% for Window
reduce-scatter. Direct reduce-scatter measured through the production-equivalent
external-reuse synchronization path improves M128, M512, and M1024 by
1.33%, 2.11%, and 6.30%, respectively. Downstream DPA serving
improves throughput by 6.39%–10.18% across concurrency 64–1024 with GSM8K
accuracy preserved.

Technical Details

Tuned Stage2 collective families

  • Integrate and tune three complementary kernel families:
    • Mega for low-token all-reduce buckets.
    • Direct for latency-sensitive BF16 reduce-scatter plus shared-expert add.
    • Window for larger all-reduce and reduce-scatter workloads.
  • Improve Window producer scheduling, collective ordering, cache policy, local
    worker assignment, and drain behavior.
  • Support dynamic route scaling and native compact MXFP4 communication payloads
    for validated configurations.
  • Keep eager and CUDA graph execution on the same runtime selection path with
    graph-safe workspace ownership and lifetimes.

Unified configuration and runtime selection

  • Make the standard model tuned FMoE CSV the single source of truth for both
    ordinary and comm-fused winners.
  • Extend ShapeKey and the tuner schema with collective type, shared-add, and
    backend configuration metadata.
  • Align tuner output with production lookup so a tuned row can be consumed
    directly by the runtime.
  • Expose the shared bucket_for() helper and explicit runtime capabilities such
    as supports_ragged_m and supports_external_reuse_sync.
  • Remove superseded standalone comm-fused winner/untuned CSVs, legacy JIT config
    alias plumbing, and obsolete atomic/output-shard experiments.

Compact ragged reduce-scatter

  • Accept reduce_scatter_sizes and compute each rank's real local_rows and
    rank_offset.
  • Select the kernel bucket from the maximum loaded rank while keeping the actual
    input compact.
  • Return only the calling rank's real rows instead of a padded shard.
  • Advertise layout support through an explicit capability contract so callers
    can select compact or fixed-layout collection without implementation-specific
    probing.

Synchronization and callback compatibility

  • Add explicit external reuse synchronization for Direct kernels. An enclosing
    DPA input gather can prove that every peer consumed the previous partial
    buffer, allowing the production path to skip a redundant standalone wait.
  • Retain the internal fallback synchronization for callers that cannot provide
    that proof.
  • Separate producer/consumer synchronization for the Stage2 input and
    shared-expert add, and simplify the Direct reduction/add path.
  • Preserve the legacy zero-argument before_stage2() callback and add the
    explicit row-aware before_stage2_for_rows(rows) callback. Supplying both is
    rejected to keep behavior unambiguous.

Commit Breakdown

Commit Purpose
9b5921ad — refactor(comm-fused-moe): load winners from tuned fmoe configs Establishes one configuration source of truth. It moves comm-fused winner metadata into the standard tuned FMoE rows, extends the shape/tuner schema with collective metadata, aligns tuning output with runtime lookup, and removes the separate winner/untuned CSV plus legacy JIT config alias plumbing.
144cf44f — feat(comm-fused-moe): optimize Stage2 collective fusion Implements the main production kernel/runtime optimization. It integrates tuned Mega, Direct, and Window AR/RS paths; adds BF16 Direct RS + shared add; optimizes Window scheduling, ordering, cache behavior, synchronization, route scaling, and graph-safe workspaces; supports validated compact MXFP4 payloads; and removes superseded atomic/output-shard experiments.
f3fff4c1 — feat(comm-fused-moe): support ragged reduce-scatter layouts Adds compact ragged RS semantics through reduce_scatter_sizes, per-rank row/offset calculation, max-loaded-rank bucket selection, and exact local-row output. It also introduces the explicit ragged-layout capability used by downstream integrations.
82d101a8 — perf(comm-fused-moe): streamline direct reuse synchronization Adds the external reuse-synchronization contract for Direct kernels. Production callers can reuse an enclosing gather as the cross-rank consumption proof and remove the redundant wait, while other callers retain the safe internal synchronization path.
90268259 — fix(comm-fused-moe): preserve Stage2 callback ABI Restores the legacy zero-argument callback unchanged and adds before_stage2_for_rows(rows) for consumers that need the exact output size. It rejects simultaneous callback forms and guarantees that current ATOM remains compatible while the row-aware ATOM integration lands.

Test Plan

  • Run TP8 comm-fused MoE correctness across representative Mega, Direct, and
    Window buckets, including uneven and skewed rank distributions.
  • Cover eager and CUDA graph execution, repeated graph replay, shared-expert
    addition, compact ragged RS, fixed-layout fallback, and synchronization reuse.
  • Run the tuning/lookup flow against the unified model FMoE CSV.
  • Compare ordinary GEMM2 + collective + shared add with every positive tuned
    production winner and focused production synchronization paths.
  • Validate downstream DeepSeek-V4-Pro DPA serving with dashboard-aligned
    A/B/A/B/A/B performance and full GSM8K.
  • Validate legacy and row-aware callback contracts, including current ATOM main
    against the new Aiter runtime.

Test Result

Single-operator performance

The table below replaces the earlier CSV-derived figures with measured results
from the current branch. The common shape is gfx950, 256 CUs, hidden size
7168, local intermediate size 384, 384 experts, top-k 6, TP8. Mega and Window
were re-run with a clean Aiter/FlyDSL cache and skewed routing. Direct uses the
external-reuse synchronization contract exercised by DPA production. Each
number covers Stage2 + collective + shared-expert add; speedup is
ordinary / comm-fused - 1.

Tokens (M) Collective Family Ordinary Comm-fused Speedup
1 AR Mega 20.6734 us 14.4418 us +43.15%
2 AR Mega 26.3707 us 14.8594 us +77.47%
4 AR Mega 22.2335 us 14.7302 us +50.94%
8 AR Mega 21.2186 us 14.7854 us +43.51%
16 AR Mega 25.0727 us 20.9146 us +19.88%
128 RS Direct 68.3820 us 67.4816 us +1.33%
512 RS Direct 137.3245 us 134.4922 us +2.11%
1024 RS Direct 195.5465 us 183.9565 us +6.30%
4096 AR Window 499.6208 us 352.3720 us +41.79%
4096 RS Window 393.7843 us 317.3006 us +24.10%
8192 AR Window 973.0854 us 559.0888 us +74.05%
8192 RS Window 682.4939 us 480.6690 us +41.99%
16384 AR Window 1937.4477 us 948.7749 us +104.21%
16384 RS Window 1331.6551 us 822.0266 us +62.00%
32768 AR Window 3792.5641 us 1726.6000 us +119.66%
32768 RS Window 2544.2404 us 1494.3613 us +70.26%
131072 RS Window 10258.4778 us 5492.6495 us +86.77%

M512 Direct is the average of three production-path runs. Direct numerical
error stayed at max_abs=0.0625 and rel_l2=0.0046–0.0047; Mega stayed at
rel_l2=0.0134–0.0150; Window RS stayed at rel_l2=0.0264–0.0267. Window AR
uses the existing FP4 aggregate validation policy (max_abs <= 3,
rel_l2 <= 0.13) and measured rel_l2=0.1224–0.1225.

Downstream DPA serving performance

DeepSeek-V4-Pro, DPA/TP8, ISL/OSL 8192/1024, random range ratio 0.8,
concurrency 64–1024, concurrency x 10 requests per leg, A/B/A/B/A/B:

Concurrency Ordinary total tok/s Comm-fused total tok/s Throughput TTFT improvement TPOT improvement
64 15,080.81 16,044.58 +6.39% 16.56% lower 5.20% lower
128 23,331.48 25,125.15 +7.69% 10.03% lower 6.97% lower
256 32,808.34 35,395.31 +7.89% 11.68% lower 6.88% lower
512 41,456.72 44,613.91 +7.62% 9.75% lower 7.24% lower
1024 48,415.08 53,341.71 +10.18% 11.01% lower 9.20% lower

Every point completed all requested requests in all six legs. Logs confirmed
comm-fused activation on all eight ranks and Window RS selection under high
load, demonstrating that the operator gains carry through to serving.

Accuracy, correctness, and graph safety

  • Full 1319-sample, 3-shot GSM8K:
    • Ordinary: flexible 0.9431 +/- 0.0064, strict 0.9447 +/- 0.0063.
    • Comm-fused: flexible 0.9522 +/- 0.0059, strict 0.9530 +/- 0.0058.
    • Both pass the 0.94 CI threshold; the comm-fused run recorded seven bucket
      activations and selected the tuned M16384 Window AR path.
  • TP8 correctness passed for M64, M1024, and M4096 in eager and CUDA graph modes.
  • M1024 completed 10 consecutive CUDA graph replays.
  • The M512 production graph path remained within the FP4 aggregate tolerance.
  • Black, Ruff, py_compile/compileall, and diff checks passed.

Downstream compatibility validation

Current ATOM main (8820e482) with new Aiter (90268259) completed full GSM8K
and two 8192/1024, concurrency-16 serving runs without runtime errors. Both
runs activated the comm-fused M16384 Window AR path. Against the recorded
ordinary mean, the combination delivered:

  • Throughput: 6650.58 -> 6887.73 tok/s (+3.57%).
  • Mean TTFT: 537.07 -> 489.89 ms (8.79% lower).
  • Mean TPOT: 20.73 -> 20.05 ms (3.28% lower).
  • GSM8K flexible/strict: 0.9492 +/- 0.0060 / 0.9500 +/- 0.0060.

The callback contract was also validated directly: legacy zero-argument calls
pass, row-aware calls pass, and providing both callbacks raises the intended
error.

Compatibility and Merge Order

Combination Result
Current/old ATOM + new Aiter Compatible and end-to-end validated
New ATOM + new Aiter Compatible
New ATOM + old Aiter Not supported
Old ATOM + old Aiter Unchanged

Merge Aiter first, then ATOM. The Aiter package declares flydsl==0.3.4.1;
the validation environment used that declared dependency.

Submission Checklist

@yifehuan
yifehuan requested a review from a team September 28, 2026 09:30
@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
multigpu 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: 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 5907 --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.

@github-actions github-actions Bot changed the title comm fused moe stage2 reducescatter for dsv4 dpa [FlyDSL] [CI] [JIT] comm fused moe stage2 reducescatter for dsv4 dpa Sep 28, 2026
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe_stage2_reducescatter branch from 804da03 to d579a5f Compare September 28, 2026 15:00
@github-actions github-actions Bot changed the title [FlyDSL] [CI] [JIT] comm fused moe stage2 reducescatter for dsv4 dpa [FlyDSL] [JIT] comm fused moe stage2 reducescatter for dsv4 dpa Sep 28, 2026
@github-actions github-actions Bot removed the CI label Sep 28, 2026
@zufayu
zufayu requested a review from coderfeli September 29, 2026 00:32
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe_stage2_reducescatter branch 2 times, most recently from 1f1c2b0 to 82d101a Compare September 29, 2026 15:32
@binding7012

Copy link
Copy Markdown
Contributor

The reuse protection of direct RS did not prevent sorting from zeroing out; the peer read a partial data that had been zeroed out or overwritten in the next round.

@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe_stage2_reducescatter branch from 9026825 to 8b06c56 Compare October 12, 2026 06:14
@yifehuan yifehuan removed the multigpu label Oct 12, 2026
Integrate and tune the direct BF16 and Window AR/RS Stage2 communication paths for DSV4 production workloads. Improve Window producer scheduling, collective ordering, cache policy, synchronization, and graph-safe workspace lifetimes, with dynamic route scaling and native MXFP4 communication payloads for validated AR winners. Remove superseded atomic/output-shard experiments and their host/test plumbing.
@yifehuan
yifehuan force-pushed the yifehuan/comm_fused_moe_stage2_reducescatter branch from 8b06c56 to 8528e03 Compare October 12, 2026 10:21

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

LGTM

@yifehuan
yifehuan merged commit 825a0ce into main Oct 13, 2026
@yifehuan
yifehuan deleted the yifehuan/comm_fused_moe_stage2_reducescatter branch October 13, 2026 03:53
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.

3 participants