Skip to content

feat(ep/v2): HIP intranode on gfx942/gfx950: token dropping, routing replay, unquantized scatter, local_expert_count, StdMoE - #1065

Open
jhchouuu wants to merge 10 commits into
mainfrom
jiahzhou/ep-v2-hip-intranode-parity
Open

jhchouuu wants to merge 10 commits into
mainfrom
jiahzhou/ep-v2-hip-intranode-parity

Conversation

@jhchouuu

@jhchouuu jhchouuu commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follows #1012. This brings the HIP intranode backend on gfx942/gfx950 to the FlyDSL feature set. It has six feature commits, each covered by a section below; the review fixes that followed are folded into those sections. gfx125x keeps refusing these features.

Dispatch drains every block's peer stores

Fixes how the portable HIP dispatch (gfx942/gfx950) publishes its peer writes before it signals each destination's token count.

Until now, the dispatch body's grid arrival was __syncthreads() followed by thread 0's atomicAdd. Warp 0 then waits for every block, fences at system scope, and stores the per-destination counts.

That system fence orders only warp 0's own stores. The other warps' peer stores could still be in flight when a destination observed its count. Those stores carry the payload rows, weights, expert ids, scale rows and reverse map. In the same situation:

  • FlyDSL drains each block with a waitcnt before it arrives.
  • The base op's docstring records stale reverse-map reads on MI355X at high occupancy.

Changes

  • Before arrival. Every block waits for its own outstanding stores (s_waitcnt 0) before it arrives at the dispatch grid barrier.
  • A drain, not a release. The drain writes nothing back from L2. On a cached cco window (CCO_UNCACHED_WINDOW=0, or ROCm 7.2.x, whose VMM path ignores the uncached type) a per-block release would be the memory model's choice. The rows are complete there without one (Testing below), and a release costs 6-40% of dispatch (Cost below), so the kernel only drains.
  • New check. test_op.py gains FRESH=1. Copies of the received rows, weights, expert ids, scales and reverse map are queued on the stream right behind the dispatch kernel, before any host sync or barrier. They must equal what the same views hold after the barrier. The intranode suite runs it on both backends.

Cost

Dispatch latency in µs, EP8, hidden 7168, topk 8, bf16, HIP, graph mode, minimum over rounds. The __threadfence_system column is the stronger fence, measured for comparison and not used.

8x MI300X

tokens/rank before this PR __threadfence_system instead
32 24.1 24.0 35.7
128 48.3 48.9 52.1
512 152.1 152.7 160.1
1024 271.4 272.7 278.8
2048 542.9 542.4 551.8
4096 1063.7 1063.6 1071.8

8x MI355X (a shared node, so minimum over four rounds)

tokens/rank before this PR
32 23.8 23.8
128 47.3 47.1
512 132.3 132.4
1024 245.6 245.5
2048 471.6 471.8
4096 917.2 916.6

A per-block __threadfence_system on a cached window, measured and not used. Dispatch latency in µs with CCO_UNCACHED_WINDOW=0, same setup, median over three rounds; main has no drain:

tokens/rank MI355X main MI355X release MI300X main MI300X release
32 26.5 32.4 23.2 42.6
128 51.1 64.1 51.2 66.8
512 131.8 164.2 146.1 179.8
1024 239.3 283.0 261.7 302.2
2048 454.1 505.1 504.4 562.5
4096 882.6 947.3 987.5 1059.5

On ROCm 7.2.4, where the window is cached by default, the release costs the same: 19.1 to 26.7 µs at 32 tokens a rank, 879.5 to 933.3 µs at 4096.

Testing

  • FRESH=1 passes on both backends, on 8x MI355X with ROCm 7.14.1 and 7.2.4, on an uncached and a cached window, up to 4096 tokens a rank.
  • It passes on main too: the missing drain never showed up as a stale read. The drain is there because the memory model asks for it, and the check guards against a regression.
  • The intranode suite runs FRESH=1 on a cached window for both backends (test_dispatch_cached_window).

Token dropping under max_total_recv_tokens

With this PR, the HIP intranode backend on gfx942/gfx950 accepts a max_total_recv_tokens below the worst case and drops the slots past it, as FlyDSL does. Until now it refused the config.

Semantics, the same as FlyDSL

  • One pool per receiving rank. The receiving rank's effective_max_recv slots are claimed first come, first served.
  • A slot past the cap:
    • is null in the dest map (world_size * effective_max_recv, the existing null);
    • sends nothing;
    • is not counted.
  • Results.
    • total_recv = min(demand, cap), and rows [0, total_recv) are dense.
    • In combine, a dropped slot contributes nothing to the token sum or to the weight fold. A token whose slots were all dropped comes back as zeros.
  • Choice of tokens. Which tokens are dropped depends on atomic order, so it varies between runs and between backends.
  • Detecting saturation. total_recv == effective_max_recv means the pool filled.

