Repository navigation
[FlyDSL] [MoE] DeepSeek-V4.1 TP4 A8W4: stage 1 -> stage 2 in one launch up to 512 tokens, exact stage-1 FP8 quant rule (traceability) - #8
Draft
amd-pedghazi wants to merge 1 commit into
Conversation
… exact stage-1 FP8 quant rule The tested build's code: a new FlyDSL module (md5 be081d13) traces AITER's stage-1 body and the v2-layout stage-2 tile into one kernel with per-sort-block ready counters, behind an opt-in env switch with row-limit and occupancy settings. The builder gets trace-time hooks and the exact stage-1 FP8 epilogue (opt-in switch and key list), md5 7bdda7b7. File and env-var names are the build's; ROCm#8658 is the upstream form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 25, 2026
amd-pedghazi
force-pushed
the
w48/dvh-fused-s12
branch
from
November 25, 2026 09:00
17ae2ba to
23d4f81
Compare
amd-pedghazi
force-pushed
the
w48/a5b-base
branch
from
November 25, 2026 09:00
4234d6f to
0bd8f9f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream draft of this change, ported to ROCm/aiter main (FlyDSL 0.5.3, stacked on ROCm#7917 and ROCm#7918, not GPU-tested yet): ROCm#8658.
Draft inside the fork, on the AITER base of a tested DeepSeek-V4.1-Flash build (MI355X, ROCm 7.2.4, FlyDSL 0.4.0). Not opened against
ROCm/aitermain yet, see "Why not main" below.Summary
For DeepSeek-V4.1-Flash TP4 on gfx950 (A8W4: MXFP8 activations x MXFP4 weights;
model_dim5120,inter_dim640, 385 experts, top-7),fused_moeruns MoE stage 1 and the v2-layout stage 2 as one kernel launch for calls of up to 512 tokens (DSpark verify steps), and the stage-1 FP8 epilogue can quantize with the exact rule of the two-kernel path. Both are opt-in through environment variables.The only similar upstream PR, ROCm#8381 (closed, draft), is written for another shape (H5120 / I2304, top-6 / top-3, EP8) with its own kernels on FlyDSL 0.5.0. This PR instead traces AITER's own stage-1 body and AITER's v2-layout stage-2 tile (
compile_gemm2_a4w4_port(_composition=...)) into one kernel, so it keeps the tuned tiles and the fused output can be compared bit for bit with the two-launch path.Motivation
At 257-512 tokens, the stage-1 and stage-2 launches of a verify-step MoE call each leave the GPU partly idle at their start and end. One launch removes one launch gap and lets stage-2 tiles start while later stage-1 tiles still run.
Changes
aiter/ops/flydsl/kernels/devb_fused_s12.py:sc1), waits for its stores, and adds 1 to its sort block's ready counter;AITER_DEVB_FUSED_S12=1installs it for the process (it holds the stage-1 launch of afused_moecall and launches it with the stage-2 launch of the same call);DEVB_FUSED_MAX_ROWS(512 in the tested build) caps the token count,DEVB_FUSED_OCC(3 in the tested build) sets the LDS size for 3 workgroups per CU. The reduction kernel after stage 2 is unchanged.mixed_moe_gemm_2stage_common.py:SharedAllocatorper kernel, a call after each stage-1 tile and around each stage-2 tile); the stage-1 grid moves into_grid1so the fused kernel can reuse it;fp8_exactfor the stage-1 FP8 epilogue (AITER_DEVB_S1FP8_EXACT=1): values rounded to bf16, amax floored at 1e-10, e8m0 = ceil_pow2(amax / 448), asfused_dynamic_mxfp8_quant_moe_sortdoes. Without it the FP8 epilogue uses AITER's own rule (round to the nearest power of two, 8 bits of headroom), and the MoE output error goes from 0.0268 to 0.0305 (relative L2);xcd_swizzle0 and to the<tile_m>/<waves_per_eu>/<xcd_swizzle>keys listed inAITER_DEVB_S1FP8_EXACT_KEYS. The tested build sets32/2/1,32/3/4,64/3/1: the stage 1 of its 512, 1024 and 2048 verify rows. The prefill rows (t64,w4,xcd1; 4096-32768 tokens) keep AITER's rule. Exact builds get_fp8qxin the kernel name instead of_fp8q.AITER_DEVB_S1FP8_EXACT_KEYSlist) built the same ISA as the unchanged builder for the six standalone kernels of these rows (compiled and compared on CPU). Not repeated for this revision.Why not main
mixed_moe_gemm_2stage_common.py: main lacks [FlyDSL] MoE v2 stage 2: skip the inter_dim padding ROCm/aiter#7917'sstage2_skips_inter_pad(the stage-1 grid code this PR moves) and has a changed FP8 epilogue.SharedAllocator,llvm.AtomicRMWOp, the stage-2 composition API), so a main version needs its own build and GPU test.Performance (if applicable)
fused_moecall, 512-token row (stage 1t32x128x256_w2_gui_xcd1, v2-layout reduce stage 2), real verify routing, CUDA graph, median of 10 rounds, 288 / 320 / 384 / 480 tokensThe serving rows measure this PR together with the XCD-remap verify rows of ROCm#8650; the fused launch alone was not measured in serving. An earlier arm with the fused launch and v2-layout rows but no XCD stage 1 gave +0.90 % (random 8k/1k c256, 2 pairs) against the same baseline.
Testing
gfx950 only (MI355X), so MI250X and MI300X do not apply. No op test is added to
op_tests/yet: the checks below ran with our own scripts (named in "Validation"). The performance box stays unticked until an 8-point serving A/B of this switch alone has run (pending, see below).Documentation
N/A (small opt-in change): the switches are off by default and documented in the module docstring.
Dependencies
Base of this PR (
0bd8f9f0e6): AITER285579b6with earlier ports of ROCm#6170 (stage-1 LDS-DMA wait,dma_wait_fix), ROCm#7917, ROCm#7918 and ROCm#7940 (#2) and of ROCm#7949. None of these is part of this PR. The tested build adds ROCm#8550's hunk on top of this PR's builder (#9); that is not ours either and is not in this PR.Breaking Changes
None. With
AITER_DEVB_FUSED_S12andAITER_DEVB_S1FP8_EXACTunset, nothing changes.PR Self-Review
Reviewed revision
23d4f8169bfe46949c5a8aeb188a23f7f592b395Behavior and intent
With
AITER_DEVB_FUSED_S12=1, afused_moecall of up toDEVB_FUSED_MAX_ROWStokens whose row names an FP8-epilogue stage 1 and a reduce v2-layout stage 2 (or an_fp8stage 1 and a mixed stage 2) runs both stages in one launch. Other calls, and calls during a CUDA-graph capture before the workspace exists, run as before. WithAITER_DEVB_S1FP8_EXACT=1, the selected stage-1 builds quantize exactly like the two-kernel path.Validation and unverified scope
Tested on MI355X (gfx950), ROCm 7.2.4, FlyDSL 0.4.0 (this PR's files at
23d4f8169bplus ROCm#8550's hunk, #9 atf617635ce2):[devb_fused_s12] installed: occ 3, max rows 512on all 4 ranks.fusedvariant in serving (the tested build serves only the v2-layout one).ruff check(the repo's config at the base) reports two C408 findings (dict(...)calls) in the added lines;black --checkwould reformat both files (the base file also fails it). Kept as in the tested build.PR-specific question
N/A (fork draft).
Changed op tests
None.
🤖 Generated with Claude Code
Note (2026-11-25): commit messages on this fork were reworded without file changes; the earlier commit ids stay reachable as tags
keep/<12-char id>(for examplekeep/4234d6fc2ec7).The module, env var and log tag names in this PR are the tested build's; ROCm#8658 renames them (
moe_fused_s12.py,AITER_MOE_FUSED_S12,AITER_MOE_FUSED_S12_MAX_ROWS,AITER_MOE_FUSED_S12_OCC,AITER_MOE_S1_FP8_EXACT,AITER_MOE_S1_FP8_EXACT_KEYS).