Repository navigation
fix(fused_moe): require KBatch >= 2 for block-fp8 split-k - #3997
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
valarLip
previously approved these changes
Jun 29, 2026
Contributor
|
|
get_ksplit could pick a split where each K partition owns a single k-tile (KBatch = model_dim / (split * 256) == 1). In that case the CK stage1 kernel still uses atomic-add but skips the output memset, accumulating onto uninitialized memory and producing gibberish at bs=1 (e.g. Qwen3.5-FP8 TP8, K=4096, split=16). Add the KBatch >= 2 condition in get_ksplit, and guard ck_moe_stage1 so splitk from tuned CSV / AITER_KSPLIT cannot bypass it. Add op_tests/test_moe_blockscale_ksplit.py: exercises the high-level fused_moe() CK 2-stage path (which get_ksplit feeds, unlike test_moe_blockscale) against a bf16 pre-quant reference, asserting row-0 rel error stays within fp8 block-quant noise.
ZiguanWang
force-pushed
the
fix-fp8-moe-kbatch1
branch
from
July 14, 2026 07:16
ec92287 to
b22d6e9
Compare
Contributor
Author
already removed. |
junhaha666
approved these changes
Jul 14, 2026
3 of 4 tasks
jin-amd
added a commit
to jin-amd/aiter
that referenced
this pull request
Sep 30, 2026
…it-K The default fp8-blockscale 2-stage fused MoE returns wrong output whenever get_ksplit() asks for model_dim / 256 splits, one 256-wide K tile each. This happens at small decode batches on gfx942 (cu_num 304), for example at one token for (model_dim, inter_dim) = (4096, 256) with 288 experts and top-8, (7168, 128) with 257 experts and top-9, and (2048, 384) with 128 experts and top-8. Every output element differs from the reference, and the values change from run to run. ck_moe_stage1_gemm turns the requested number of splits into CK's KBatch, the number of KPerBlock tiles each split covers: K / (splitk * KPerBlock). With one tile per split that is 1, which DeviceMoeGemmBlockScale reads as "no split": it runs a single z-block over the whole K and skips zeroing the output. The split-K instance still accumulates into that output atomically, and fused_moe allocates it with torch.empty. StrideE also keys the split-K layout (2 * N per row) on KBatch > 1, so the rows overlap as well. ROCm#3997 fixed this in ck_moe_stage1() by turning split-K off for such requests, and the MoE refactor in ROCm#4394 dropped that guard. This fix sits at the KBatch conversion instead, so no caller reaches KBatch == 1 through split-K, whether the split comes from get_ksplit(), a tuned CSV or AITER_KSPLIT. It also keeps the split rather than turning it off: when splitk would leave fewer than two tiles per split, stage 1 uses fewer splits of at least two tiles, KBatch = 2 or the smallest divisor of the tile count that is at least 2. At the (4096, 256, E=288, top-8) one-token shape the operator then takes 32.1 us, against 41.1 us without split-K. A K of a single tile cannot be split and now fails with an error. Requests that already give two or more tiles per split are unchanged. Signed-off-by: Jin Tao <[email protected]>
4 of 5 tasks
yifehuan
pushed a commit
that referenced
this pull request
Oct 2, 2026
…it-K (#5979) The default fp8-blockscale 2-stage fused MoE returns wrong output whenever get_ksplit() asks for model_dim / 256 splits, one 256-wide K tile each. This happens at small decode batches on gfx942 (cu_num 304), for example at one token for (model_dim, inter_dim) = (4096, 256) with 288 experts and top-8, (7168, 128) with 257 experts and top-9, and (2048, 384) with 128 experts and top-8. Every output element differs from the reference, and the values change from run to run. ck_moe_stage1_gemm turns the requested number of splits into CK's KBatch, the number of KPerBlock tiles each split covers: K / (splitk * KPerBlock). With one tile per split that is 1, which DeviceMoeGemmBlockScale reads as "no split": it runs a single z-block over the whole K and skips zeroing the output. The split-K instance still accumulates into that output atomically, and fused_moe allocates it with torch.empty. StrideE also keys the split-K layout (2 * N per row) on KBatch > 1, so the rows overlap as well. #3997 fixed this in ck_moe_stage1() by turning split-K off for such requests, and the MoE refactor in #4394 dropped that guard. This fix sits at the KBatch conversion instead, so no caller reaches KBatch == 1 through split-K, whether the split comes from get_ksplit(), a tuned CSV or AITER_KSPLIT. It also keeps the split rather than turning it off: when splitk would leave fewer than two tiles per split, stage 1 uses fewer splits of at least two tiles, KBatch = 2 or the smallest divisor of the tile count that is at least 2. At the (4096, 256, E=288, top-8) one-token shape the operator then takes 32.1 us, against 41.1 us without split-K. A K of a single tile cannot be split and now fails with an error. Requests that already give two or more tiles per split are unchanged. Signed-off-by: Jin Tao <[email protected]>
4 of 5 tasks
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.
Motivation
get_ksplit could pick a split where each K partition owns a single k-tile (KBatch = model_dim / (split * 256) == 1). In that case the CK stage1 kernel still uses atomic-add but skips the output memset, accumulating onto uninitialized memory and producing gibberish at bs=1 (e.g. Qwen3.5-FP8 TP8, K=4096, split=16). Add the KBatch >= 2 condition in get_ksplit, and guard ck_moe_stage1 so splitk from tuned CSV / AITER_KSPLIT cannot bypass it.
Technical Details
Test Plan
Add op_tests/test_moe_blockscale_ksplit.py: exercises the high-level fused_moe() CK 2-stage path (which get_ksplit feeds, unlike test_moe_blockscale) against a bf16 pre-quant reference, asserting row-0 rel error stays within fp8 block-quant noise.
Test Result
Submission Checklist