Changes

  • ep_intranode_kernel.hpp.
    • After claiming a slot, dispatch checks it against EpMaxRecv.
    • A kept slot does what it did before.
    • A dropped slot writes the null flat index, and the warp skips the publish.
    • This is behind if constexpr (EpRecvCapped(kCfg)), so uncapped configs compile the same code as before.
    • The flat-index stride stays EpMaxRecv, because every published slot is now below it.
  • ep_cfg.hpp.
    • EpRecvCapped() is new.
    • EpCfgIsValid no longer rejects a capped maxRecv.
  • MakeEpCfg. A capped config on gfx125x is refused, because the gfx125x body does not guard its slot encodes.
  • hip_backend.py.
    • The cap refusal now applies to gfx125x only.
    • The intranode op advertises recv_cap.
  • Docs. The config field documents the drop semantics, and the max_recv docstring no longer calls world_size * M the sentinel.

Tests

  • test_op.py. OP-CAP used to check only total_recv <= cap. It now checks the drop invariants, on both backends:
    • total_recv == min(demand, cap), with the demand counted from every rank's expert ids;
    • every kept dest-map entry decodes to a slot below the destination's total_recv, whose reverse-map entry names this token;
    • the kept slots over all ranks equal the sum of total_recv.
  • Combine and LEC checks.
    • Under a cap, the combine check, the weight-fold check and the local_expert_count expectation count the PEs each token kept, from the dest map. Capped runs used to skip the combine check.
    • Without a cap, they still come from the expert ids alone, and the new OP-RECV line requires total_recv to equal the demand counted from every rank's routing. A dispatch that wrongly drops a slot therefore fails, rather than lowering its own expectation.
    • The dest map is decoded only under a cap. gfx125x never caps, and its LL128 dest map is not flat-encoded.
  • New suite cases. test_dispatch_combine_v2_intranode.py adds bf16-gather-cap and hip-bf16-gather-cap (cap 1024: drops at 512 tokens a rank, none at 128), and hip-bf16-scatter-fp8-1x128-cap.
  • C++ and describe tests.
    • test_jit_core.cpp now expects a capped maxRecv to be valid.
    • test_jit_binding.py checks that a capped plan's regions shrink, or that the cap is refused on gfx125x.

Routing replay

The HIP intranode backend on gfx942/gfx950 now serves routing replay, dispatch(..., routing=handle), and advertises the replay capability. Until now the base op raised NotImplementedError for HIP.

The semantics are FlyDSL's:

  • Slots. Replay sends each (token, k) to the slot the handle's dest map names. It claims no new slot and never writes the handle's map. Null entries (dups, negative experts, slots dropped under a recv cap) are skipped.
  • What it rewrites. It rewrites what the routing pass wrote at those slots: the reverse map, forwarded weights and expert ids, scale rows and payload.
  • Count. It recounts total_recv through the same handshake, so the op's count equals the handle's.
  • After replay. A later combine(routing=handle), with or without the weight fold, reads this round's data.

Changes

  • ep_intranode_kernel.hpp.
    • The per-slot publish (weights, expert ids, payload, scale row with its zero-filled pitch) moves into EpPublishSlot. The routing pass and the new replay pass both call it.
    • Replay decodes the destination PE and slot from the dest map, as V1 does, so a misused handle cannot address out of bounds.
  • Cfg and request.
    • EpCfg.replay and EpRequest.replay are new.
    • The default is omitted from the rendered Cfg, so existing kernels and their cache keys keep their text.
    • Replay plans get the entry name ..._dispatch_replay.
    • MakeEpCfg refuses replay on combine and on gfx125x, whose dispatch body has no replay.
  • hip_backend.py.
    • One replay plan is built per dispatch plan when the op is constructed.

    • So the first replay inside a graph capture compiles nothing.

    • It costs one more JIT compile per dispatch geometry, which the disk cache keeps. Op construction, EP8, hidden 7168, top-k 8, 32 experts a rank, 4096 tokens a rank max:

      dispatch plans cold JIT cache warm
      MI300X, with replay plans 8 12.8 s 0.24 s
      MI300X, without 4 8.1-8.6 s 0.24 s
      MI355X, with replay plans 4 5.1-5.2 s 0.12-0.13 s
      MI355X, without 2 3.9 s 0.13 s
  • Token count. dispatch(routing=handle) refuses a token count other than the handle's, before the launch: the kernel reads only that many dest-map entries, and only those were written. from_tensors() records no count unless given cur_rank_num_token, and replay refuses such a handle.
  • Docs. The README, the EP guide and ep_backends.rst list the cap and replay for HIP on gfx942/gfx950.

Tests

  • test_routing_snapshot.py. It already runs both backends and gates its replay checks on the capability, so it now covers HIP replay: replayed count, replayed combine and replayed weighted combine with an older snapshot handle. It also checks that a replay with another token count is refused, that a handle rebuilt by from_tensors() without its count is refused, and replays one rebuilt with it.
  • test_op.py. REPLAY=1 now zeroes the received rows, weights, expert ids and scales before the replay. It then requires all of them, and the recounted total_recv, to equal what the routing pass delivered, so a replay that writes nothing fails. It also runs under a recv cap.
  • New suite cases. test_dispatch_combine_v2_intranode.py adds HIP replay cases:
    • plain;
    • with SCALE_DIM=32;
    • with TOPK=9 RAGGED=1 NOSELF=1;
    • with MAXRECV=1024;
    • ahead of the plain scatter and the fp8 1x128 scatter, which read the reverse map and weights replay rewrites.
  • test_jit_binding.py. It checks that a replay plan uses the same arena regions as the routing plan, and that replay is refused for combine and on gfx125x.

