Repository navigation
Conversation
…outed 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 <noreply@anthropic.com>
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
Path scope:
|
…quantize launch before it DeepSeek-V4.1's shared expert is a native MXFP8 module (group32 E8M0 scales) computed apart from the routed experts. Its gate_up GEMM quantized its BF16 input itself (quantize_fp8(x)) on every layer and every step: on the target layers' dense path, inside the routed MegaMoE call that computes it (shared_in, ROCm#3894), and on the three DSpark draft layers. x is the FFN seam's normed output, and the seam's HIP Mega-MHC launch can write the same MXFP8 pair next to the BF16 rows (out_dtype="mxfp8", what the attention seam already does for wqkv_a), bit for bit quantize_fp8 of those rows. - Block (deepseek_v41/model.py): the FFN seam asks for the pair (hc_ffn_fuse_quant) where the HIP seam writes row-major scales and the MoE takes it (MoE.takes_mxfp8_input); ffn_forward hands (bf16, fp8, e8m0) to the MoE. - V4 MoE: takes_mxfp8_input holds for a shared expert that reads the pair (Expert.reads_mxfp8_input: native group32 FP8 gate_up, not the BF16 fallback) on the layer's own stream (no dual-stream / comm-fused op, which carry the BF16 rows alone). single_stream_moe_forward passes the pair to the dense shared expert, whose gate_up reads it instead of quantizing x, or, on a shared_in layer, to the routed call (routed_with_shared_mxfp8). - flydsl_mega_experts: moe_forward_shared_mxfp8 is moe_forward with the pair as two more (uint8) arguments of a custom op; the layer holds it while the call runs, and shared_in's fused kernel and its dense fallback both read it. A pair of other rows is ignored (x is quantized as before). Precision and formats are unchanged (E4M3, one E8M0 ceil scale per 32 columns); the shared expert is still computed in FP8 on its own. No new switch or environment variable: the pair is byte for byte what the GEMM would make, so it is on wherever the conditions hold. Tests: tests/models/deepseek_v41/test_ffn_seam_mxfp8.py (where the pair is asked for and where it goes; GPU: the seam's pair against quantize_fp8 over 1-4096 rows, and the dense shared expert on real checkpoint weights of a target and a draft layer, pair vs BF16 rows, byte for byte), tests/test_mega_shared_in.py, tests/test_mega_decode_capacity.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8a4ad5f to
8aeae71
Compare
|
Updated (force-pushed, new head 8aeae71): the implementation is replaced with a wider one.
Still draft: depends on #3894 and ROCm/aiter#8491. |
… one launch (silu_mul_mxfp8) On the dense shared-expert path (the three DSpark draft layers every step, and target-layer row counts the routed MegaMoE call does not fuse, prefill included) silu_and_mul wrote the BF16 product and w2's native group32 FP8 GEMM then quantized it (quantize_fp8). AITER's silu_mul_mxfp8 (module_dsv41_seg_fuse, ROCm/aiter#8871) does both in one launch: the product is rounded to BF16 and quantized with the same group-32 MXFP8 math, so w2 gets the same codes and E8M0 scales. - model_ops/activation.py: silu_mul_mxfp8_available() (gfx950 and an AITER with the op; otherwise the unfused path is kept) and the silu_mul_mxfp8_fuse custom op. - Expert.w2_takes_silu_mul_mxfp8(): a native group32 FP8 w2 (not the BF16 fallback) whose padded input width is a multiple of 32 and half the gate_up output; Expert.forward uses it for an ungated call. The Triton fused_clamp_act_mul path (ATOM_V4_USE_TRITON_FUSION) keeps precedence. - tests: which experts take it, the call wiring, the op against silu_and_mul + quantize_fp8 byte for byte, and real-checkpoint shared experts (layers.10/39, mtp.0/2) against the fully unfused chain. Kernel from the DeepSeek-V4.1 DEP8 AgentX PoC (plugin_poc PR ROCm#129, Bin Ding). Co-authored-by: Bin Ding <Bin.Ding@amd.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Update (11-28): added the second commit
Still stacked on #3894; will rebase and mark ready once it lands. |
Stacked on #3894 (MegaMoE shared_in caller, needs ROCm/aiter#8491). This branch carries #3894's commit rebased on current
main; please review only the top two commits (perf(dsv41): the FFN seam writes the shared expert's MXFP8 input ...andperf(dsv41): the dense shared expert's SiLU-mul and w2 input quant in one launch (silu_mul_mxfp8)). I will rebase ontomainonce #3894 lands.Depends on ROCm/aiter#8871 for the second commit (new op
aiter.ops.dsv41_seg_fuse.silu_mul_mxfp8). Without it (or off gfx950) ATOM detects the missing op and keeps the unfused launches, so this PR is safe to merge before the AITER PR reaches the CI image.Update (11-28): added the second commit (S2,
silu_mul_mxfp8) and the full end-to-end A/B of S1 + S2 (see Performance).Update (11-27): the implementation is replaced. The first version only covered the fused
shared_inpath and handed the pair over through a one-entry slot besidemoe_forward. This version passes the pair as arguments through the MoE (amoe_forwardvariant custom op) and covers every place the shared expert quantizes its input: the target layers' fusedshared_inpath, its dense fallback (rows the small-input kernel does not take, prefill), the target layers withoutshared_in, and the three DSpark draft layers.Root cause
DeepSeek-V4.1's shared expert is a native MXFP8 module (E4M3, one E8M0 scale per 32 columns), computed on its own next to the routed experts. Its
gate_upGEMM quantized its BF16 input itself (quantize_fp8(x)) on every layer of every step:shared_in, [DeepSeek-V4.1] MegaMoE: target layers hand their FP8 shared expert to the routed call (aiter shared_in, needs ROCm/aiter#8491) #3894): the separate quantize beforemegamoe_small_stage1, or inside the dense fallback;shared_in, and all prefill rows: the dense chainquantize_fp8(x) -> gate_up -> silu_and_mul -> quantize -> down;xis the FFN seam's normed output, and the seam's HIP Mega-MHC launch can write the same MXFP8 pair next to the BF16 rows (mega_mhc(out_dtype="mxfp8"), which the attention seam already uses forwqkv_a). The pair is byte for bytequantize_fp8of those BF16 rows, so the shared expert can read it instead of launching its own quantize.Change
deepseek_v41/model.py(Block): the FFN seam asks for the MXFP8 output (hc_ffn_fuse_quant) where the HIP seam writes row-major scales (fuse_quant_supported) and the MoE takes the pair (MoE.takes_mxfp8_input);ffn_forwardhands(bf16, fp8, e8m0)to the MoE. Decided once after loading, like the attention seam'shc_fuse_quant.deepseek_v4/__init__.py:Expert.reads_mxfp8_input(): a native group32 FP8gate_up(not the BF16 fallback);Expert.forward(..., x_fp8=, x_scale=)feeds the pair togate_upinstead of quantizingx. Nothing else in the chain changes.MoE.takes_mxfp8_input(): such a shared expert on the layer's own stream (the dual-stream and comm-fused ops carry the BF16 rows only, so they keep today's path).MoE.single_stream_moe_forward(x, x_fp8=None, x_scale=None): the dense shared expert gets the pair; on ashared_inlayer the routed call gets it (routed_with_shared_mxfp8).router_logits(x)is factored out ofrouted_expert_forward(V4.1 already overrides it).flydsl_mega_experts.py:moe_forward_shared_mxfp8ismoe_forwardwith the pair as two more arguments of a custom op (aiter::moe_forward_shared_mxfp8; the pair crosses the op boundary as uint8 views because Inductor cannot functionalize a mutating op carrying an E8M0 tensor). The layer holds the pair while the call runs;shared_in's fused kernel (SharedExpertInput.x_fp8 / x_scale) and its dense fallback both read it. A pair whose row count does not match is ignored andxis quantized as before.deepseek_v41/moe.py:forward(hidden, hidden_fp8=None, hidden_scale=None); theshared_incall records its TBO stream likerouted_expert_forward.No new switch or environment variable: the pair is exactly what the GEMM would compute, so it is on wherever the conditions above hold (native MXFP8 shared expert, single-stream MoE, HIP Mega-MHC seam with row-major scales: gfx950, and gfx1250 through
scale_row_major). Precision and format are unchanged; the shared expert is still computed in FP8 on its own (SA rules: 48 local experts / top-6, shared expert not fused into the routed experts, draft not merged).Second commit: SiLU-mul +
w2's input quant in one launch (silu_mul_mxfp8)On the dense shared-expert path (the three draft layers every step, target-layer rows
shared_indoes not fuse, prefill) the chain still ransilu_and_mul(BF16 product) and thenw2's ownquantize_fp8of it. ROCm/aiter#8871 addssilu_mul_mxfp8:silu_and_mul's kernel body copied statement for statement with the Mega-MHC group-32 MXFP8 epilogue, so the product is rounded to BF16 and quantized with the same math;w2gets the same codes and E8M0 scales.model_ops/activation.py:silu_mul_mxfp8_available()(gfx950 and an AITER that has the op) and thesilu_mul_mxfp8_fusecustom op.Expert.w2_takes_silu_mul_mxfp8(): a native group32 FP8w2(not the BF16 fallback) whose (padded) input width is a multiple of 32 and half thegate_upoutput.Expert.forwarduses it for an ungated call; the Tritonfused_clamp_act_mulpath (ATOM_V4_USE_TRITON_FUSION) keeps precedence, and a gated call (weights) keepssilu_and_mul.gate_up(seam pair) -> silu_mul_mxfp8 -> w2(pair): 3 launches instead of 5. The fusedshared_inpath already does act + quant inside the MegaMoE kernel, so S2 only touches the dense path.The kernel comes from the DeepSeek-V4.1 DEP8 AgentX PoC (coderfeli/plugin_poc PR #129, commit 158b4b5, author Bin Ding); the commit carries
Co-authored-by: Bin Ding.Correctness
mainwith AITERmain(tests/models/deepseek_v41/test_ffn_seam_mxfp8.py):quantize_fp8of the BF16-only seam's norm, with and without the owed post, rows 1, 5, 6, 48, 128, 186, 192, 512, 513, 2048, 4096 x 2 inputs (with large per-row dynamic range): FP8 codes and E8M0 scales identical byte for byte, and every BF16 output (residual / normed / pre / post / comb) identical to the BF16-only seam. An extended sweep over 33 row counts from 1 to 16,384: 132 cases, 0 mismatches.mtp.0), from the seam's pair vs from the BF16 rows (weights preshuffled as loaded, 32x32 scales, swiglu limit 10): output identical byte for byte. Extended sweep: layers 10 and 39, draftmtp.0andmtp.2, 33 row counts from 1 to 16,384 each, 0 mismatches; flipping one FP8 code of the pair does change the output, so the comparison is sensitive.tests/models/deepseek_v41/test_ffn_seam_mxfp8.py, 39 passed):silu_mul_mxfp8vssilu_and_mul+quantize_fp8, widths 2304 / 320 / 576 / 32 (and 4096 in an extended sweep), clamp 10 and off, 1-16,384 rows, 3 seeds, with all-zero, clamped, 1e-30-scale and silu ~ 0 rows: 894 cases, 0 mismatches in codes or scales. Real checkpoint shared experts (layers 10 / 39, draftmtp.0/mtp.2), 33 row counts each, swiglu limit 10 and 0: S2 alone from BF16 rows and S1 + S2 from the seam's pair both give the fully unfused chain's bytes (264 cases, 0 mismatches); flipping one FP8 code of the op's output changesw2's output. Also undertorch.compile(fullgraph=True, dynamic=True)and in a captured HIP graph replayed on new inputs: identical bytes. CPU tests: the S1 list above 269 passed / 81 skipped with the same 7 pre-existingtest_moe_streams.pyfailures; the failure set overtests/models/deepseek_v41is identical with and without this commit.torch.equal, first calls per row count and site, eager only): 49,941 checks over 2,293 row counts (1-16,384, decode and prefill), 0 mismatches (seam pairs vsquantize_fp8of the seam's norm 25,294,shared_ininput 12,233, the follow-up's act pair 12,414). Server logs: every fusedshared_incall received the seam's pair (0 fell back to a separate quantize); draft layers never tookshared_in.shared_in-only first version; 0.9265 for stack v3 below (threshold 0.9157).tests/test_mega_shared_in.py,tests/test_mega_decode_capacity.py,tests/model_ops/test_comm_fused_moe.py,tests/model_ops/test_mhc_pre_delayed_backend.py,tests/models/deepseek_v41/{test_compilation,test_dspark,test_math}.py,tests/attentions/deepseek_v41/test_tbo.py: 261 passed, 71 skipped. (tests/models/deepseek_v41/test_moe_streams.pyfails 7 tests onmainas well: its V4 MoE stand-in does not takeenable_eplb; unrelated to this change.)Performance
All end-to-end numbers: DeepSeek-V4.1-Flash, MI355X, DEP8, AgentX, SA-compliant configuration (48 experts per rank / top-6, shared expert in FP8 on its own, draft not merged, draft lm_head BF16), dynamic EPLB, golden AL 3.51 for perf runs, server restarted every run. They come from our experimental stack (an earlier base with #3894 and aiter#8491 ported), not from this exact branch.
Full A/B of S1 + S2 (11-28), our experimental stack, same node, 900 s per run, ordered A,B,B,A (A = stack without, B = with S1 + S2; same AITER build in both arms):
Both B runs' p90 are above both A runs' at both concurrencies. GSM8K (no fixed acceptance length): B 0.9325 +/- 0.0069, A 0.9303 +/- 0.0070 (threshold 0.9157); DSpark acceptance 0.4859 vs 0.4869. Smoke 16/16. An online
torch.equalcheck run with S1 + S2 (c512, 300 s): 48,085 checks over 2,191 row counts, 0 mismatches. Every run's server log checked for the SA configuration (48 local experts / top-6, draft top-3 / 16 not merged, shared expert never inside the draft MegaMoE, no FP8 draft lm_head). Verdict: no regression, slightly better p90 / TPOT within noise; kept as fewer launches with identical numerics.S2 kernel (one MI355X, CUDA graph, back to back):
silu_and_mul+quantize_fp8(mid)4.8-6.0 us vssilu_mul_mxfp82.6-3.6 us at 1-512 rows (2.1-2.4 us saved per dense shared expert call), 23 us saved at 16,384 rows.Kernel level (one MI355X, inside a CUDA graph, per layer):
quantize_fp8(x)costs 2.2-2.9 us at 1-512 rows; writing the pair from Mega-MHC adds 0.1-0.6 us, so 1.7-2.4 us saved per layer at decode widths (24 us at 16,384 prefill rows). About 0.08-0.10 ms per decode step over 40 target + 3 draft layers in isolation; under serving loadquantize_fp8measured 4.4 us per call in a trace.Prototype of this version (
shared_in+ dense + draft coverage), c512, 900 s per run: total throughput -0.12%, interactivity p90 +0.21%, both inside run-to-run noise (+/-0.5%); one run per arm (the node went to maintenance before the second pair).First version (
shared_inonly), c512, A,B,B,A x 900 s: mean decode step 16.29 -> 16.17 ms (-0.11 ms); throughput -0.11% and p90 -0.21% (noise).Stack v3 (this item's first version together with two other small items, perf(dsv41): route V4.1 decode steps (<=128 rows) in one launch after the gate GEMM, 48-expert layout included #3938 and [DSV4.1] DSpark: DP-shard the draft head under ATOM_DP_DRAFT_ARGMAX (bit-identical, measured GEMM pad) #3939), A,B,B,A x 900 s: c512 total throughput +0.59%, p90 +1.12%; c128 +0.86%, p90 +3.46%, mean decode step 8.81 -> 8.51 ms.
So on its own this is below what an end-to-end A/B resolves at c512; it is kept as a strictly-fewer-launches, bit-identical change, measured together with the other small items.
Test plan
quantize_fp8, dense shared expert on real weights (target + draft layer)silu_mul_mxfp8vssilu_and_mul+quantize_fp8; real-weight dense chain S1 + S2 vs fully unfusedscale_row_majorpair): pending; S2 is gfx950-only (the op is not used elsewhere)ci:atom)🤖 Generated with Claude Code