Repository navigation
[GEMM] gemm_a16w16: return the empty result for M=0 before backend dispatch - #8960
Conversation
…spatch An idle data-parallel rank's dummy step reaches the lm_head GEMM with no rows. _gemm_a16w16 looked up a tuned config for M=0 and dispatched it; on gfx1250 DSV4.1 BF16 shapes resolve to the FlyDSL TDM kernel (#8031), whose validator rejects a zero dimension. The idle ranks crashed and the serving rank hung in a collective (DSV4.1-Flash DEP4). Answer M=0 before the lookup with the [*A.shape[:-1], N] result of otype, or `out` viewed to that shape. The out-dtype check still runs first; M>0 is unchanged. Add op_tests/test_gemm_a16w16.py -t empty. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ 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 |
zoe-cop
left a comment
There was a problem hiding this comment.
The early return before backend lookup is appropriate for the native M=0 path. One regression-coverage issue below. I independently checked the base/head control flow with real CPU tensors and the TDM validator; I have not reproduced the gfx1250 serving run.
|
The fix is in the right place (empty result before backend dispatch). Before merge, please clear the failing CI checks so the PR is mergeable. Please also add a regression test for the empty-input path (M=0 with and without out=, plus a batched A with a zero leading dim) and keep K=0 behavior explicitly defined in the docstring. |
|
Flagged #8879 as a duplicate of this fix (same guard, narrower test coverage) and suggested consolidating here. Given this is fixing a real serving hang (idle-rank M=0 dummy step hitting the FlyDSL TDM validator, per #8958), a few things to close out before merge:
Given the severity (first-request hang on DSV4.1-Flash DEP4), this seems worth fast-tracking through those steps rather than blocking on process. |
… #8879 closed in favor of it)
|
@srinivamd Checking in — this has been open ~36h with no updates and it's fixing a real serving hang (first-request hang on DSV4.1-Flash DEP4, #8958), so I don't want it stuck on process:
If I don't hear back shortly I'll push the docstring update myself and re-run the failed shards so this can get reviewed and merged — let me know if you're already on it. |
Per review feedback on #8960: document that the M=0 early return is independent of K=0, which still falls through to the normal tuned dispatch and is only as well-defined as the selected backend's handling of a zero contraction. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Pushed 7c90e77 directly: adds the K=0 docstring note requested above — it's a comment-only change (no behavior change), clarifying that K=0 is unrelated to the M=0 early-return path and still falls through to the normal tuned dispatch. Also re-ran the 3 failed Standard Tests shards (1, 5, 6) — they looked unrelated to this diff (infra timeout / an unrelated MoE accuracy flake). @srinivamd feel free to amend/squash if you'd rather word it differently — just trying to unblock this given the severity. |
|
@zoe-cop CI is now fully green (8/8 Standard Tests shards passed, Aiter Test Gate SUCCESS) after re-running the earlier unrelated failures and adding the K=0 docstring note. Given the severity (first-request hang on DSV4.1-Flash DEP4), would you be able to convert your review to an approve, or let us know if anything's still outstanding? |
M=0 happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (ROCm#8958). gemm_a16w16 already treats this as a no-op (ROCm#8960), and gemm_a8w8_bpreshuffle_out / gemm_a8w8_mxfp8_bpreshuffle already do within gemm_op_a8w8.py. This extends the same convention to the remaining a8w8 entry points flagged in ROCm#8984: gemm_a8w8_ASM, gemm_a8w8_CK, gemm_a8w8_bpreshuffle (via the shared _gemm_a8w8_bpreshuffle_into, which also protects gemm_a8w8_blockscale, gemm_a8w8_blockscale_bpreshuffle (via the shared _gemm_a8w8_blockscale_bpreshuffle_native), gemm_a8w8_blockscale_abpreshuffle, and gemm_a8w8_mxfp8. Each guard sits right after the output buffer's shape is known and before the first tuned-config lookup or kernel dispatch, matching the pattern of the two existing guards in this file. Verified on MI300X (gfx942): on origin/main, calling each of these seven entries with M=0 either raises (gemm_a8w8_blockscale_abpreshuffle's gfx1250 check), fails to resolve a kernel (gemm_a8w8_blockscale_bpreshuffle, gemm_a8w8_mxfp8 -- the latter's failure is a HIP "invalid configuration argument" error, i.e. an actual bad kernel launch, not a clean Python exception), or triggers a JIT build of an untested shape (gemm_a8w8_CK / gemm_a8w8_ASM / gemm_a8w8_bpreshuffle / gemm_a8w8_blockscale -- the latter's build happens to fail here on an unrelated CK/toolchain issue, which is itself evidence the M=0 path was never meant to reach a kernel build at all). With this change all seven return a correctly-shaped empty bf16 result without reaching a backend. Added op_tests/test_gemm_a8w8_zero_m.py covering all seven entries with placeholder tensors that never reach a kernel for M=0. Related: ROCm#8984, ROCm#8958, ROCm#8960
Zero tokens happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (ROCm#8958). This extends the no-op convention already applied to the GEMM entry points (ROCm#8960, - fused_moe_dp_share_expert (aiter/fused_moe_dp_shared_expert.py): already had an `if M == 0: return moe_buf` guard, but it sat after the get_2stage_cfgs tuned lookup, so a zero-token call was still doing a config lookup it never used. Moved the guard (and the moe_buf allocation it depends on) before that lookup; nothing else on this path reads `metadata` before the lookup, so the reorder is safe. - fused_moe_2stages (aiter/fused_moe.py): had no guard at all. Added one right after `token_num` and the `moe_out` buffer are resolved (the existing `moe_out.numel() == 0` check right above it is a different thing -- a reduce-mode workspace placeholder, not a token-count check), before get_2stage_cfgs. - fused_moe_1stage (aiter/fused_moe.py): had no guard. Its first branch (pure bf16) dispatches straight into aiter.fmoe before `token_num` is even read, so the guard has to sit above all three branches, right after the kernelName validation block. Verified on MI300X (gfx942): on origin/main, fused_moe_2stages and fused_moe_1stage both reach their real kernel entry point for token_num=0 (confirmed by a TypeError demanding non-None sorting metadata tensors that a token_num=0 caller has no reason to build). fused_moe_dp_share_expert already worked correctly on origin/main, just with the wasted lookup this change removes. With this change all three return a correctly-shaped empty bf16 result without reaching a kernel, and without requiring real sorted_ids/sorted_weights/etc. for the token_num=0 case. fused_moe / fused_moe_ / _fused_moe_impl (the main public MoE entry, layered above fused_moe_1stage/2stages) are left out of this PR's scope: the real first-dispatch point in _fused_moe_impl was not pinned down, and guessing at it risks a guard that looks right but never executes. Flagging as a follow-up. Added op_tests/test_fused_moe_zero_tokens.py covering all three. Related: ROCm#8984, ROCm#8958, ROCm#8960, ROCm#8992, ROCm#8995, ROCm#8996
…8996) M=0 (and, for a batched GEMM, batch=0) happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (#8958). This extends the no-op convention already applied to gemm_a16w16 (#8960) and the a8w8 family (#8995) to the batched GEMM entry points flagged in #8984: - batched_gemm_bf16_CK / batched_gemm_a8w8_CK: guard added right after the output buffer Y is allocated (b, m, n are already known at that point), before the tuned-config lookup (get_CKBatchedGEMM_config) and the kernel launch. - batched_gemm_a8w8_mxscale (_batched_gemm_a8w8_mxscale_impl) and batched_gemm_a8w8_mxscale_bpreshuffle (_batched_gemm_a8w8_mxscale_bpreshuffle_impl): guard added right after m, g, n, k are read, before the tuned lookup and the opus/flydsl libtype dispatch. batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant (a distinct (fp8, e8m0-scale) tuple return contract) is left out of this PR's scope; flagging it as a follow-up. Verified on MI300X (gfx942): with this change all four entries return a correctly-shaped empty result for batch=0 or M=0 without reaching a backend. On origin/main (before this change), batched_gemm_bf16_CK(B=0) reaches get_CKBatchedGEMM_config and a JIT kernel build/launch for an untested shape. Added op_tests/test_batched_gemm_zero_m.py covering all four entries. Related: #8984, #8958, #8960, #8995 Co-authored-by: zufayu <[email protected]>
) * Return an empty result for M=0 in a16w8/a4w6/a6w4/a6w6/a8w4 GEMMs M=0 happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (#8958). gemm_a16w16 already treats this as a no-op (#8960); this extends the same convention to the other dense GEMM entry points that were missing it (#8984): - gemm_a4w6 / gemm_a6w4 raised ValueError on M<=0; M=0 is now a legal no-op instead of an error, answered before the tuned-config lookup. - gemm_a6w6 had no M guard at all and reaches the ASM launcher with M=0, which aborts with "M must be a positive multiple of 256". - gemm_a8w4_mxfp8 had no M guard; M=0 reaches the config lookup and kernel launch with an untested shape. - gemm_a16w8_asm allocates `out` but calls the kernel unconditionally; M=0 is already asserted as a no-op in this file's own guard checks (test_gemm_a16w8_asm.py::_run_guard_checks), which this makes true. Verified on MI300X (gfx942): on origin/main, gemm_a6w6(M=0) crashes with the ASM "M must be a positive multiple of 256" error, and the other four either raise or reach an unvalidated kernel path; with this change all five return the correctly-shaped empty/bf16 result without reaching a backend. a4w6/a6w4/a6w6 require gfx950 end-to-end and a8w4 requires gfx1250 for their non-zero-M paths, so only the M=0 guard itself (and the new regression tests, which use placeholder tensors and never reach a kernel) could be exercised on this hardware. Related: #8984, #8958, #8960 * Fix Black formatting of the new ValueError messages --------- Co-authored-by: zufayu <[email protected]>
Zero tokens happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (ROCm#8958). This extends the no-op convention already applied to the GEMM entry points (ROCm#8960, - fused_moe_dp_share_expert (aiter/fused_moe_dp_shared_expert.py): already had an `if M == 0: return moe_buf` guard, but it sat after the get_2stage_cfgs tuned lookup, so a zero-token call was still doing a config lookup it never used. Moved the guard (and the moe_buf allocation it depends on) before that lookup; nothing else on this path reads `metadata` before the lookup, so the reorder is safe. - fused_moe_2stages (aiter/fused_moe.py): had no guard at all. Added one right after `token_num` and the `moe_out` buffer are resolved (the existing `moe_out.numel() == 0` check right above it is a different thing -- a reduce-mode workspace placeholder, not a token-count check), before get_2stage_cfgs. - fused_moe_1stage (aiter/fused_moe.py): had no guard. Its first branch (pure bf16) dispatches straight into aiter.fmoe before `token_num` is even read, so the guard has to sit above all three branches, right after the kernelName validation block. Verified on MI300X (gfx942): on origin/main, fused_moe_2stages and fused_moe_1stage both reach their real kernel entry point for token_num=0 (confirmed by a TypeError demanding non-None sorting metadata tensors that a token_num=0 caller has no reason to build). fused_moe_dp_share_expert already worked correctly on origin/main, just with the wasted lookup this change removes. With this change all three return a correctly-shaped empty bf16 result without reaching a kernel, and without requiring real sorted_ids/sorted_weights/etc. for the token_num=0 case. fused_moe / fused_moe_ / _fused_moe_impl (the main public MoE entry, layered above fused_moe_1stage/2stages) are left out of this PR's scope: the real first-dispatch point in _fused_moe_impl was not pinned down, and guessing at it risks a guard that looks right but never executes. Flagging as a follow-up. Added op_tests/test_fused_moe_zero_tokens.py covering all three. Related: ROCm#8984, ROCm#8958, ROCm#8960, ROCm#8992, ROCm#8995, ROCm#8996
M=0 happens in production when an idle data-parallel rank runs a dummy step to stay in its group's collectives (ROCm#8958). gemm_a16w16 already treats this as a no-op (ROCm#8960), and gemm_a8w8_bpreshuffle_out / gemm_a8w8_mxfp8_bpreshuffle already do within gemm_op_a8w8.py. This extends the same convention to the remaining a8w8 entry points flagged in ROCm#8984: gemm_a8w8_ASM, gemm_a8w8_CK, gemm_a8w8_bpreshuffle (via the shared _gemm_a8w8_bpreshuffle_into, which also protects gemm_a8w8_blockscale, gemm_a8w8_blockscale_bpreshuffle (via the shared _gemm_a8w8_blockscale_bpreshuffle_native), gemm_a8w8_blockscale_abpreshuffle, and gemm_a8w8_mxfp8. Each guard sits right after the output buffer's shape is known and before the first tuned-config lookup or kernel dispatch, matching the pattern of the two existing guards in this file. Verified on MI300X (gfx942): on origin/main, calling each of these seven entries with M=0 either raises (gemm_a8w8_blockscale_abpreshuffle's gfx1250 check), fails to resolve a kernel (gemm_a8w8_blockscale_bpreshuffle, gemm_a8w8_mxfp8 -- the latter's failure is a HIP "invalid configuration argument" error, i.e. an actual bad kernel launch, not a clean Python exception), or triggers a JIT build of an untested shape (gemm_a8w8_CK / gemm_a8w8_ASM / gemm_a8w8_bpreshuffle / gemm_a8w8_blockscale -- the latter's build happens to fail here on an unrelated CK/toolchain issue, which is itself evidence the M=0 path was never meant to reach a kernel build at all). With this change all seven return a correctly-shaped empty bf16 result without reaching a backend. Added op_tests/test_gemm_a8w8_zero_m.py covering all seven entries with placeholder tensors that never reach a kernel for M=0. Related: ROCm#8984, ROCm#8958, ROCm#8960
Fixes #8958.
Change
An M=0 call to
_gemm_a16w16(e.g. the dummy step an idle data-parallel rank runs to stay in its group's collectives) now returns the[*A.shape[:-1], N]result ofotype— orout, viewed to that shape — before the tuned lookup. Backends reject a zero dimension: on gfx1250 the FlyDSL TDM validator raises, which hung DeepSeek-V4.1-Flash DEP4 serving after #8031 routed DSV4.1 BF16 shapes to TDM.The guard is in the native body behind
_route, sotgemm.mm,gemm_a16w16andgemm_a16w16_outall get it.Behaviour preserved
out.dtype != otypecheck still runs first.gemm_a16w16_out'sdata_ptridentity check holds (outis returned).save_shapes(AITER_TUNE_GEMM).Test
New
op_tests/test_gemm_a16w16.py -t empty: M=0 as 2-D and 3-D inputs, with and without bias andout=, on every(N, K)this GPU has tuned to a backend, plus untuned shapes.Validation (4× gfx1250 B0, ROCm 10.3.0 b1124 docker)
-t empty: passes.3c03a0beaDEP4 (EP4 + DP attention), MLPerf Endpoints Agentic:Note
-t outfails on gfx1250 independently of this change (torch bf16+biasat M=128 routes to triton on gfx1250; the test expects torch).🤖 Generated with Claude Code