Unquantized scatter combine, and one scatter body over a codec template

The HIP intranode backend on gfx942/gfx950 now runs combine_mode="scatter" without a quant type. That is the unquantized bf16/fp32 scatter combine FlyDSL already has. Until now HIP refused it.

It reuses the quantized scatter's landing area and barrier, and its kernel. EpCombineScatterBody<kCfg, T> is now one template over a codec, EpScatterCodec<kCfg, T>, with two specializations:

  • Quantized. bf16 in; fp8 or e2m1 plus group scales on the wire.
  • Unquantized. bf16 or fp32 rows as they are.

The codec supplies Put, Get and Add, so the stage-1 batch loop, the barrier, and the stage-3 row loads and sums are written once. #1012's quantized scatter keeps its precision. Its latency holds on MI300X (fp8 1x128 is 691.0 µs at 4096 tokens a rank before and after), while on MI355X fp8 1x128 is 1-3% slower from 128 to 1024 tokens a rank (see Testing).

The plain scatter's flow:

  • Stage 1. Each rank copies every post-expert row it computed, 16 bytes a lane, into the landing row (computing rank, source token) on the token's own rank. The token's weights go in the same row.
  • Barrier. One cross-device barrier.
  • Stage 3. Each rank sums its tokens' landed rows in f32, in top-k order, and writes bf16 or f32.

Both stages issue all of a warp's loads before using any of them.

Changes

  • Kernel. One scatter body over the codec template; the quantized-only body is gone.
  • Cfg and request.
    • EpCfg.combineScatterPlain and EpRequest.combineScatterPlain are new.
    • The landing row is the token bytes plus the weights, padded to 128 bytes.
    • The entry name is ..._combine_scatter.
    • MakeEpCfg refuses the plain scatter on gfx125x, beside a quant group, and beside the push, LL128 or card combine.
  • hip_backend.py.
    • It requests the plain scatter for combine_mode="scatter" with no quant type.
    • The refusal now applies to gfx125x only.
  • bench_ep.py. COMB_MODE=scatter times it.
  • hip_tuning_configs.lookup(scatter=True). A scatter combine, quantized or not, takes the scatter rows (_SCATTER_COMBINE_TABLE). A gather keeps the IntraNodeV2 combine rows. The config passes scatter=is_scatter.
  • Docs. The README, the EP guide and the JIT design doc list it.

Performance

Combine latency in µs, EP8, hidden 7168, topk 8, bf16, HIP, graph mode, minimum over rounds:

The unquantized scatter is slower than the gather on one node. It moves the same bf16 bytes and then adds a local reduction pass, so it is there for config parity with FlyDSL, not speed. The scatter column uses the scatter rows. On the gather's rows it was 1510 µs (MI300X) and 970 µs (MI355X) at 4096 tokens.

tokens/rank MI300X gather MI300X scatter MI355X gather MI355X scatter
32 24.1 31.6 24.1 26.3
128 46.2 80.2 41.8 63.8
512 132.4 187.2 109.6 139.0
1024 247.2 309.7 202.2 231.7
2048 475.0 577.0 382.4 412.5
4096 928.7 1092.3 742.3 773.8

Tests

  • New suite cases. test_dispatch_combine_v2_intranode.py adds:
    • hip-bf16-scatter;
    • hip-f32-scatter;
    • hip-bf16-scatter-scales-ragged (scales, ragged ranks, topk 9);
    • hip-bf16-scatter-h2304 (a partial last step);
    • hip-bf16-scatter-cap (a recv cap).
  • test_jit_binding.py. It checks the landing row size for bf16 and fp32, and the refusals.
  • test_op.py. The identity-expert combine is checked against U[t] · input[t] at 2% tolerance. Further runs cover hidden 2304 (a partial last step), topk 9 with ragged ranks and no self-routing, and a recv cap with per-token scales.

local_expert_count

What this does

