Repository navigation
Return an empty result for M=0 in a16w8/a4w6/a6w4/a6w6/a8w4 GEMMs - #8992
Conversation
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); this extends the same convention to the other dense GEMM entry points that were missing it (ROCm#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: ROCm#8984, ROCm#8958, ROCm#8960
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
@aiter-bot review |
|
aiter-bot — queued behind 31 review(s); expect to start in about 0 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8992 — Return an empty result for M=0 in a16w8/a4w6/a6w4/a6w6/a8w4 GEMMs
Review (advisory):
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the PR ships the single test target op_tests/test_gemm_a8w4_zero_m.py, so a deterministic report could have run — environment gap, not a PR defect
Perf (advisory): NOT RUN — the PR's test target exposes no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the M>0 path gains one integer comparison per call and no kernel code changes
Size: 90 lines / 9 files
Design (advisory): per-entry inline M=0 guards at each of the five wrappers, ahead of the tuned lookup and backend dispatch, rather than the shared empty_gemm_result() helper #8984 proposes
Human: recommend Kristian Sikiric review whether the per-entry inline M=0 guard in this PR (vs the shared helper #8984 proposes) is the convention to carry across the remaining entries — the _out/asm variants and the pack/quant path
📝 [inferred] The new guards look unreachable end-to-end for the packed ops: a 0-row activation cannot be packed, because mxfp4_gemm_pack_size (aiter/ops/gemm_op_a6w4.py:276) and the mxfp6 pack layout (aiter/ops/gemm_op_a6w6.py:855) still raise "requires positive dimensions" on rows==0, so the idle-rank dummy step this PR cites (#8958) would die at the quant step before reaching the fixed gemm_a4w6/gemm_a6w4/gemm_a6w6 entries — unless serving frameworks skip activation quant for a dummy step, which I could not confirm. Reviewer should ask whether the pack/quant entries also need the M=0 no-op convention for the scenario to complete end-to-end.
aiter/aiter/ops/gemm_op_a6w4.py
Line 276 in 52b4451
aiter/aiter/ops/gemm_op_a6w6.py
Line 855 in 52b4451
2 finding(s) posted inline, on the lines they are about:
aiter/ops/gemm_op_a16w8.py:50— The description and self-review claim the pre-existing test_gemm_a16w8_asm.py::_run_guard_checks M=0…aiter/ops/gemm_op_a6w6.py:1166— The M=0 convention stops at the wrapper layer: the exported asm-level entries still dispatch M=0 to a backend
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
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
Context
gemm_a16w16's M=0 as a no-op. This PR extends the same convention to the other dense GEMM entry points flagged as missing it in [Tracking] Zero-size GEMM inputs (M=0/N=0) across AITER: empty = no-op, never hang #8984's scope:gemm_a16w8_asm,gemm_a4w6,gemm_a6w4,gemm_a6w6,gemm_a8w4_mxfp8.What changed
gemm_a4w6/gemm_a6w4: previously raisedValueErroronM<=0. M=0 is now a legal no-op, answered before_select_gemm_a4w6_kernel/_select_gemm_a6w4_kernel(and therefore before any tuned-config lookup).gemm_a6w6: had no guard at all for M=0. Verified on MI300X that without this fix it reaches the ASM launcher and crashes withM must be a positive multiple of 256!fromcsrc/py_itfs_cu/asm_gemm_a6w6.cu.gemm_a8w4_mxfp8: had no M guard; M=0 reached_resolve_mxfp8_gemm_configand the kernel launch with an untested shape. The new guard sits after the N/K validation (still enforced) but before thea_preshuffleM%2 check, which is moot for M=0.gemm_a16w8_asm: allocatesoutunconditionally but always called the kernel. This file's own test (test_gemm_a16w8_asm.py::_run_guard_checks, added with the original gfx950 decode kernel in [ASM] [HIP] [JIT] Add a gfx950 asm GEMM with BF16 activations and FP8 weights for decode #6101) already assertsgemm_a16w8_asm(M=0, ...).shape == (0, 4608)— that assertion was not actually true until this change.Testing
origin/main(before this change):gemm_a4w6/gemm_a6w4raiseValueError,gemm_a6w6crashes with the ASMM must be a positive multiple of 256!error,gemm_a8w4_mxfp8/gemm_a16w8_asmfail reaching an unvalidated kernel/dtype path.(0, N)bf16 tensor without reaching a backend.test_*_returns_empty_result_for_m_zeropytest cases toop_tests/test_gemm_a4w6.py,test_gemm_a6w4.py,test_gemm_a6w6.py, and a new minimalop_tests/test_gemm_a8w4_zero_m.py, following the existingplaceholder = torch.empty(0, dtype=torch.uint8)pattern already used in this repo for pre-kernel validation tests (e.g.test_a4w6_rejects_unsupported_launch_contracts_before_allocation). All four pass locally.gemm_a16w8_asmalready had the right assertion in its existing guard checks; no new test added there, this PR just makes it pass.gemm_a4w6/gemm_a6w4/gemm_a6w6require gfx950 andgemm_a8w4_mxfp8requires gfx1250 for their actual (M>0) compute paths, which I could not exercise on this MI300X machine. Only the M=0 short-circuit itself (and the new tests, which never reach a kernel) were verified here; please let CI/gfx950+gfx1250 runners confirm the M>0 paths are unaffected.Related: #8984, #8958, #8960
PR Self-Review
Reviewed revision
52b4451
Behavior and intent
Before this PR,
gemm_a4w6/gemm_a6w4raiseValueErroronM<=0,gemm_a6w6/gemm_a8w4_mxfp8have no M guard at all and reach the tuned-config lookup and kernel launch with M=0 (an untested shape), andgemm_a16w8_asmunconditionally calls its kernel regardless of M. This is insufficient per #8984: an idle data-parallel rank's dummy step (#8958) produces M=0 in production, and the existing behavior either errors where a no-op is expected, or reaches a backend that may reject or mishandle a zero-size launch (verified below:gemm_a6w6actually crashes). The PR adds anif M == 0: return <empty tensor>short-circuit to each of the five entries, placed before any tuned lookup or kernel dispatch, matching the conventiongemm_a16w16already uses (#8960, not yet merged).Validation and unverified scope
Verified on an MI300X (gfx942) machine by calling each of the five functions directly with M=0 placeholder tensors, both on
origin/main(f7c6089) and on this PR's head:origin/main:gemm_a4w6/gemm_a6w4raiseValueError("... requires positive dimensions ...");gemm_a6w6crashes with the ASM runtime errorM must be a positive multiple of 256!;gemm_a8w4_mxfp8/gemm_a16w8_asmfail with anAssertionErrorreaching an unvalidated ctypes/dtype path (this specific failure mode is an artifact of this MI300X not being this kernel's target arch, not itself evidence of the M=0 bug for those two -- thegemm_a6w6crash and the twoValueErrors are the clean evidence).(0, N)bf16 tensor, no backend reached.Unverified: the actual M>0 compute path for
gemm_a4w6/gemm_a6w4/gemm_a6w6(needs gfx950) andgemm_a8w4_mxfp8(needs gfx1250) was not exercised on this MI300X hardware, since this PR does not touch that path's logic (the newif M == 0check is strictly before it) I believe it is unaffected, but CI on the relevant architectures is the authority here, not my local run.PR-specific question
Why does
gemm_a16w8_asmget no new test file, while the other four do? Becauseop_tests/test_gemm_a16w8_asm.pyalready has an_run_guard_checks()assertion (assert gemm_a16w8_asm(a, b, s).shape == (0, 4608), "M 0 should be a no-op") dating to the function's original PR (#6101) that was not actually true until this change -- adding a second test for the same behavior would be redundant with a check the repo already owns.Changed op tests
op_tests/test_gemm_a4w6.py(addedtest_a4w6_returns_empty_result_for_m_zero): covers the new M=0 behavior forgemm_a4w6. Not redundant with the file's existingtest_gemm_a4w6_matches_quantized_reference(which only exercises M>0 shapes) ortest_a4w6_rejects_unsupported_launch_contracts_before_allocation(which covers alpha/K-range errors, not M=0).op_tests/test_gemm_a6w4.py(addedtest_a6w4_returns_empty_result_for_m_zero): same reasoning, mirrored forgemm_a6w4.op_tests/test_gemm_a6w6.py(addedtest_a6w6_returns_empty_result_for_m_zero): same reasoning forgemm_a6w6, which previously had no M=0 guard or test at all (not even an error-path one).op_tests/test_gemm_a8w4_zero_m.py(new file): no prior test file existed forgemm_a8w4_mxfp8's M=0 behavior to extend; this is a minimal, narrowly-scoped regression test rather than a full correctness suite for the op, which is out of this PR's scope.