Skip to content

[FlyDSL] perf(mega_moe): gfx1250 decode megakernel - dispatch, GEMM1, GEMM2 and combine in one launch - #7345

Draft
GwilliamHu wants to merge 1 commit into
mainfrom
ghu_mega_decode_1250
Draft

GwilliamHu wants to merge 1 commit into
mainfrom
ghu_mega_decode_1250

Conversation

@GwilliamHu

@GwilliamHu GwilliamHu commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds two opt-in single-kernel paths to MegaMoEGfx1250. Each runs the whole MoE layer as one persistent kernel: fp4 wire quant, dispatch, GEMM1, GEMM2 with EP scatter, the cross-rank combine and the top-k reduce. The staged compact path needs 6-7 launches per layer for the same work (plan, quant, dispatch or S1F, GEMM1, GEMM2, combine sync, reduce).

  • small_m (AITER_MEGA_DECODE=N): fixed per-expert slots. It runs every step whose receive bound (recv_token_bound, or world * max_tokens_per_rank when unbounded) is at most world * N.
  • large_m (AITER_MEGA_LARGE=1): the staged compact layout. It runs every larger step, which covers decode up to 1536 tokens per rank and prefill.

Both are the gfx1250 counterpart of the gfx950 MegaMoE (#6881), adapted to gfx1250: wave32, TDM loads and gather stores, and no readable XCC id.

  • The output is bitwise identical to the staged path, with and without fused shared experts.
  • Both are off by default. Nothing changes unless a variable is set:
    • the new builder knobs default to the existing code and kernel names;
    • the new arena regions are added only when a path is enabled.
  • Status: small_m is 3-5% faster than the staged path. large_m is correct and 2-9% slower than the staged path (see Results). Overlapping its send with GEMM1 is the next step.

How small_m works (mega_moe_gfx1250/decode_mega.py, layout="slots")

Every CTA of an all-resident grid (CU count × 2, 4 waves each) runs these phases.

  1. Start handshake. CTA 0 stores the launch's generation into every peer's started[rank], polls theirs and opens each CTA's send gate. The route waves load their rows first and wait on the gate only for the remote atomic and the stores.
    • Without it, writes that reached a rank still between two launches came out corrupted now and then. About 1 in 400 calls had one token wrong (one route's whole output row, in the first call of a layer).
    • An idle delay before any send removed it. Under random launch skew between ranks: 3 bad calls in 640 without the handshake, 0 in 1920 with it.
    • Cost: 1-2 µs per layer.
  2. Produce. One wave per route (token, k).
    • Lane 0 reserves a slot of the destination expert with one SCOPE_SYS buffer atomic on that rank's running[parity][expert]. Idle lanes address out of bounds, so they cost nothing.
    • Meanwhile the token's bf16 row, loaded first, is quantized to the fp4 wire in registers. The e8m0 rule and amax floor match the HIP quant, so the wire bytes match the staged path.
    • The row and its (meta, weight) rowmap pair go straight into the slot with SCOPE_SYS stores.
    • The wave that finishes the rank's last route stores the generation into every peer's src_done[rank].
  3. Plan. CTA 0 alone polls the peers' flags.
    • It publishes the expert counts in 128 replicas (16-bit counts), then opens each CTA's own gate line.
    • Hundreds of CTAs polling or reading one uncached line serialize at its DRAM bank and stall every access queued behind it. This design cut the kernel by more than 2×.
  4. GEMM. One dynamic queue holds every GEMM1 item, then every GEMM2 item.
    • Both use the existing build_gemm_a8w4_tdm_task bodies with explicit tiles, inside the kernel.
    • GEMM1 output is written SCOPE_DEV. A per-m-tile counter publishes g1_ready, and a GEMM2 item's A waves wait on it while its B waves stream W2.
    • The EP-scatter epilogue writes to the peers with SCOPE_SYS gather stores.
  5. Close and reduce.
    • A unit-counted close (no grid barrier) stores the generation into every peer's comb_flag.
    • CTA 0 opens the reduce gates, and each CTA sums its tokens' top-k slots in k order in fp32, the staged reduce's arithmetic.

How large_m works (layout="compact")

large_m replaces phase 1 with a count-first front end on the staged compact layout: expert-major, each expert padded to tile_m, sources in rank order inside it. So its rows, m-tiles and GEMMs are the staged path's, and it needs no slots sized for every token.

  1. Tally. CTAs 1..T each count a chunk of this rank's routes in an LDS histogram. Each takes one device atomic per (CTA, segment) for the chunk's base, so a hot expert costs T atomics, not one per route. A segment is a destination rank's expert. Each route's (segment, rank in segment) goes to a route table.
  2. X1. The last tally CTA sends the segment totals into every peer's X1 row. Every dword carries the launch's 16-bit tag, so no separate flag is needed.
  3. Layout. CTA 0 polls the X1 rows until every dword carries this launch's tag. It then lays out every destination exactly as the staged plan does; all ranks compute the same layout. It publishes this rank's GEMM plan (its receive counts) and its send bases in replicas, then opens the send gates.
  4. Send. One wave per token quantizes the row in registers while X1 is in flight. It then waits for its CTA's send gate and stores the row and its rowmap pair at each route's row.
  5. GEMM, close and reduce as in small_m, with one difference: the queue starts before the rows land.
    • GEMM1's A owners wait on a rows-ready gate, which CTA 0 opens once every peer's src_done arrived. Its B owners stream W1 meanwhile.
    • GEMM2 items wait on the same gate before their body, because the EP-scatter epilogue loads its rowmap pairs before a_ready.

large_m runs 4 CTAs per CU with t64x256x128 b3 GEMM tiles, the staged GEMMs' tile. The weight-bound GEMM phase needs that occupancy: at 2 CTAs per CU with t64x256x256 it was about 90 µs slower at 2048 tokens/rank.

large_m needs no start handshake: it sends rows only after every peer's X1, which proves every peer has started.

large_m shares disp_out, ep_rowmap and comb_inp with the staged path. Each path writes a peer's copy only after a message from that peer's current launch (large_m's X1, the staged dispatch's count exchange), so neither overwrites what the other still reads.

Cross-launch reuse of every region is ordered by the protocol itself (see the module docstring). Generation, parity and the X1 tag come from device-side tickets, so both paths are CUDA-graph safe.

Waits. Every cross-CTA or cross-rank wait traps after a time limit (120 s, AITER_DMK_TIMEOUT_S), not after a poll count. The ranks' first launches can be seconds apart, because each rank JIT-compiles its own kernel (the rank is baked in). Each launcher's first launch therefore compiles first and meets a host barrier.

New knobs on build_gemm_a8w4_tdm_task, all defaulting to 0 (unchanged): a_cache_modifier, c_cache_modifier and scatter_cache_policy. They are the in-kernel GEMM1 → GEMM2 and GEMM2 → peer hand-offs. Policy 0 on the scatter fails accuracy; GEMM2's A loads can stay at policy 0.

Results

4× gfx1250, DSV4-Pro shape (7168 × 3072), E384 + 4 fused shared experts, top-6+1, EP4, fp4 dispatch wire, bf16 combine. Times are µs per layer, graph replay, including the bench's own RMSNorm and residual kernels.

small_m (bench_mega_moe.py --layers 4, AITER_MEGA_PLAN_PREFETCH=0, before the start handshake):

tokens/rank staged (main default, S1F on) small_m
8 184.5 176.4 (−4.4%)
64 316.2 300.2 (−5.0%)
128 327.7 314.4 (−4.1%)

With the start handshake (same instance and inputs for both paths, local-expert weights): 167.2 vs 175.3 at 8 tokens/rank (−4.7%) and 290.3 vs 298.2 at 64 (−2.7%).

large_m (4 layers, same instance and inputs for both paths; every run bitwise equal):

tokens/rank staged large_m
256 315.6 345.3 (+9.4%)
512 335.1 365.3 (+9.0%)
1024 433.9 473.8 (+9.2%)
1536 (staged: S1F off) 594.4 606.3 (+2.0%)
2048 (staged: S1F off) 677.4 727.7 (+7.4%)

Without the MoE call, the same graph takes 55-96 µs per layer (RMSNorm, residual, launch gaps). So the MoE itself is about 30 µs slower at 256-1024 tokens/rank and 50 µs at 2048.

Where large_m still loses (kernel phase stamps, AITER_DMK_TRACE): GEMM1 cannot start a tile before every row of every rank has landed. Each 64-row tile holds rows of dozens of tokens, sent one wave per token, so tiles fill only at the end of the send. Below 4096 received tokens, S1F instead ships rows tile by tile and starts GEMM1 per flag tile as they land.

Next, in order:

  1. Send tile by tile, as S1F does: quantize into a local wire buffer, let producer CTAs ship (tile, source) pieces in expert order, and have each GEMM1 item wait only for its tile.
  2. Pipeline across items in the persistent GEMM loop (S1F's deferred C wait and item hooks).

The GEMM tile does not change the output bits, so each megakernel picks its own tiles.

  • small_m: below 64 tokens per rank, t16x256x256 b3 for GEMM1 and t16x512x128 b3 for GEMM2; above that, tile_m 32.
  • large_m: t64x256x128 b3 for both GEMMs, 4 CTAs per CU.

Limitations

  • Every CTA of the grid must be resident, so no other kernel may hold CUs while a megakernel runs. A co-tenant on the same GPUs can make it time out. The bench's side-stream plan prefetch becomes a no-op for bounds a megakernel serves.
  • Requires the compact dispatch on the fp4 wire, the fused bf16 combine, Silu or Swiglu, and no bias. Any other call falls back to the staged path; warmup_compact_plan still warms those bounds' plans.
  • The choice is made per step from the receive bound, which every rank passes identically, so all ranks always agree. A compact plan an earlier staged layer started for a step a megakernel serves is retired.
  • small_m's slots are sized for world * N rows per local expert: ~191 MB at EP4 with 97 local experts and N=128, plus a2.
  • large_m holds an expert's received rows in 16 bits (world * max_tokens_per_rank <= 65535), counts at most 131072 routes per rank, and checks that its X1 rows and LDS scratch fit at admission.

Test plan

  • python3 op_tests/multigpu_tests/test_mega_moe_decode_gfx1250.py on 4× gfx1250. It is new and skips off gfx1250. It runs both megakernels, with and without a shared expert, at token counts that differ across ranks, and checks:
    • against the fp32 reference;
    • bit for bit against the staged path of the same instance, switching both ways;
    • a graph replay bit for bit against eager;
    • path selection by the receive bound (small_m, large_m, staged), and a dropped pending plan leaving the next staged step unchanged.
    • A throwaway step on other inputs runs before every rerun and replay, so data left in the regions the paths share cannot mask a missing write.
  • In-process A/B on the full shape, same instance:
    • small_m: 528 layer calls at 1-128 tokens/rank, with and without the shared expert, uniform/zipf/zipf_rank routing. All bitwise equal to the staged path and deterministic.
    • small_m with the start handshake: 2560 megakernel-only calls under random launch skew between ranks (128 tokens/rank, zipf_rank), all deterministic.
    • large_m: 8-2048 tokens/rank with the same mix. Bitwise equal and deterministic, also against AITER_MEGA_S1F=0.
  • bench_mega_moe.py with AITER_MEGA_DECODE=128 at 8/64/128 tokens per rank: accuracy PASS.
  • CI

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 2, 2026

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 (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 gfx1201 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 7345 --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.

@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision cdb1291f147f · 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. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/multigpu_tests/test_mega_moe_decode_gfx1250.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@yanboshao
yanboshao force-pushed the ghu_mega_decode_1250 branch from bff56e5 to 12db182 Compare November 11, 2026 04:15
@yanboshao
yanboshao force-pushed the ghu_mega_decode_1250 branch from 12db182 to 9b0a534 Compare November 11, 2026 04:23
@yanboshao
yanboshao force-pushed the ghu_mega_decode_1250 branch from 9b0a534 to 17f9005 Compare November 16, 2026 05:00
@yanboshao
yanboshao force-pushed the ghu_mega_decode_1250 branch from bb7e534 to f9caf81 Compare November 19, 2026 10:01
zejunchen-zejun added a commit that referenced this pull request Dec 2, 2026
…e, for Kimi-K3's A/Bs

--act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound
and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray
with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch
(zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's
routing checks stay, and the step bounds come from resolve_step_bounds, which
equals #7345's inline logic without --sim_ep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zejunchen-zejun added a commit to ROCm/ATOM that referenced this pull request Dec 2, 2026
…-dev-1201-iod

- D_MOE_LOC sets AITER_MOE_LOC on D (LLM-Booster #875). It is off by default
  and needs aiter's IOD placement (ROCm/aiter#8728 + #8997), which lives on
  aiter `zejun/k3-455-dev-1201-iod`. On K3 only W13 is placed.
- The aiter decode megakernel (ROCm/aiter#7345, #865) lives on aiter
  `zejun/k3-455-dev-1201`. The two do not combine yet: they conflict in 21
  hunks of the S1F / GEMM builder, so they are A/B'd on separate builds. The
  IOD install script now defaults AITER_REF to the -iod branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zejunchen-zejun added a commit to ROCm/ATOM that referenced this pull request Dec 2, 2026
…ark draft window, per-request log, MoRIIO hop timing, tools (#4106)

* scheduler: ATOM_SPEC_REQUEST_LOG, one line per finished request with its speculative acceptance

Diagnostics for LLM-Booster #878 (DSpark acceptance falls in long-context
turns). Each `Sequence` counts the speculative steps it verified and the
drafts offered and accepted across them, at the same point and under the
same condition as `EngineStats.update_spec`. When the env names a path
prefix, `_mark_finished` appends one JSON line per request to
`<prefix>.dp<rank>.<pid>.jsonl`: prompt / cached / output tokens, k, steps,
drafted, accepted and the finish reason. That relates acceptance to context
length offline. Off by default; written once per request, never per token; a
failed write warns and turns it off for that engine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — lossless sampling on D at every point (to validate at c512 / c1024), megakernel and spec-log knobs

- D_LOSSLESS now defaults to 1 at every point. c192 was measured (R9c);
  c512 and c1024 are validated on this branch (LLM-Booster #874).
- D_MEGAKERNEL=1 sets AITER_MEGAKERNEL=1 on D: aiter's decode megakernel
  (ROCm/aiter#7345, LLM-Booster #865). It is off by default, to be A/B'd at
  c192, also with the shared expert off its side stream
  (ATOM_DUAL_STREAM_MOE_TOKEN_THRESHOLD=0), since the megakernel needs no
  kernel running beside it.
- D_SPEC_LOG sets ATOM_SPEC_REQUEST_LOG on D: per-request acceptance against
  context length (LLM-Booster #878).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — keep lossless sampling's default at c192 only; c512 / c1024 are #874's

LLM-Booster #874 (lossless sampling at c512 / c1024) and the c1024 point now
belong to gbyu. This branch therefore no longer changes their default: D_LOSSLESS
is on at c192 only, as on k3-455-dev. The knob stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* diagnostics: a P/D request's wait for its KV, hop by hop (LLM-Booster #883); ATOM_REQUEST_LOG

At c192 a request waits ~0.5 s on D before its first decode. D's own metrics
put ~96% of it in pd_kv_transfer_seconds: the MoRIIO write-mode hand-off after
P has finished. This change logs where that hand-off goes.

- ATOM_SPEC_REQUEST_LOG becomes ATOM_REQUEST_LOG, one JSON line per finished
  request. Besides the speculative counters it records ttft_ms and e2e_ms; on
  a P/D consumer it also records park_ms (began waiting for the remote KV) and
  kv_ms (the scheduler found it arrived). It is written once per request and
  only when the env names a path prefix.
- Under ATOM_MORIIO_TRANSFER_STATS:
  - On the producer, each push's stats line gains queue_ms (from the write
    request arriving to the write service taking it) and its PP stage.
  - On the consumer, each receive logs gate_ms (until the forwards queued
    before it finish and the write is asked for), report_ms (until the last
    producer stage reports) and pickup_ms (until an engine step takes it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — request_log_report.py (#878) and pd_timeline_report.py (#883)

Two stdlib-only readers for the new diagnostics:
- request_log_report.py: DSpark acceptance and tokens per forward by
  context-length bin, from ATOM_REQUEST_LOG.
- pd_timeline_report.py: where a P/D request's wait for its KV goes, from
  the MoRIIO transfer stats and write timeline lines
  (ATOM_MORIIO_TRANSFER_STATS=1) and the request log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — replay_turns.py, to tell length from content in DSpark's acceptance drop (#878)

DSpark acceptance falls as c192's agentic trajectories deepen (0.34 to 0.27).
The draft's own card reports only a small drop on ~95k-token documents
(AA-LCR 3.23 against a 3.73 mean, at temperature 1.0), and it trained on
single-turn and chat prompts. So the deep turns' content (tool output, ~150
turns deep) may matter more than their length.

The tool replays three categories of recorded turns through the router:
- early turns;
- deep turns;
- the deep turns cut to a short history: the system prompt, the first user
  message, then the newest whole exchanges, never starting with a tool
  result.
It then joins D's ATOM_REQUEST_LOG to report the acceptance per category.
It is stdlib-only.

On R5b's events the selection takes 8 s and gives:
- early: median 56 KB, turn index 21;
- deep: median 435 KB, turn index 156;
- deep_cut: median 117 KB, turn index 157.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — replay_turns.py records what each turn generated (prose or a tool call) and splits acceptance by it

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* DSpark: ATOM_DSPARK_DRAFT_WINDOW, the newest W context tokens a paged draft block attends (LLM-Booster #878)

Kimi-K3's DSpark acceptance collapses past ~120K tokens of context (E17 c192,
12-02: 0.43 at 96-104K, 0.19 at 128-136K, 0.05 past 176K), while the draft's
card verifies it only up to AA-LCR's 115K. With rope, q.k depends only on the
distance, so attending the newest W tokens keeps every distance the draft sees
in that range. Off by default. A windowed variant of the KV index generator
(kv_indices_generate_window_triton) writes each row's tokens from its first
one; the shared generator is unchanged. CSR MLA decode only, no DCP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — c192 defaults to P_TRANSFER_SLOTS=0 (#883) and a 96K DSpark draft window (#878)

12-02, E17 05-08, c192, 1x613 (R11c) against 12-01's R9c: interactivity
64.7 -> 68.2, 438 -> 480 tok/s/GPU, TTFT p50 1.14 -> 0.86 s. D's KV wait
0.43 -> 0.16 s: P staged each finished prefill's KDA state into its transfer
slot at the next step of every PP stage. The draft's acceptance at 128-144K
0.185 -> 0.410. c512 / c1024 keep 128 transfer slots and no window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — c192 defaults to the MoRIIO write thread on P; record the 12-02 code (aiter heads-mla build)

Every 12-02 c192 run (R11b / R11c / R11d) had ATOM_MORIIO_WRITE_THREAD=1 on P;
with the transfer slots off it sends each push as soon as it is asked for,
not at each PP stage's next step, so the recipe needs it to reproduce the
measured hand-off. The note now says which aiter build the 12-02 numbers used
and marks the 1x613 numbers as early-window only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — 12-02 c192 full-window result with both fixes (R11d: 58.5 interactivity, 530 tok/s/GPU)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
zejunchen-zejun added a commit that referenced this pull request Dec 2, 2026
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096)

* MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z)

Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound:
- "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with
  IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072);
- "compact" up to COMPACT_MAX_TOKENS per rank;
- otherwise the staged path.
Off by default, so nothing changes unless the variable is set. The PR's
tests show the output bitwise equal to the staged path.

Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four
files conflicted:
- s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus
  #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had
  no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's
  _packed_sc).
- s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps
  #8483's SiTUv2 arguments and adds the PR's value_attrs.
- gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...),
  a superset of the PR's.
- dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped
  the PR's two DSR1 rows (not Kimi-K3).
Placement is detected from the GEMM builder's signature (BUILDER_LOC), so
without IOD placement the placed paths stay off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z)

Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016):
the TDM that sends a hist row to rank w is issued by wave w and could read the
row head before wave 0's LDS tag was visible to it. Every sending wave now
re-seals the tag before its store. Kimi-K3's D runs this compact plan
(dispatch=compact).

(cherry picked from commit 4214819)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs

--act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound
and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray
with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch
(zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's
routing checks stay, and the step bounds come from resolve_step_bounds, which
equals #7345's inline logic without --sim_ep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256

Neither head had a gfx1250 row, so both ran the default bandwidth-bound
gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the
target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile
covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 /
128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a
tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on
one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul):

  rows      bf16 out          fp32 out
  1-32      1.04-1.16x        1.0-1.12x (rows <= 8 keep production)
  33-64     1.25-1.37x        1.31-1.35x
  65-128    1.43-1.62x        1.53-1.63x
  129-160   2.04-2.44x        2.10-2.43x   (c192's verify / draft rows)
  161-192   2.33-2.49x        2.42-2.66x
  193-256   2.10-2.72x        2.17-2.77x

At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching

An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads
M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the
commit before) validate_gemm_gfx1250_config refused the empty dimension and
the engine died at its first prefill ("dimensions, tiles, stages, wave counts
and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the
[0, N] result (or the caller's buffer) without a launch, as the default
kernel effectively did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Honglie Yi <[email protected]>
… GEMM2 and combine in one launch

One persistent kernel per rank runs a MegaMoE step end to end
(AITER_MEGAKERNEL=1): quantize and tally the routed rows, exchange the
counts, ship the rows to their experts' ranks, GEMM1, GEMM2 with the EP
scatter back to the source ranks, and the top-k reduce. Two layouts share
one protocol (megakernel/):

- slots: fixed expert slots, for steps whose receive bound is at most
  SLOTS_RECV (SLOTS_RECV_PLACED by shape with IOD-placed weights);
- compact: the staged compact layout, the stage-1 producer running inside
  the kernel (STREAM), for larger steps below COMPACT_MAX_TOKENS per rank.

Larger steps, a quantized combine wire, biases, a post-GEMM2 RMSNorm and a
step that hands in shared_add / shared_ready run the staged path.

Kimi-K3 SiTUv2 (hidden 3584, inter 3072, top-16), EP8 on two nodes, us a
layer, stage-1 fused (S1F) -> megakernel: 120 tokens per rank 206.3 ->
190.6, 640 tokens per rank 301.0 -> 281.0.

Also in this change:
- s1f_stage1: the producer is split out (_PCtx, s1f_produce,
  s1f_producer_lds) so the megakernel runs the same code; the stage-1
  kernel takes W1's IOD phase table as a trailing argument.
- builder: a_cache_modifier / c_cache_modifier / scatter_cache_policy and
  defer_ep_wait (a caller with tile hooks retires the EP scatter itself).
- routing weights are rounded to bf16 in compact / S1F / megakernel
  (config.route_weight_bits); batched SiTUv2 uses v_tanh_f32.
- bench_mega_moe: --routing_dir, --max_tpr / --recv_bound, MoE-only time,
  power and GFX clock; the prefetched plans carry the step's bound.
- warmup_compact_plan compiles and lines up the megakernel of the bound.

Rebased onto main as one commit; the branch's history is in #7345.

Co-authored-by: Shao <[email protected]>
Co-authored-by: XingerZhu <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
@yanboshao
yanboshao force-pushed the ghu_mega_decode_1250 branch from 1839079 to d300aab Compare December 3, 2026 11:57
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096)

* MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z)

Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound:
- "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with
  IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072);
- "compact" up to COMPACT_MAX_TOKENS per rank;
- otherwise the staged path.
Off by default, so nothing changes unless the variable is set. The PR's
tests show the output bitwise equal to the staged path.

Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four
files conflicted:
- s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus
  #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had
  no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's
  _packed_sc).
- s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps
  #8483's SiTUv2 arguments and adds the PR's value_attrs.
- gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...),
  a superset of the PR's.
- dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped
  the PR's two DSR1 rows (not Kimi-K3).
Placement is detected from the GEMM builder's signature (BUILDER_LOC), so
without IOD placement the placed paths stay off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z)

Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016):
the TDM that sends a hist row to rank w is issued by wave w and could read the
row head before wave 0's LDS tag was visible to it. Every sending wave now
re-seals the tag before its store. Kimi-K3's D runs this compact plan
(dispatch=compact).