op.local_expert_count() now runs on the HIP backend's intranode path on gfx942 (MI300X) and gfx950 (MI355X). It returns the same thing FlyDSL returns: one persistent int32 [num_experts_per_rank] buffer holding, for each of this rank's experts, how many (row, k) of the last dispatch's recv_indices()[:total_recv] name it. Other ranks' ids, negative ids and out-of-range ids are skipped, and a repeated id counts twice. The call zeroes the buffer and launches one kernel on the current stream, with no host sync and no allocation, so it can be captured in a graph (SGLang's expert-distribution recorder calls it right after dispatch, under capture).

gfx125x, internode and AsyncLL ops still raise NotImplementedError, and do not advertise the capability.

Design

A local-kernel family. Kernels that only read and write this rank's own rows do not need EpCfg, EpArgs or the arena, so they get their own:

  • include/mori/ops/dispatch_combine_v2/ep_local_cfg.hpp: EpLocalCfg (shape, geometry, wave), EpLocalRequest, and EpLocalArgs with its published schema and the same offset/field-count asserts EpArgs has. No Args field is named window or off<Region>, so plan_api binds no arena region.
  • src/ops/dispatch_combine_v2/ep_local_kernels.hpp: the device bodies.
  • ep_spec.cpp: MakeEpLocalCfg, EpLocalExpertCountSpec, and the ep_local_expert_count plan, registered next to ep_dispatch / ep_combine. It does not go through MakeEpCfg.
  • ep_plans.local_plan(name) makes the Plan class on first use, so a libmori_ops_v2.so without it still serves dispatch and combine.
  • Past the local kernels' limits (top-k past the wavefront, more than 8192 experts a rank), the op serves dispatch and combine without local_expert_count, and refuses enable_std_moe at construction. The gate asks the plans: describe() runs EpLocalCfgIsValid without compiling, and a refusal carries its message, so the limits live in C++ only.

The kernel. One thread per (row, k), grid-stride over rows * topk, an unsigned compare of out_idx[i] - rank * epr against epr, and an atomicAdd into a per-block LDS histogram; each block then adds its non-zero bins to the output once. Every id of a rank lands on its epr counters, so per-id global atomics serialize (54-65 µs at 4096 tokens a rank); the histogram cuts that to one add per expert and block. rows is total_recv clamped to the recv capacity, so a bad count cannot read past out_idx. The geometry is the op's dispatch (block_num, warp_num_per_block), the same source FlyDSL uses. The plan is built with the op, so nothing compiles at call time.

The base op owns the method. KernelSet gets a local_expert_count callable, next to dispatch_replay. EpDispatchCombineOp.local_expert_count() owns the buffer, the zero and the return; a backend only hands back callable(total_recv=, out=). The "local_expert_count" capability is derived from whether the callable is there. FlyDSL moves onto the same seam: its kernel is unchanged, and it now returns the callable instead of defining the method.

Tests

  • test_op.py: OP-LEC now compares every rank's counts per expert against a reference built from all ranks' routing (under a recv cap, from the rows this rank received), plus the global sum over the slots the dest map kept (world * ct * K without a cap). The first read is launched right after dispatch, with no sync and no barrier, the way SGLang calls it. REROUTE=N adds N rounds of new routing per sweep point, each read straight after dispatch.
  • test_dispatch_combine_v2_intranode.py: HIP cases hip-bf16-gather, hip-bf16-gather-scales-ragged (scales, RAGGED, NOSELF), hip-bf16-gather-topk9, hip-bf16-gather-reroute (REROUTE=8). OP-LEC runs in every case of both backends, and the suite requires each case's OP lines (LEC, REPLAY, REROUTE, STDMOE-PACK, CAP, FRESH, SCALES) to appear, so a check gated on a capability cannot drop out silently. The lifecycle test also runs on hip and checks the plans are closed. A hip graph-capture test runs local_expert_count() inside the captured step.
  • test_graph_capture.py: LEC=1 puts the call between dispatch and combine and checks the count after every replay.
  • test_jit_binding.py: the plan's describe() against the built plan, no arena regions, the refusal of a top-k past the wave, launches on synthetic ids (negative and out-of-range ids, a count past the rows, epr=1/topk=1, more experts than block threads, zero rows), and the base raising without a kernel.

Results

local_expert_count() time, graph mode, EP8, hidden 7168, top-k 8, 32 experts a rank, uniform routing, mean over ranks in µs. The kernel column launches the kernel alone; the call column is op.local_expert_count() (zero plus kernel).

Arch Tokens a rank Recv rows HIP kernel FlyDSL kernel HIP call FlyDSL call
gfx942 128 682 2.0 3.2 3.7 4.9
gfx942 4096 21.7k 2.7 54.5 4.5 56.4
gfx950 128 682 2.0 3.5 3.6 5.2
gfx950 4096 21.7k 2.7 64.7 4.5 66.7

StdMoE

What this does

StdMoE (enable_std_moe=True, convert_dispatch_output(), convert_combine_input(routing), then combine()) now runs on the HIP backend's intranode path on gfx942 (MI300X) and gfx950 (MI355X), bf16 with the gather combine. It returns what FlyDSL returns:

  • convert_dispatch_output() packs the last dispatch's recv rows per local expert and returns (packed_x [E_local, world_size * M, hidden], packed_count [E_local] int32, packed_src [E_local * world_size * M] int32), where packed_src is src_rank * M + src_token. These are op-owned buffers, rewritten by each call; row order inside a bucket comes from atomics.
  • convert_combine_input(routing) writes out_tok[r] = sum over the local k of w[r, k] * packed_x[row of (r, k)] with the forwarded weights, accumulated in fp32.
  • combine() on a StdMoE op takes its input from what convert_combine_input wrote, whatever input it is passed.

gfx125x keeps refusing enable_std_moe, as do non-bf16 dtypes (as on FlyDSL), combine_mode="scatter", and the internode and AsyncLL paths. A StdMoE dispatch without weights raises on both backends, since convert_combine_input folds the forwarded ones.

Design

Two more plans on the local-kernel family from the previous PR (EpLocalCfg / EpLocalArgs, no arena regions): ep_convert_dispatch and ep_convert_combine, both bf16 only.

  • Convert dispatch, one warp per (row, k). Lane 0 tests whether the id is local with an unsigned compare, claims a bucket row with an atomicAdd on packed_count, and writes slot_map and packed_src; the warp copies the token in 16 B vectors. A non-local (row, k) gets slot_map = -1. A claim past the bucket (only possible with a repeated id in one row) is dropped and taken back off the count.
  • Convert combine, one warp per row, or several per row splitting hidden in 16 B chunks when warps outnumber rows. Lanes < topk fill a per-warp LDS array of source pointers from slot_map (null for -1), and core::WarpAccum folds them with the row's forwarded weights.
  • Both run two 8-warp blocks a CU. They are local row copies bound by load latency, and the comm kernels' grids that FlyDSL reuses for them (64 to 128 blocks) leave most CUs idle: on one MI355X at 21.7k rows, convert-combine took 913 µs on 64x8 and 296 µs on 512x8.

The base op now owns convert_dispatch_output(), convert_combine_input(), the packed buffers and the zero/fill steps. Backends hand back convert_dispatch / convert_combine callables in KernelSet, and the "std_moe" capability follows them. FlyDSL moves onto the same callables with its kernels unchanged. On a backend whose combine stages its input in the kernel (stages_in_kernel), a StdMoE combine passes combine_in_view() as the input, so the HIP kernel skips its staging copy instead of overwriting the converted rows.

Tests

  • test_op.py: with STDMOE=1, convert_dispatch_output() runs right after dispatch with no sync or barrier. After the barrier, OP-STDMOE-PACK checks packed_count against the exact per-expert reference, each bucket's packed_src as a multiset against the recv rows' sources, and every packed row against the recv row it came from. The final combine is checked against (sum_k w) * x as before. Under a recv cap both run as well: the references come from the rows each rank kept, and the combine sums only the k whose PE kept the token. REROUTE=N also checks packed_count in each extra round.
  • test_dispatch_combine_v2_intranode.py: HIP cases hip-bf16-stdmoe, hip-bf16-stdmoe-epr4-ragged (4 experts a rank, so a token often lands on several of them; RAGGED and NOSELF), hip-bf16-stdmoe-reroute, and bf16-stdmoe-cap / hip-bf16-stdmoe-cap (MAXRECV=1024). The hip graph-capture test also runs dispatch, both converts and combine in one captured step. The lifecycle test alternates StdMoE ops.
  • test_jit_binding.py: describe() against the built plans, the non-bf16 refusals, a single-GPU round trip of both converts against a CPU reference, the hip gate (gfx125x, non-bf16, scatter, and the plans' own reasons for a top-k past the wave, more than 8192 experts and a hidden that is not whole 16 B rows), and the base raising without the kernels.

Results

Time per call, graph mode, EP8, hidden 7168, top-k 8, 32 experts a rank, uniform routing, mean over ranks in µs. convert_dispatch_output() includes its zero and fill of the count and slot map; convert_combine_input() is one kernel.

Arch Tokens a rank Recv rows convert_dispatch_output HIP FlyDSL convert_combine_input HIP FlyDSL
gfx942 128 682 16.2 67.1 23.6 27.1
gfx942 4096 21.7k 267.3 4472.6 311.7 730.9
gfx950 128 682 16.1 75.4 17.0 30.0
gfx950 4096 21.7k 228.6 3495.3 315.1 1051.5

Testing

On main (4f5ebf8) plus this PR, EP8:

8x MI355X (gfx950), ROCm 7.14.1

  • test_dispatch_combine_v2_intranode.py: 74 passed.
  • test_quant_types.py, test_v2_tuning_tables.py, test_tuning_configs.py, test_tuning_profile.py, test_gfx1250_strict_arch.py, test_asyncll_options.py, test_active_qp_config.py: 235 passed, 2 skipped. test_jit_binding.py: 135 passed, 45 skipped.
  • CI's EPv2 steps pass: test_op.py plain and with scales, test_asym_dtype.py (fp8/fp4 dispatch with the gather and both quantized scatters), test_ep_backend_parity.py, test_routing_snapshot.py, test_graph_capture.py with LEC=1, and the bench_ep.py smoke.
  • test_op.py passes 32 cases on both backends:
    • a recv cap with replay;
    • ragged ranks with top-k 9 and no self-routing;
    • fresh reads right behind dispatch;
    • re-routing with local_expert_count and StdMoE, and StdMoE on FlyDSL;
    • the unquantized scatter with a cap, and with f32 rows;
    • hidden 2304;
    • every served quant format at input scales 1, 200 and 0.001.

8x MI300X (gfx942), ROCm 7.14

  • test_dispatch_combine_v2_intranode.py: 64 passed, 10 skipped (fp4 is gfx950 only).
  • The same CPU and binding tests, and the same CI steps without fp4, pass.
  • test_op.py passes the same cases without the fp4 formats, 26 in all.

8x MI355X, ROCm 7.2.4, at b36a62d. Everything above passes except test_ep_backend_parity.py and one test_asym_dtype.py case. Both fail in ccoMemAlloc on ROCm 7.2.x's hipMemSetAccess sub-buffer bug, which 7.14 fixes.

Performance against main (graph mode, median over three rounds, 128 tokens a rank and above):

  • Dispatch and the gather combine are within ±0.8% on both GPUs.
  • The fp4 1x32 scatter (MI355X) and the fp8 1x128 scatter on MI300X are within 1%.
  • The fp8 1x128 scatter on MI355X is 1-3% slower from 128 to 1024 tokens a rank (+2.0%, +3.0%, +1.2%) and 0.6% slower at 2048 and 4096. It shows on ROCm 7.14.1 in two separate runs; on ROCm 7.2.4 it is within 0.4%.

🤖 Generated with Claude Code

jhchouuu and others added 6 commits November 20, 2026 09:17
…counts are signaled

- every block waits for its own stores (s_waitcnt) before it arrives at the dispatch grid barrier; the signal fence only covered warp 0, and __syncthreads does not wait for vector-memory stores
- the drain assumes the uncached cco window (the default); MI300X/MI355X EP8 dispatch latency unchanged (within 0.6 us at 32-4096 tokens a rank)
- test_op FRESH=1 copies the received rows and the reverse map in-stream right behind dispatch and compares them with the post-barrier views; the intranode suite runs it on both backends

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/gfx950

- dispatch drops a slot past the recv cap: null in the dest map, no payload, not counted, so total_recv = min(demand, cap) with dense rows; behind if constexpr, uncapped kernels are unchanged
- the C++ validator accepts a capped maxRecv; MakeEpCfg and the backend gate refuse it on gfx125x only; the HIP intranode op advertises recv_cap
- test_op checks delivery against the routing (OP-RECV) and, under a cap, the drop invariants (recv count, kept slots vs reverse maps, combine, weight fold and LEC over kept PEs) on both backends

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- dispatch(routing=handle) sends to the slots the handle's dest map names, claims none, and recounts total_recv, as FlyDSL does
- replay is a Cfg bit with its own dispatch_replay binary sharing EpPublishSlot with the routing pass; refused on gfx125x; plans built with the op so a first replay under capture compiles nothing
- OP-REPLAY zeroes the received rows, weights, ids and scales first, so a replay that writes nothing fails; HIP replay cases with scales, topk 9 + ragged + no-self, and a cap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… codec template

- combine_mode="scatter" without a quant type copies bf16/fp32 rows into the landing row and sums them locally in f32, as FlyDSL serves it
- EpCombineScatterBody<kCfg, T> takes its wire from EpScatterCodec<kCfg, T> (quantized and unquantized specializations); quantized latency unchanged (MI300X fp8 1x128 T4096 691.0 us)
- a scatter combine, quantized or not, takes the scatter tuning rows: bf16 scatter T4096 MI300X 1510 -> 1092 us, MI355X 970 -> 774 us; bench_ep COMB_MODE=scatter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gfx950)

- a local-kernel family (EpLocalCfg / EpLocalArgs, no arena regions) with the ep_local_expert_count plan: one thread per (row, k) into a per-block LDS histogram
- the base op owns local_expert_count(); backends hand back a callable in KernelSet and the capability follows it; FlyDSL moves onto the same seam with its kernel unchanged
- EP8 H7168 kernel time: 2.0 us at 128 tokens a rank and 2.7 us at 4096 (FlyDSL 3.2-3.5 / 54-65 us); OP-LEC checks an exact per-expert reference read straight after dispatch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ep_convert_dispatch packs each local (row, k) into its expert's bucket; ep_convert_combine folds the bucket rows back with the forwarded weights (WarpAccum over LDS source pointers); bf16, gather combine
- the base op owns convert_dispatch_output / convert_combine_input and the packed buffers; gfx125x, non-bf16 and scatter stay refused
- EP8 H7168 at 4096 tokens a rank: convert_dispatch 229-267 us (FlyDSL 3495-4473), convert_combine 312-315 us (FlyDSL 731-1052)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

GPU CI for 75530f5d (run): changed areas: epv2

lane runs jobs
mori no MI355X intranode, MI355X ROCm 7.14, MI355X JAX, MI355X internode
mi300x no MI300X intranode, MI300X internode
umbp no UMBP unit test
cco yes CCO unit test, CCO EPv2 single-node test, CCO internode
fused no CCO fused GEMM test
build yes MoRI build (compile check)

Test groups (the steps that run in those jobs): epv2.

Lanes follow the changed files. Adding ci:full re-runs CI with every lane, the full internode sweeps and every fused GEMM case; adding ci:mi300x re-runs it with the MI300X lanes added. /ci-rerun re-runs CI against the current main.

jhchouuu and others added 2 commits November 23, 2026 08:33
- Routing replay refuses a token count other than its handle's; StdMoE dispatch without weights is refused on both backends
- Past the local kernels' limits, local_expert_count is not served and StdMoE is refused at construction
- The intranode suite requires every check a case turns on, and adds StdMoE under a recv cap, scatter replay and a cached-window FRESH run
- The dispatch drain stays a drain: rows are complete on a cached cco window too, and a per-block release costs 6-40% of dispatch
- Docs: gfx125x replay, the HIP feature list, test_op knobs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Black 25.1.0 reformats three test files; no change in behaviour

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhchouuu
jhchouuu requested a review from kawhil-amd November 23, 2026 11:08

@kawhil-amd kawhil-amd 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.

Thanks for the PR. I read the diff and spot-checked a few points against the code. Five comments below: two questions about behavior changes (the waitcnt cost, StdMoE on FlyDSL), one gap in the replay token-count check, and two on JIT build time and duplicated limits. I did not run it on gfx942 / gfx950.

// Drain this block's peer stores before it arrives, as FlyDSL does: the signal fence
// below covers warp 0's stores only. No release: a cached window passes FRESH without
// one, and a per-block release costs 6-40% of dispatch.
__builtin_amdgcn_s_waitcnt(0);

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.

The PR text gives the reason for dropping the release (6-40% of dispatch) and says FlyDSL drains the same way, so this matches FlyDSL. What it does not give is the cost of the drain itself. This is in the dispatch body, so every dispatch built from it on gfx942/gfx950 pays it, not only the new replay and capped paths. Could you add a before/after dispatch latency for one small and one large token count?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kawhil-amd

The PR text gives the reason for dropping the release (6-40% of dispatch) and says FlyDSL drains the same way, so this matches FlyDSL. What it does not give is the cost of the drain itself. This is in the dispatch body, so every dispatch built from it on gfx942/gfx950 pays it, not only the new replay and capped paths. Could you add a before/after dispatch latency for one small and one large token count?

The before/after numbers are in the PR description under Dispatch drains every block's peer stores → Cost: EP8, hidden 7168, top-k 8, bf16, HIP, graph mode, every count from 32 to 4096 tokens a rank.

32 tokens/rank 4096 tokens/rank
MI300X, before → this PR 24.1 → 24.0 µs 1063.7 → 1063.6 µs
MI355X, before → this PR 23.8 → 23.8 µs 917.2 → 916.6 µs

At the counts in between, the two are within 1.3 µs (1.2%) of each other. So the drain costs nothing measurable. What costs 6–40% is a per-block release (__threadfence_system), which is measured in the same section and not used.

"dispatch with the next combine (its recv counts and slot map are "
"per round), so a routing handle is only ever used by that combine"
)
if self.cfg.enable_std_moe and weights is None:

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.

