Repository navigation
[FlyDSL] MegaMoEV2 DeepSeek-V4.1-Flash: FP8 shared expert computed inside the MegaMoE kernels (shared_in), standalone on main - #8878
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
Re-ran the multi-GPU bit-exactness check on this head (53a9109), MI355X: EP8 24 cases and EP4 26 cases (large / small routes, mixed row counts, 0-row ranks, and the EP4 256 bucket that this PR newly fuses). |
…pert in the MegaMoE kernels forward(shared_in=S) returns routed + shared, bit for bit routed + S.dense() on BF16 tensors: - Small-input route: a v41_shared kernel variant computes the shared expert of the rank's rows before its routed work. Every CTA claims shared units from one rank-local counter (each m-tile's GEMM1 units, then its GEMM2 units, which wait for the m-tile's ready epoch), so any row count up to 512 fits; GEMM2 writes BF16 rows into the combine output and the combine reducers add the routed sum to them. The cross-rank protocol is unchanged. Tiles: 32 rows x 64 / 128 columns below 128 rows, 64 rows x 128 / 256 columns from 128 rows. Buckets with tok_done (at most 4 rows a rank) and row counts whose dense split the tiles do not reproduce run S.dense(). - Large-input route: the dense launches write their rows into a new output and the persistent kernel's combine adds the routed sum (_sha variant); with an FP8 route the kernel reads S's MXFP8 x instead of quantizing x again. - Every other call (staged route, other models, DSpark draft layouts) runs S.dense() and adds it into the routed rows. AITER_MEGA_SHARED_IN=0 takes that path everywhere. - Without shared_in nothing changes: the non-shared kernels keep their names and code. AOT: preload_aot_bundle also loads the shared variants; both MegaMoE caches declare v41_shared_expert.py and AITER_MEGA_SHARED_IN. Based on ROCm#8491 (small-input shared_in) and the 64-row-tile and large-input extensions of ROCm#8878. Co-authored-by: zhiding512 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
53a9109 to
c8265d9
Compare
|
This PR no longer stacks on #8491 (closed). It now stands on What changed against the previous head (53a9109, on top of #8491):
Bit-exactness: New per-layer micro-benchmark on real V4.1-Flash decode routes (MI355X, graph replay, 4 rotating shared-weight copies; not end-to-end), routed + dense chain vs
Details are in the updated description. The caller, ROCm/ATOM#3894, keeps its interface ( |
#8491 was closed; its shared_in is part of #8878 on aiter main with the same interface (SharedExpertInput keyword constructor, forward(shared_in=), used_dense). Only the references and the description of where aiter computes the shared expert change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pert in the MegaMoE kernels forward(shared_in=S) returns routed + shared, bit for bit routed + S.dense() on BF16 tensors: - Small-input route: a v41_shared kernel variant computes the shared expert of the rank's rows before its routed work. Every CTA claims shared units from one rank-local counter (each m-tile's GEMM1 units, then its GEMM2 units, which wait for the m-tile's ready epoch), so any row count up to 512 fits; GEMM2 writes BF16 rows into the combine output and the combine reducers add the routed sum to them. The cross-rank protocol is unchanged. Tiles: 32 rows x 64 / 128 columns below 128 rows, 64 rows x 128 / 256 columns from 128 rows. Buckets with tok_done (at most 4 rows a rank) and row counts whose dense split the tiles do not reproduce run S.dense(). - Large-input route: the dense launches write their rows into a new output and the persistent kernel's combine adds the routed sum (_sha variant); with an FP8 route the kernel reads S's MXFP8 x instead of quantizing x again. - Every other call (staged route, other models, DSpark draft layouts) runs S.dense() and adds it into the routed rows. AITER_MEGA_SHARED_IN=0 takes that path everywhere. - Without shared_in nothing changes: the non-shared kernels keep their names and code. AOT: preload_aot_bundle also loads the shared variants; both MegaMoE caches declare v41_shared_expert.py and AITER_MEGA_SHARED_IN. Based on ROCm#8491 (small-input shared_in) and the 64-row-tile and large-input extensions of ROCm#8878. Co-authored-by: zhiding512 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
c8265d9 to
10159d2
Compare
|
Review pass on this PR, new head 10159d2 (rebased on main a9fb0c1; one new commit on top of the previous three). Kernel code is unchanged; the fixes are in the dispatch, the AOT declaration, the dense-split lookup and the tests.
Validation on MI355X (
|
…ores v41_shared_expert.py: the DeepSeek-V4.1-Flash shared expert with the checkpoint's MXFP8 weights ((16, 16)-preshuffled E4M3, 32x32-block E8M0), computed apart from the MXFP4 routed experts, in tiles that give the bits of the model's dense launches: - GEMM1 (x x [gate | up]) and GEMM2 (activation x down) run gemm_ring._Ring (weights as the scaled MFMA's operand A, zero-initialised accumulators, one 16x16x128 MFMA per 128-K step, K ascending), with an FP8 weight loader and their own epilogues; a split-K 2 dense GEMM is reproduced as 0 + p0 + p1. - GEMM1's epilogue rounds gate / up to BF16 and runs silu_mul_mxfp8's arithmetic (clamp, exp expansion, group-32 E8M0 = ceil_pow2(amax / 448)) with FP32 denormals flushed, and writes the MXFP8 activation in the order the GEMM2 ring copies it. GEMM2 writes BF16 rows. - dense_gate_up_ksplit reads AITER's live tuned table for the split the dense launches run at a row count (0 where the tiles cannot reproduce it). - v41_shared_in_layout: only the EP8 / EP4 / EP2 V4.1-Flash main-model layouts; AITER_MEGA_SHARED_IN=0 turns the in-kernel path off. weights.SharedExpertInput: the shared_in contract (x's MXFP8 pair, the weights and scales, dense()), with a device check. The epilogue arithmetic and the dense split detection follow ROCm#8491. Co-authored-by: zhiding512 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pert in the MegaMoE kernels forward(shared_in=S) returns routed + shared, bit for bit routed + S.dense() on BF16 tensors: - Small-input route: a v41_shared kernel variant computes the shared expert of the rank's rows before its routed work. Every CTA claims shared units from one rank-local counter (each m-tile's GEMM1 units, then its GEMM2 units, which wait for the m-tile's ready epoch), so any row count up to 512 fits; GEMM2 writes BF16 rows into the combine output and the combine reducers add the routed sum to them. The cross-rank protocol is unchanged. Tiles: 32 rows x 64 / 128 columns below 128 rows, 64 rows x 128 / 256 columns from 128 rows. Buckets with tok_done (at most 4 rows a rank) and row counts whose dense split the tiles do not reproduce run S.dense(). - Large-input route: the dense launches write their rows into a new output and the persistent kernel's combine adds the routed sum (_sha variant); with an FP8 route the kernel reads S's MXFP8 x instead of quantizing x again. - Every other call (staged route, other models, DSpark draft layouts) runs S.dense() and adds it into the routed rows. AITER_MEGA_SHARED_IN=0 takes that path everywhere. - Without shared_in nothing changes: the non-shared kernels keep their names and code. AOT: preload_aot_bundle also loads the shared variants; both MegaMoE caches declare v41_shared_expert.py and AITER_MEGA_SHARED_IN. Based on ROCm#8491 (small-input shared_in) and the 64-row-tile and large-input extensions of ROCm#8878. Co-authored-by: zhiding512 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-exact check in the routes suite tests/test_mega_moe_gfx950_shared_in.py (no GPU): which layouts take shared_in, the env switch, SharedExpertInput's contract, the dense split detection, the tiles' LDS, the AOT preload variants, the small / large readiness and MegaMoEV2's dispatch between kernel and dense paths. op_tests/multigpu_tests/test_mega_moe_v2.py --suite routes --network v41_flash: [SHARED_IN] checks forward(shared_in=S) == forward() + S.dense() bit for bit on uniform, uneven and idle ranks of both routes, with AITER_MEGA_SHARED_IN=1 and 0, and times it against routed + dense (--shared-in-only runs just that). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-split whitelist, tile op test - AITER_MEGA_SHARED_IN is read only by MegaMoEV2._forward_shared. It no longer keys the small/large stage1 AOT caches (setting it, even to 1, missed every prebuilt stage1 entry); it is listed in ENV_NOT_CODE. The runtimes' shared_in_ready and preload no longer read it; V4.1-Flash layouts always preload the shared variants. - dense_kernel_ksplit: only kernel families whose split-K order the tiles reproduce (flydsl_mxpsh_*, flydsl_bmm_mxfp8_mfma_* by _sk<N>; flydsl_mxfp8_8w_* via its name parser, 0 with _ns<N>); anything else returns 0 (dense) and is logged once. Lookup errors are no longer swallowed (only ImportError). - op_tests/test_mega_moe_v41_shared.py: the tiles against the dense launches, bit for bit, over every V4.1-Flash tuned M bucket to 512 rows and past it, both tiles; compile_v41_shared_test now has its caller, _TILE_OVERRIDE is gone. - routes suite [SHARED_IN]: per-rank expected kernel path asserted; env restored after the check; --shared-in-only refuses configurations it would not check. - comments: tile rows 32/64, per-wave columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
10159d2 to
58e8515
Compare
|
Rebased onto main a84010d; new head 58e8515 (same four commits, no code change beyond the conflict resolution). Conflicts, both from #8920 (SwiGLU-OAI GEMM1 activation):
Re-tested on MI355X (
|
#8491 was closed; its shared_in is part of #8878 on aiter main with the same interface (SharedExpertInput keyword constructor, forward(shared_in=), used_dense). Only the references and the description of where aiter computes the shared expert change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An AITER before ROCm/aiter#8878 has no SharedExpertInput, and its MegaMoE call takes no shared_in. attach_mega_shared_expert now checks for it at construction and otherwise leaves the shared expert a dense pass beside the routed call (one warning), so such an AITER runs as before instead of failing at the first routed call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o the routed call (aiter shared_in) (#3894) * perf(dsv41): Mega target layers hand their FP8 shared expert to the routed call (aiter shared_in) DeepSeek-V4.1's shared expert (MXFP8 weights with 32x32-block scales) is not fused into the MXFP4 routed experts by default, so a Mega layer ran it as its own dense launches (quantize, gate_up GEMM, act, down GEMM) next to the MegaMoE call. With ROCm/aiter#8491, MegaMoEV2.forward(shared_in=...) computes it inside its small-input kernel where that kernel can, with the same MXFP8 activations and the checkpoint's FP8 weights, and otherwise runs it dense on the caller's stream; either way it returns routed + shared. - attach_mega_shared_expert (flydsl_mega_experts): on a layer every routed call of which reaches run_mega_moe on the rank's own rows with nothing reduced after it (the Mega method; no comm-fused or SP MegaMoE, PCP merge, DP-logical split or experts reduction), run_mega_moe passes the shared expert as shared_in. DeepSeek-V4 MoE attaches it on its target layers (TP 1, single stream) and then adds no shared output of its own; the DSpark / MTP draft layers keep their dense shared expert. - The MXFP8 copy of x is made only when AITER reads it, i.e. for a call it fuses; a call it cannot fuse runs the dense shared expert, which quantizes x itself, so x is quantized once a call either way. - An AITER without shared_in (no weights.SharedExpertInput, which arrives with it) keeps today's path: the shared expert is computed apart. No new switch or environment variable. Tests: tests/test_mega_shared_in.py (lazy MXFP8 copy, where the shared expert is attached, an AITER without shared_in); test_mega_decode_capacity checks run_mega_moe passes shared_in exactly for an attached layer. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(dsv41): shared_in review: weight layout check, layer-id draft test, capability check, tests - attach_mega_shared_expert attaches only shared-expert weights in the layout AITER's shared_in reads: gate_up_proj and w2 both native 32x32-block FP8 linears (no BF16 fallback, no bias) with their E8M0 scale, the weight held in the (16, 16) preshuffle (weight_is_stored_preshuffled, the load's own decision). Otherwise (e.g. ATOM_GROUP32_WEIGHT_PRESHUFFLE=0, row-major weights AITER would read as shuffled) the shared expert stays a dense pass and a warning is logged once per reason. - Draft layers are told apart by layer id (MoE.is_draft_layer: layer_id >= n_layers, as MTPBlock(args.n_layers + i) and V4.1's topology number them), not by the "mtp." prefix. The attach decision is MoE._hand_shared_expert_to_routed. - AITER capability: weights.SharedExpertInput and MegaMoEV2.forward taking shared_in, both required; an AITER missing either keeps the shared expert apart. - Tests (CPU): layout refusals and the one-time warning, preshuffle on/off, AITER without shared_in in either form, target vs draft / TP / dual-stream / comm-fused layers, and the attached layer's forward never calling its shared expert or adding a shared output. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(dsv41): shared_in review: one owner and one attach call, aiter interface imported, eager x quant, CPU tests run in CI - FusedMoE._shared_in_expert (class default None) is the one fact; MoE.__init__ makes one attach_mega_shared_expert call (draft layer, TP, dual stream passed in) and single_stream_moe_forward branches on it. _shared_in_routed, _hand_shared_expert_to_routed and MoE.is_draft_layer are gone. - SharedExpertInput is imported from aiter directly (ROCm/aiter#8491), built with keyword arguments; the capability probe and LazySharedExpertInput are gone and x is quantized once per attached call. - The reduction clauses are FusedMoE.combine_output_is_reduced, shared with combine_accepts_shared. The layout check keeps only what aiter's weights_fit cannot see (preshuffled vs row-major, bias, scale, BF16 fallback). - run_mega_moe: plain if / else around mega.forward, no dict per call. - tests/model_ops/test_mega_shared_in.py runs under atom_under_stubs (CPU CI); gate_up / w2 and x_fp8 / x_scale are checked against distinct tensors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(dsv41): shared_in now comes from ROCm/aiter#8878 #8491 was closed; its shared_in is part of #8878 on aiter main with the same interface (SharedExpertInput keyword constructor, forward(shared_in=), used_dense). Only the references and the description of where aiter computes the shared expert change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(dsv41): shared_in only with an AITER that has it An AITER before ROCm/aiter#8878 has no SharedExpertInput, and its MegaMoE call takes no shared_in. attach_mega_shared_expert now checks for it at construction and otherwise leaves the shared expert a dense pass beside the routed call (one warning), so such an AITER runs as before instead of failing at the first routed call. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
MegaMoEV2.forward(..., shared_in=S)computes DeepSeek-V4.1-Flash's FP8 shared expert inside the MegaMoE kernels and returnsrouted + shared, bit for bitforward(...) + S.dense()(the model's dense FP8 shared-expert launches). The shared expert keeps the checkpoint's MXFP8 weights and is computed apart from the MXFP4 routed experts.This PR now stands on
mainby itself. It takes over the small-inputshared_inof the closed #8491 (by @zhiding512) and this PR's earlier 64-row-bucket and large-input extensions, rebuilt on #8623's ring GEMM cores: the shared tiles reusegemm_ring._Ringinstead of the GEMM helpers #8623 removed, there is no copy of the oldgemm_util, and none of #8491's tuning switches (shared_in_opt,AITER_MEGA_SHARED_IN_OPT, M2, ...) come back.Motivation
V4.1-Flash runs its shared expert as dense FP8 launches next to every MoE layer (quant, gate_up GEMM, SiLU-mul, quant, down GEMM, add): five to six launches and a second pass over the activations per layer. In decode those launches are latency-bound and serialized after the MegaMoE kernel. Computing the shared expert inside the MegaMoE kernel overlaps it with dispatch and routed work and removes the extra launches. The shared expert stays FP8 (not re-quantized to FP4, not merged into the routed experts), so serving configurations that require an unmodified shared expert can use it.
Changes
mega_moe/v41_shared_expert.py(new, V4.1-Flash only): the shared expert's GEMM1 (x x [gate | up]) and GEMM2 (activation x down) tiles ongemm_ring._Ring, with an FP8 weight loader ((16, 16) preshuffle, 32x32-block E8M0 scales) and their epilogues. GEMM1 rounds gate / up to BF16, then appliessilu_mul_mxfp8's arithmetic (with FP32 denormals flushed, as that kernel) and writes the MXFP8 activation in the order GEMM2's ring copies it. A split-K 2 dense GEMM is reproduced as0 + p0 + p1;dense_gate_up_ksplitreads the split from AITER's live tuned table, and only for the dense kernel families whose split order the tiles reproduce (flydsl_mxpsh_*andflydsl_bmm_mxfp8_mfma_*by_sk<N>,flydsl_mxfp8_8w_*without_ns<N>). Any other tuned kernel makes those calls take the dense path, logged once per kernel name. The epilogue arithmetic follows [FlyDSL] MegaMoEV2 V4.1-Flash small-input: shared expert inside the kernel (opt-in), EP4 / EP8 tunes (into #7788) #8491.mega_moe_small_m.py): av41_sharedkernel variant (_v41sh<split>m<rows>n<cols>in its name) runs the shared expert before its routed work. Every CTA claims shared units from one rank-local counter: an m-tile's GEMM1 units, then its GEMM2 units, which wait for the m-tile's ready epoch. Because units are claimed in a loop, every row count up to 512 is covered, not only those with fewer units than consumer CTAs, and 64-row routed tiles are supported. GEMM2 writes BF16 rows into the combine output, and the combine reducers add the routed sum (bf16(f32(bf16(sum)) + f32(shared))). The cross-rank protocol does not change. Tiles: 32 rows x 64 / 128 columns below 128 rows a rank; 64 rows x 128 / 256 columns from 128 rows.mega_moe_large_m.py): the dense launches write the shared rows into a new output, and the persistent kernel's combine adds the routed sum (_shavariant). With an FP8 route, the kernel readsS's MXFP8 x instead of quantizing x again.MegaMoEV2.forward(shared_in=): chooses between the kernel paths andS.dense()added into the routed rows. The dense path is taken for every other call: the staged route, buckets withtok_done(at most 4 rows a rank), row counts whose dense split the tiles do not reproduce, DSpark draft layouts and other models.weights.SharedExpertInput: the input contract from [FlyDSL] MegaMoEV2 V4.1-Flash small-input: shared expert inside the kernel (opt-in), EP4 / EP8 tunes (into #7788) #8491 (keyword construction,dense(),used_dense,weights_fit/fits). It now also checks the device.preload_aot_bundlealso loads the shared variants. The small- and large-input caches declarev41_shared_expert.py.AITER_MEGA_SHARED_INis not part of any cache key: onlyMegaMoEV2's dispatch reads it, it picks kernels without changing any, and it is listed inENV_NOT_CODE. Setting it, to 0 or 1, does not invalidate prebuilt entries.One switch:
AITER_MEGA_SHARED_IN(default1).0takes the dense path for everyshared_incall (for A/B comparisons and debugging). OnlyMegaMoEV2.forward(shared_in=)reads it, per call. This is a V4.1-Flash-specific optimization: only the EP8 / EP4 / EP2 V4.1-Flash main-model layouts (48 / 96 / 192 experts a rank) computeshared_inin a kernel. Callers that do not passshared_insee no change; for them the kernels and their names are the same as onmain.Performance (if applicable)
Per-call micro-benchmarks only (no end-to-end serving runs). MI355X, DeepSeek-V4.1-Flash layer-10 shared expert, a8w4.
Real decode routes (per MoE layer)
Routes recorded from DeepSeek-V4.1-Flash serving with DSpark: a DEP8 dump (layers 0 / 10 / 21 / 32, live EPLB placement, rows per rank cycled to the target count; ranks without rows in the dump take another rank's rows so all 8 ranks are busy), and 72 DEP4 c64 samples (W = max rows per rank from 6 to 54, real per-rank row counts including idle ranks, physical expert ids). Graph replay of 20 calls with 4 rotating copies of the shared weights (as across layers in a step), median of 9 trials, max over ranks, best of 2 alternating rounds. "Before" = routed call + the model's dense chain (x quant, gate_up GEMM,
silu_and_mul, quant, down GEMM) + add; "After" = x quant +forward(shared_in=S). Every case was also checked bit for bit (0 differing elements in all 112 cases: EP8 with and without the busy-rank fill, EP4). Per step = 40 MoE layers.The routed call alone takes 90-219 us (EP8) here; the fused shared expert adds 9-35 us to it, against 24-35 us for the dense chain plus its launches and add after it. At 240 rows the in-kernel cost approaches the dense chain's, so the saving shrinks.
Shared expert alone on one GPU (standalone tile kernels, one workgroup per unit, against the 5 dense launches; both include the x quant): 1-96 rows -2% to +22% (dense 16.0-23.3 us), 128-384 rows +15% to +65%, 512 rows -2%. The standalone tiles are not the fast part: inside MegaMoE they run on CTAs that would otherwise wait for dispatched rows, which is where the saving above comes from. The large-input route does not use the tiles (it runs the dense chain and fuses only the add).
Synthetic routes (uniform random top-6), per call
MI355X. MegaMoEV2 call with the V4.1-Flash layer-10 shared expert. Each number is the median over 9 trials of graph replays of 20 calls, max over ranks, us per call. "Before" is routed +
S.dense(), today's path, with the dense chain the model runs (its own x quant, gate_up GEMM,silu_and_mul, quant, down GEMM). "After" isforward(shared_in=S), including the x quant that buildsS.All other EP8 rows: 16: -6.2%; 192: -7.1%; 384: -3.7%; 1024: -0.7%. All other EP4 rows: 16 to 384: -2.3% to -3.1%; 1024: -1.4%. The routes suite's
[SHARED_IN_TIME]lines show the same, with random shared weights (EP8: -6.9% at 8 rows, -5.6% at 256, -1.3% at 4096). The tile shapes were picked from timings on EP4: 64-row tiles at 384 / 512 rows (-3.5% / -4.5%, against +1.6% / -0.1% with 32-row tiles), and 64 / 128-column units below 128 rows (-8.0% against -5.6% at 8 rows). A call withoutshared_inkeeps main's time: the EP8 small-input route measured within 0.3% ofmainat all 12 row counts of the routes suite.Testing
Bit-exactness (
torch.equalon the BF16 output; the dense reference is the model's chain on the real layer-10 shared expert):Tiles on one GPU (gfx950),
op_tests/test_mega_moe_v41_shared.py(in this PR): 77 row counts from 1 to 16384, covering both sides of every V4.1-Flash tuned M bucket up to 512 rows for the gate_up and down GEMMs, times both tiles (154 cases, random FP8 weights). GEMM1's MXFP8 activation (codes and scales), GEMM2 alone and the chain match the dense launches at the tuned split: 0 differing bytes (split-K 2 at 33 to 64 rows, split-K 1 elsewhere). Earlier, with the real layer-10 shared expert, 26 row counts from 1 to 16384: GEMM1's MXFP8 activation (bytes and E8M0 scales), GEMM2 alone and the GEMM1 to GEMM2 chain all match the dense launches at the tuned split (0 differing elements). All three tile shapes were checked. Putting the weights in MFMA operand A and x in operand B gives the same bits as the dense kernels, which put x in A. Forcing split-K 2 where the table runs split-K 1 changes the output (31 elements at 16384 rows), so following the table is required.MegaMoEV2, EP8 / EP4 / EP2:
forward(shared_in=S)againstforward() + S.dense():Ranks with at most 4 rows (
tok_donebuckets) took the dense path as designed; every other non-empty rank fused. The routes suite's[SHARED_IN]check now asserts this per rank: each rank's path must be the one the route, the bucket and the dense tuned table call for (EP8: 59 of 59 expected kernel-path rank calls, EP4: 30 of 30; withAITER_MEGA_SHARED_IN=0all 60 / 30 non-empty rank calls dense).DSpark draft layout (EP8, 128 experts, top-3):
shared_inalways takes the dense path (used_denseon every rank) and equals routed + dense.Calls without
shared_in: outputs are bit-identical tomain(EP8, 18 row cases from 1 to 8192 rows a rank including uneven and idle ranks, two layers: 288 rank outputs, 0 differing elements against main a84010d; also 0 against a9fb0c1 before the rebase). The generated ISA of the non-shared kernels is identical tomain. This covers every small-input bucket kernel on EP8 and EP4, and the large-input kernel on EP8 and on EP4 (each compiled in its own process).Documentation
Dependencies
Breaking Changes
None.
forward()withoutshared_inis unchanged. ROCm/ATOM#3894 (the caller) keeps its interface: it constructsSharedExpertInputwith keyword arguments and callsforward(shared_in=). Withshared_in, a small-input call returns the combine buffer, asforward()does. A large-input call returns a new tensor of the rank's rows. A call on the dense path returns the routed rows with the shared rows added in place.PR Self-Review
Reviewed revision
58e8515
Behavior and intent
Calls without
shared_inbehave exactly as onmain. Withshared_in, the V4.1-Flash main-model layouts compute the shared expert in the small-input kernel (decode) or write it into the large-input call's output (prefill). Every other call runs the dense launches. Theshared_inresult is bit-identical torouted + S.dense()on every path. The path is chosen automatically from the layout, the bucket and the dense tuned table;AITER_MEGA_SHARED_IN=0forces the dense path.The review points on #8491 are addressed:
SharedExpertInputchecks the device;slice_output=Falsekeeps its meaning;op_tests([SHARED_IN]below).Validation and unverified scope
The routes suite passed on EP8 and EP4 (accuracy, edges, alternation, epoch wrap, graph replay, timing, and the
[SHARED_IN]check withAITER_MEGA_SHARED_IN= 1 and 0). The CPU tests pass (315 passed, 1 skipped, in the files above plustests/test_aot_drivers.py). WithAITER_FLYDSL_AOT_RUNTIME_BUILD=0,--shared-in-onlyon EP4 had no AOT misses withAITER_MEGA_SHARED_INunset, 0 and 1 on the same cache. Routes-suite--time-onlyon EP8 (main and this branch alternating, two rounds each): the small-input route withoutshared_inis within 0.44% ofmainat all 12 row counts (measured against main a9fb0c1, before the rebase). The AOT prebuild of the EP8 V4.1-Flash profile holds every small- and large-input kernel theshared_incalls launch: a run withAITER_FLYDSL_AOT_RUNTIME_BUILD=0had no misses of the small- or large-input kernels. The dense GEMMs come from their own AOT profiles. In that run the MXFP8 quant of the large-input dense chain's activation (n = 2304) was a miss;preload_aot_bundlenow also loads it.Not measured here:
a4w4routes withshared_in(the kernel paths are the same; thea4w4large-input route quantizes x to FP4 itself);PR-specific question
The kernel files change (a
v41_sharedsmall-input variant and a_shalarge-input combine), and the change is V4.1-Flash specific by design:v41_shared_expert.py;main;Changed op tests
op_tests/test_mega_moe_v41_shared.py(new): the shared tiles against the dense launches on one GPU, bit for bit, over the V4.1-Flash tuned M buckets and both tiles.tests/test_mega_moe_gfx950_shared_in.pyalso checks that every V4.1-Flash tuned row up to 512 rows names a kernel the tiles reproduce, so a re-tuned table that would turn the kernel path off is flagged.op_tests/multigpu_tests/test_mega_moe_v2.py:--suite routes --network v41_flashadds[SHARED_IN]. It checks thatforward(shared_in=S) == forward() + S.dense()bit for bit, on the small- and large-input routes with uniform, uneven and idle ranks, with the env switch at 1 (kernel path) and 0 (dense path), and that every rank takes the path expected for it. The switch is restored after the check;--shared-in-onlyrefuses a network, quant or--time-onlycombination it would not check. It also timesshared_inagainst routed + dense.--shared-in-onlyruns just that. No existing op test coveredshared_in; the previous tests of #8491 had no GPU numeric coverage.🤖 Generated with Claude Code