(cherry picked from commit 4214819)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs

--act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound
and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray
with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch
(zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's
routing checks stay, and the step bounds come from resolve_step_bounds, which
equals #7345's inline logic without --sim_ep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256

Neither head had a gfx1250 row, so both ran the default bandwidth-bound
gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the
target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile
covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 /
128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a
tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on
one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul):

  rows      bf16 out          fp32 out
  1-32      1.04-1.16x        1.0-1.12x (rows <= 8 keep production)
  33-64     1.25-1.37x        1.31-1.35x
  65-128    1.43-1.62x        1.53-1.63x
  129-160   2.04-2.44x        2.10-2.43x   (c192's verify / draft rows)
  161-192   2.33-2.49x        2.42-2.66x
  193-256   2.10-2.72x        2.17-2.77x

At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching

An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads
M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the
commit before) validate_gemm_gfx1250_config refused the empty dimension and
the engine died at its first prefill ("dimensions, tiles, stages, wave counts
and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the
[0, N] result (or the caller's buffer) without a launch, as the default
kernel effectively did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Honglie Yi <[email protected]>
(cherry picked from commit 4c4e333)

Rebase onto main 12-03: main since has #8189's final head, #8889 (packed A only where its stores fit storecnt, tdm_b_th from the tuned row) and #8737 (LDS-to-TDM flush, C staged at the arena tail). Resolved: s1f_ctl.py keeps main's _s1f_gemm_opts / _s1f_packed_a_ok / s1f_prefill_tile(config, ...) / _s1f_warps(config, ...) (this commit's same-purpose _gemm_opts method and (world_size, topk) helpers are dropped) and adds this commit's IOD placement next to main's tdm_b_th: _launcher / _precompile take both, the launcher key and the precompile keys carry (tdm_b_th, placed), make_s1f_stage1 gets tdm_b_th, b_placed, loc_group. s1f_stage1.py: the producer role is this commit's s1f_produce(_PCtx(...)) (its body is main's inline producer, packed A and WAIT_STEPS included); OP_STORES / the storecnt check use main's s1f_packed_a_op_stores / s1f_packed_a_fits (R is 8 there); make_s1f_stage1 takes tdm_b_th and b_placed / loc_group; imports both. dispatch_compact.py: main's 4-tuple _compact_gemm_tiles. mxfp4_preshuffle_gfx1250_tdm.py: main's single C_OFF staging (arena tail, flush scratch at the head) is kept; this commit's a/c cache modifiers, scatter cache policy and defer_ep_wait are added, defer_ep_wait moving C_OFF past the input stages (and growing the arena) instead of this commit's C_EP_OFF / C_Q_OFF; the kernel name carries both suffixes. kimik3_bf16_tuned_gemm.csv: the 504 LM / draft head rows replayed by key. Multi-GPU MegaMoE / megakernel not run on the rebased tree.

Rebase onto main 12-03: after #8483 was updated to its PR head 21120ee (which adds its own bench_mega_moe flags --max_tokens_per_rank / --activation / --situ_beta), op_tests/multigpu_tests/bench_mega_moe.py keeps this commit's version (--max_tpr / --recv_bound / --act / --situ_beta / --sim_ep cover the same knobs); taking both would define --situ_beta twice.
gbyu-amd pushed a commit to ROCm/ATOM that referenced this pull request Dec 3, 2026
…ark draft window, per-request log, MoRIIO hop timing, tools (#4106)

* scheduler: ATOM_SPEC_REQUEST_LOG, one line per finished request with its speculative acceptance

Diagnostics for LLM-Booster #878 (DSpark acceptance falls in long-context
turns). Each `Sequence` counts the speculative steps it verified and the
drafts offered and accepted across them, at the same point and under the
same condition as `EngineStats.update_spec`. When the env names a path
prefix, `_mark_finished` appends one JSON line per request to
`<prefix>.dp<rank>.<pid>.jsonl`: prompt / cached / output tokens, k, steps,
drafted, accepted and the finish reason. That relates acceptance to context
length offline. Off by default; written once per request, never per token; a
failed write warns and turns it off for that engine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — lossless sampling on D at every point (to validate at c512 / c1024), megakernel and spec-log knobs

- D_LOSSLESS now defaults to 1 at every point. c192 was measured (R9c);
  c512 and c1024 are validated on this branch (LLM-Booster #874).
- D_MEGAKERNEL=1 sets AITER_MEGAKERNEL=1 on D: aiter's decode megakernel
  (ROCm/aiter#7345, LLM-Booster #865). It is off by default, to be A/B'd at
  c192, also with the shared expert off its side stream
  (ATOM_DUAL_STREAM_MOE_TOKEN_THRESHOLD=0), since the megakernel needs no
  kernel running beside it.
- D_SPEC_LOG sets ATOM_SPEC_REQUEST_LOG on D: per-request acceptance against
  context length (LLM-Booster #878).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — keep lossless sampling's default at c192 only; c512 / c1024 are #874's

LLM-Booster #874 (lossless sampling at c512 / c1024) and the c1024 point now
belong to gbyu. This branch therefore no longer changes their default: D_LOSSLESS
is on at c192 only, as on k3-455-dev. The knob stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* diagnostics: a P/D request's wait for its KV, hop by hop (LLM-Booster #883); ATOM_REQUEST_LOG

At c192 a request waits ~0.5 s on D before its first decode. D's own metrics
put ~96% of it in pd_kv_transfer_seconds: the MoRIIO write-mode hand-off after
P has finished. This change logs where that hand-off goes.

- ATOM_SPEC_REQUEST_LOG becomes ATOM_REQUEST_LOG, one JSON line per finished
  request. Besides the speculative counters it records ttft_ms and e2e_ms; on
  a P/D consumer it also records park_ms (began waiting for the remote KV) and
  kv_ms (the scheduler found it arrived). It is written once per request and
  only when the env names a path prefix.
- Under ATOM_MORIIO_TRANSFER_STATS:
  - On the producer, each push's stats line gains queue_ms (from the write
    request arriving to the write service taking it) and its PP stage.
  - On the consumer, each receive logs gate_ms (until the forwards queued
    before it finish and the write is asked for), report_ms (until the last
    producer stage reports) and pickup_ms (until an engine step takes it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — request_log_report.py (#878) and pd_timeline_report.py (#883)

Two stdlib-only readers for the new diagnostics:
- request_log_report.py: DSpark acceptance and tokens per forward by
  context-length bin, from ATOM_REQUEST_LOG.
- pd_timeline_report.py: where a P/D request's wait for its KV goes, from
  the MoRIIO transfer stats and write timeline lines
  (ATOM_MORIIO_TRANSFER_STATS=1) and the request log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — replay_turns.py, to tell length from content in DSpark's acceptance drop (#878)

DSpark acceptance falls as c192's agentic trajectories deepen (0.34 to 0.27).
The draft's own card reports only a small drop on ~95k-token documents
(AA-LCR 3.23 against a 3.73 mean, at temperature 1.0), and it trained on
single-turn and chat prompts. So the deep turns' content (tool output, ~150
turns deep) may matter more than their length.

The tool replays three categories of recorded turns through the router:
- early turns;
- deep turns;
- the deep turns cut to a short history: the system prompt, the first user
  message, then the newest whole exchanges, never starting with a tool
  result.
It then joins D's ATOM_REQUEST_LOG to report the acceptance per category.
It is stdlib-only.

On R5b's events the selection takes 8 s and gives:
- early: median 56 KB, turn index 21;
- deep: median 435 KB, turn index 156;
- deep_cut: median 117 KB, turn index 157.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — replay_turns.py records what each turn generated (prose or a tool call) and splits acceptance by it

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* DSpark: ATOM_DSPARK_DRAFT_WINDOW, the newest W context tokens a paged draft block attends (LLM-Booster #878)

Kimi-K3's DSpark acceptance collapses past ~120K tokens of context (E17 c192,
12-02: 0.43 at 96-104K, 0.19 at 128-136K, 0.05 past 176K), while the draft's
card verifies it only up to AA-LCR's 115K. With rope, q.k depends only on the
distance, so attending the newest W tokens keeps every distance the draft sees
in that range. Off by default. A windowed variant of the KV index generator
(kv_indices_generate_window_triton) writes each row's tokens from its first
one; the shared generator is unchanged. CSR MLA decode only, no DCP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — c192 defaults to P_TRANSFER_SLOTS=0 (#883) and a 96K DSpark draft window (#878)

12-02, E17 05-08, c192, 1x613 (R11c) against 12-01's R9c: interactivity
64.7 -> 68.2, 438 -> 480 tok/s/GPU, TTFT p50 1.14 -> 0.86 s. D's KV wait
0.43 -> 0.16 s: P staged each finished prefill's KDA state into its transfer
slot at the next step of every PP stage. The draft's acceptance at 128-144K
0.185 -> 0.410. c512 / c1024 keep 128 transfer slots and no window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — c192 defaults to the MoRIIO write thread on P; record the 12-02 code (aiter heads-mla build)

Every 12-02 c192 run (R11b / R11c / R11d) had ATOM_MORIIO_WRITE_THREAD=1 on P;
with the transfer slots off it sends each push as soon as it is asked for,
not at each PP stage's next step, so the recipe needs it to reproduce the
measured hand-off. The note now says which aiter build the 12-02 numbers used
and marks the 1x613 numbers as early-window only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* recipes: 455-k3 — 12-02 c192 full-window result with both fixes (R11d: 58.5 interactivity, 530 tok/s/GPU)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 04c31e3)

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.

3 participants