_dispatch_impl is shared, and this condition does not look at the backend. A FlyDSL StdMoE caller that dispatches without weights worked before and now gets this ValueError. Does FlyDSL need the weights here? If not, the check could move to where the HIP convert_combine_input reads the forwarded weights, or be limited to the HIP backend.

@jhchouuu jhchouuu Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kawhil-amd

_dispatch_impl is shared, and this condition does not look at the backend. A FlyDSL StdMoE caller that dispatches without weights worked before and now gets this ValueError. Does FlyDSL need the weights here? If not, the check could move to where the HIP convert_combine_input reads the forwarded weights, or be limited to the HIP backend.

FlyDSL needs them too, as does any MoE caller. With per-PE dedup, a rank's expert outputs are summed before combine, so the top-k weights are applied on the expert side: aiter's fused_moe takes the dispatched weights as its topk_weight, and StdMoE's convert folds them itself. On HIP (and in v1), weights=None is accepted and forwards nothing. FlyDSL never supported it: on main, a FlyDSL dispatch with weights=None already faulted on the GPU, with or without StdMoE, because ep_dispatch reads the weights through a null pointer. So no FlyDSL call that worked before gets this error now. For StdMoE, the check turns that fault into a ValueError on both backends.

# Replay reads n * topk entries of the handle's dest map, and only the handle's
# own tokens were written. 0 = not recorded (from_tensors without a count).
ct = 0 if routing is None else routing.cur_rank_num_token
if ct and n != ct:

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.

