Repository navigation
Conversation
…uant in one launch New JIT module module_dsv41_seg_fuse (own sources, module_activation's flags; no existing module is touched) with one op: silu_mul_mxfp8(input [.., 2d] bf16, limit) -> (q [.., d] e4m3, scale [.., d/32] e8m0) The kernel is act_and_mul_kernel<bf16, bf16, silu, 8, HAS_LIMIT> (activation_kernels.cu) copied statement for statement, with MegaMHCQuantOutput<true>::store (mega_mhc.cu) as its epilogue: the product is rounded to BF16 and the group-32 MXFP8 quant reads those BF16 bits. Output is bit for bit silu_and_mul followed by the group-32 MXFP8 quant (ATOM quantize_fp8 / Mega-MHC out_dtype="mxfp8"). gfx950 only. The kernel comes from the DeepSeek-V4.1 DEP8 AgentX PoC (coderfeli/plugin_poc PR ROCm#129, commit 158b4b5, by Bin Ding). op_tests/test_dsv41_seg_fuse.py: torch.equal against silu_and_mul + a torch group-32 MXFP8 reference, 1..16384 rows, d in {32..4096}, limit 10 and 0, zero rows, values at/beyond the limit, tiny magnitudes. Co-authored-by: Bin Ding <Bin.Ding@amd.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
… 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>
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 |
Motivation
DeepSeek-V4.1's shared expert is a native MXFP8 module (group-32 E8M0 scales) that runs apart from the routed experts. On its dense path (the three DSpark draft layers every decode step, target-layer row counts the routed MegaMoE call does not fuse, and prefill) the chain is
gate_up GEMM -> silu_and_mul -> quantize_fp8 -> w2 GEMM:silu_and_mulwrites the BF16 product and the next launch reads it back only to quantize it to group-32 MXFP8 forw2.This PR adds one op that does both in one launch, bit for bit the two launches it replaces.
What it adds
New JIT module
module_dsv41_seg_fuse(its own sources; built withmodule_activation's flags; no existing module or source is touched, and nothing is imported fromaiter/__init__, so a process that never calls it never builds it):csrc/kernels/dsv41_seg_fuse_kernels.cu:act_and_mul_kernel<bf16, bf16, silu, 8, HAS_LIMIT>(activation_kernels.cu) copied statement for statement (same clamp, samev_pk_mul_f32, same launch geometry), withMegaMHCQuantOutput<true>::store(mega_mhc.cu) as its epilogue: the product is rounded to BF16 and the quant reads those BF16 bits (amax floor 1e-10, E8M0 = ceil_pow2(amax / 448), E4M3 RNE viacvt_scalef32_pk_fp8_bf16). A lane quad owns one group of 32.csrc/include/dsv41_seg_fuse.h,csrc/pybind/dsv41_seg_fuse_pybind.cu,aiter/ops/dsv41_seg_fuse.py,optCompilerConfig.jsonentry.dmust be a multiple of 32.Why not the existing
silu_and_mul_quant: its FP8 path quantizes the FP32 product with an FP32 scale (amax / 448), so its codes differ fromsilu_and_mul+ group-32 MXFP8 of the BF16 result, which is whatw2's native MXFP8 GEMM would compute. This op keeps the numerics of the unfused chain exactly.Provenance
The kernel comes from the DeepSeek-V4.1 DEP8 AgentX PoC: coderfeli/plugin_poc PR #129 (commit 158b4b5,
csrc/kernels/dsv41_seg_fuse_kernels.cuin its AITER patch), author Bin Ding. The kernel body is unchanged; this PR renames comments, adds the op test and formats with clang-format. The commit carriesCo-authored-by: Bin Ding.Correctness
op_tests/test_dsv41_seg_fuse.py(torch.equal on codes and scales) againstaiter.silu_and_mulfollowed by a torch group-32 MXFP8 reference: rows 1..16384 (33 counts), d in {2304, 32, 512, 1536, 4096}, limit 10 and 0, three seeds, with an all-zero row (amax floor), values at/beyond the clamp, 1e-30-scale rows and a row with silu ~ 0.GPU results (MI355X, gfx950):
op_tests/test_dsv41_seg_fuse.py284 passed, 48 skipped (the skips are rows > 1024 at widths other than 2304, by design), 0 failed; tested by overlaying this PR's files on the AITER build of therocm/atom-dev:nightly_202611251520image (fb3f506); the module builds on its own. Also checked undertorch.compile(fullgraph=True, dynamic=True)and inside a captured HIP graph (replay on new inputs): identical bytes.ATOM-side checks (ROCm/ATOM#3940): the op against
silu_and_mul+ ATOMquantize_fp8, and the real DeepSeek-V4.1-Flash shared-expert chain (layers.10/39, mtp.0/2) fused vs unfused: 894 op cases (widths 2304 / 320 / 576 / 32 / 4096, limit 10 and 0, 1-16,384 rows, 3 seeds, edge rows), 0 mismatches; chain: 4 checkpoint shared experts x 33 row counts x limit 10 / 0, 0 mismatches, and flipping one FP8 code of the op's output changes thew2output (the comparison is sensitive).Performance
Per launch, CUDA-graph back to back, one MI355X, V4.1-Flash shared expert (d = 2304), µs:
End to end (DeepSeek-V4.1-Flash, MI355X DEP8, InferenceX AgentX, SA-compliant configuration: 48 local experts / top-6, FP8 shared expert computed separately, draft layers not merged, BF16 draft lm_head; 900 s per run, runs ordered A,B,B,A on the same node; B = this op plus the FFN-seam MXFP8 input of ROCm/ATOM#3940, A = without; both arms on the same AITER build):
GSM8K (no fixed acceptance length): B 0.9325 ± 0.0069, A 0.9303 ± 0.0070; DSpark acceptance 0.4859 vs 0.4869. Both P90 runs of B are above both runs of A at both concurrencies; the gain is small (the launches it removes are ~2 µs each) and is not claimed beyond "no regression, fewer launches".
Consumers
ROCm/ATOM#3940 (uses it on the dense shared-expert path when
aiter.ops.dsv41_seg_fuseimports and the GPU is gfx950; otherwise ATOM keeps the unfused launches).🤖 Generated with Claude Code