When the handle has no recorded count (from_tensors without cur_rank_num_token) ct is 0, so this check is skipped and replay reads n * topk entries of a dest map the handle never wrote. The comment says so, but it leaves a gap: a from_tensors handle replayed with a larger n gets stale slot ids with no error. Could from_tensors require the count when it builds a handle for replay, or could replay refuse a handle with no count?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kawhil-amd

When the handle has no recorded count (from_tensors without cur_rank_num_token) ct is 0, so this check is skipped and replay reads n * topk entries of a dest map the handle never wrote. The comment says so, but it leaves a gap: a from_tensors handle replayed with a larger n gets stale slot ids with no error. Could from_tensors require the count when it builds a handle for replay, or could replay refuse a handle with no count?

Fixed in 75530f5: replay now refuses a handle with no count. from_tensors() keeps cur_rank_num_token optional, because combine does not need it, but the default is now None ("not recorded") rather than 0. dispatch(routing=h) raises a ValueError for such a handle, and the message says to rebuild it with cur_rank_num_token=n. A handle that records 0 is now held to 0 tokens like any other count. test_routing_snapshot.py checks on both backends that a rebuilt handle without the count is refused, and replays a handle rebuilt with it.

self._plans.append(plan)
sized.append((cap, plan, self._card is not None and not blocks))
# Built eagerly, so a first replay inside a graph capture compiles nothing.
if not self._is1250:

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.

This builds a replay plan for every dispatch spec and cap on every gfx942/gfx950 op, including ops that never replay, so op construction compiles about twice the dispatch kernels on a cold JIT cache. The comment gives graph capture as the reason. Could the plans be built on the first replay, or warmed by an explicit call before capture? If the startup cost is small, a number in the PR would settle it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kawhil-amd

This builds a replay plan for every dispatch spec and cap on every gfx942/gfx950 op, including ops that never replay, so op construction compiles about twice the dispatch kernels on a cold JIT cache. The comment gives graph capture as the reason. Could the plans be built on the first replay, or warmed by an explicit call before capture? If the startup cost is small, a number in the PR would settle it.

Measured. Op construction time, EP8, hidden 7168, top-k 8, 32 experts a rank, 4096 tokens a rank max, HIP, two runs each, every rank sharing one JIT cache:

dispatch plans cold cache warm cache
MI300X, replay plans built (this PR) 8 12.8 s 0.24 s
MI300X, replay plans not built 4 8.1–8.6 s 0.24 s
MI355X, replay plans built (this PR) 4 5.1–5.2 s 0.12–0.13 s
MI355X, replay plans not built 2 3.9 s 0.13 s

So it is about 4.5 s on MI300X and 1.2 s on MI355X, once per shape per machine. The disk cache keeps the result, and a warm start is unchanged. I'd keep the eager build: it is there so that a first replay made inside a graph capture compiles nothing. A warm-up call would give the same only to callers who know to make it. I added the numbers to the PR description.

)

@staticmethod
def _local_shape_ok(cfg, rows=False):

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.

Non-blocking. The limits here (topk <= 64, 8192 experts, hidden % 8 for bf16) repeat EpLocalCfgIsValid in C++, so the two have to be edited together. A config that this gate accepts and the plan constructor rejects shows up as a RuntimeError at build time, and the reverse silently drops the capability. If the plan can report its own validity, the gate could ask it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kawhil-amd

Non-blocking. The limits here (topk <= 64, 8192 experts, hidden % 8 for bf16) repeat EpLocalCfgIsValid in C++, so the two have to be edited together. A config that this gate accepts and the plan constructor rejects shows up as a RuntimeError at build time, and the reverse silently drops the capability. If the plan can report its own validity, the gate could ask it.

Done in 75530f5. The gate now asks the plans: _local_refusal() calls describe() on each local plan with the op's shape. That runs MakeEpLocalCfg / EpLocalCfgIsValid and compiles nothing. The refusal carries the C++ message, for example enable_std_moe: mori v2 ep local: inconsistent config (...), and the Python copy of the limits is gone. test_jit_binding.py checks that the gate accepts a valid shape and gives the plans' reason for a top-k past the wave, more than 8192 experts, and a hidden that is not whole 16 B rows.

jhchouuu and others added 2 commits November 23, 2026 13:10
…tranode-parity

# Conflicts:
#	tests/python/ops/dispatch_combine_v2/test_op.py
…e local limits from the plans

- Replay with a handle rebuilt by from_tensors() without cur_rank_num_token now raises, instead of walking 0 rows.
- The HIP gate asks the local plans (describe()) why a shape is refused, so the limits live in C++ only.
- The intranode suite resolves the default backend per arch (hip on gfx125x) when it decides which checks a case must print.
- test_routing_snapshot covers the refusal and replays a rebuilt handle; test_jit_binding covers the gate's reasons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhchouuu

jhchouuu commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

@kawhil-amd Thanks for the review. Summary of the five points, with details in each thread:

  1. Drain cost: before/after numbers are in the description (no measurable change at 32 and 4096 tokens a rank on MI300X and MI355X).
  2. StdMoE weights: StdMoE folds the forwarded weights, so it needs them on both backends; on main a FlyDSL dispatch without weights already faulted, so the check stays in the base op.
  3. Replay with a handle without a count: now refused (75530f5).
  4. Eager replay plans: measured at 4.5 s (MI300X) and 1.2 s (MI355X) once per shape on a cold cache, and nothing when warm; kept, numbers in the description.
  5. Local limits: the gate now asks the plans (75530f5).

Retested on 8x MI300X and 8x MI355X: the intranode suite, the CPU and binding tests, CI's EPv2 steps, and test_op.py across 26 and 32 cases pass.

This branch has not been deployed

No deployments
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.

2 participants