Repository navigation
Conversation
🏷️ 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 |
|
@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 #8995 — Return an empty result for M=0 in the a8w8 GEMM family
Review (advisory): 🔴 HIGH RISK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled; the target op_tests/test_gemm_a8w8_zero_m.py existed but the run could not happen — an environment gap, not a PR defect)
Perf (advisory): NOT RUN — the target ships no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the change adds no kernel code and leaves the M>0 path byte-identical, so there is no measured perf surface
Size: 125 lines / 2 files
Design (advisory): the M=0 short-circuit lives in the shared implementation bodies (_gemm_a8w8_bpreshuffle_into, _gemm_a8w8_blockscale_bpreshuffle_native) rather than in each public wrapper, so one guard covers every caller including gemm_a8w8_blockscale's group32 branch, and it answers before the arch gates
Human: recommend BingYuan.Zhou review whether the M=0 short-circuit in PR #8995 belongs in the shared bodies of gemm_op_a8w8.py ahead of the arch gates, as this PR places it, or at each public wrapper
🔴 [verified] Every downstream job is skipped on this PR — Sglang, vLLM Benchmark, ATOM Accuracy and the 8-GPU Multi-GPU Tests all sit at "skipping" with no ci: label — yet the diff changes the M=0 behavior of the default-dispatch a8w8 GEMM path in aiter/ops/gemm_op_a8w8.py that those frameworks consume, and the 8-GPU Multi-GPU job is the only configuration that could exercise the production trigger, an idle data-parallel rank's M=0 dummy step (#8958). Author must add ci:all (the M=0 trigger is model-agnostic, so no smaller label set can be named) and require it green before merge.
🔴 [verified] aiter/ops/gemm_op_a8w8.py is a Tier-2 downstream contract (public via aiter/init.py:123) and this PR changes the M=0 behavior of seven of its public entry points from raise-or-launch to returning an empty tensor, yet the PR carries zero reviews and no owner ping — a contract change merged on CI alone is exactly what the sign-off rule exists to stop. Reviewer must @-mention the de-facto owner BingYuan.Zhou (top committer of gemm_op_a8w8.py, 13 commits) in a PR comment requesting explicit sign-off before merge.
📝 [inferred] The public gemm_a8w8 dispatcher's RDNA route (aiter/ops/gemm_op_a8w8.py:741-747) still forwards M=0 to the Triton kernel (aiter/ops/triton/gemm/basic/gemm_a8w8.py:29), which has no M=0 guard — whether M=0 returns cleanly there depends on Triton treating a zero grid as a launch no-op, which this PR neither tests nor mentions. Reviewer should ask whether #8984's sweep covers that route.
aiter/aiter/ops/gemm_op_a8w8.py
Lines 741 to 747 in 4de4836
1 finding(s) posted inline, on the lines they are about:
aiter/ops/gemm_op_a8w8.py:2916— gemm_a8w8_mxfp8's M=0 guard (aiter/ops/gemm_op_a8w8.py:2916) sits after require_gfx1250_asm, which raises on…
| raise NotImplementedError( | ||
| f"gfx1250 a8w8 MXFP8 GEMM requires N%16==0, got N={N}" | ||
| ) | ||
| if M == 0: |
There was a problem hiding this comment.
📝 [verified] gemm_a8w8_mxfp8's M=0 guard (aiter/ops/gemm_op_a8w8.py:2916) sits after require_gfx1250_asm, which raises on gfx1250-strict/A0 stepping (aiter/jit/utils/asm_guard.py:62), while gemm_a8w8_blockscale_abpreshuffle's guard deliberately precedes its arch check — so on A0 hardware an M=0 mxfp8 call would still raise, the one spot where the PR's "M=0 is a no-op regardless of backend" principle does not hold. Reviewer should ask whether M=0 should also bypass the A0 gate for consistency.
4de4836 to
155ca4b
Compare
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]>
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
155ca4b to
15909f1
Compare
|
@BingYuan.Zhou (via GitHub handle, please correct if wrong) — could you take a look at whether the M=0 short-circuit placement in 🤖 Generated with Claude Code |
|
Correction: my previous mention didn't actually ping anyone (wrong format). @solinzby1 — could you take a look at the M=0 guard placement question above when you get a chance? |
Context
gemm_a16w16already treats M=0 as a no-op ([GEMM] gemm_a16w16: return the empty result for M=0 before backend dispatch #8960), and two a8w8 entries in this same file (gemm_a8w8_bpreshuffle_out,gemm_a8w8_mxfp8_bpreshuffle) already do too. This PR extends that convention to the remaining a8w8 entry points flagged in [Tracking] Zero-size GEMM inputs (M=0/N=0) across AITER: empty = no-op, never hang #8984's scope.What changed (
aiter/ops/gemm_op_a8w8.py)gemm_a8w8_ASM,gemm_a8w8_CK: guard added directly in each function, right afterm/n/kare read, before any tuned-config lookup.gemm_a8w8_bpreshuffle: guard added in the shared_gemm_a8w8_bpreshuffle_intohelper (which it delegates to) rather than in the wrapper itself, sincegemm_a8w8_bpreshuffle_outcalls the same helper — one guard now covers both the already-fixed_outvariant's remaining path and the previously-unguarded allocating variant.gemm_a8w8_blockscale: guard added right afterm/n/k, before theisBpreshuffledbranch (which can itself dispatch into the blockscale_bpreshuffle native body).gemm_a8w8_blockscale_bpreshuffle: guard added in the shared_gemm_a8w8_blockscale_bpreshuffle_nativebody, which both the routed (out=None) and buffered (out=) public spellings call into, and whichgemm_a8w8_blockscale's group32 branch also calls directly.gemm_a8w8_blockscale_abpreshuffle: guard added afterYis resolved (fromoutor freshly allocated) and before the gfx1250 arch check — M=0 is a no-op regardless of backend, so it should not need to satisfy the "needs gfx1250" requirement either.gemm_a8w8_mxfp8: same pattern asgemm_a8w4_mxfp8in Return an empty result for M=0 in a16w8/a4w6/a6w4/a6w6/a8w4 GEMMs #8992 — guard added after the N/K validation, before thea_preshuffleM%2 check (which is moot for M=0) and the tuned-config resolution.Testing
origin/main(before this change): every one of the seven either raises, fails to resolve a kernel, or reaches a kernel build/launch with an untested shape. Notablygemm_a8w8_mxfp8fails with an actual HIPinvalid configuration argumenterror (a bad kernel launch, not a clean Python exception), andgemm_a8w8_CK/gemm_a8w8_ASM/gemm_a8w8_bpreshuffle/gemm_a8w8_blockscaleall trigger a JIT kernel build for the M=0 shape (one of which happens to fail here on an unrelated CK/toolchain issue — itself evidence this path was never meant to reach a kernel build).(0, N)bf16 tensor without reaching a backend.op_tests/test_gemm_a8w8_zero_m.pywith one pytest case per entry point, using placeholder tensors that never reach a kernel for M=0 (so no particular GPU architecture is required beyond a CUDA/HIP device). All 7 pass locally.Related: #8984, #8958, #8960
PR Self-Review
Reviewed revision
4de4836
Behavior and intent
Before this PR, seven
gemm_a8w8*entry points inaiter/ops/gemm_op_a8w8.pyreach a tuned-config lookup and/or a kernel launch for M=0, unlike the two entries in the same file (gemm_a8w8_bpreshuffle_out,gemm_a8w8_mxfp8_bpreshuffle) that already short-circuit. This is insufficient per #8984: M=0 happens in production from an idle data-parallel rank's dummy step (#8958), and reaching a backend with it is backend-dependent and undefined (verified below: one of the seven produces an actual HIP launch failure, not a clean exception). The PR adds the sameif m == 0: return <empty tensor/Y>short-circuit, placed before the first tuned lookup or kernel dispatch in each path, reusing the shared_gemm_a8w8_bpreshuffle_into/_gemm_a8w8_blockscale_bpreshuffle_nativebodies where two public entry points funnel into one implementation.Validation and unverified scope
Verified on an MI300X (gfx942) machine by calling all seven entries directly with M=0 placeholder tensors, both on
origin/main(f7c6089) and this PR's head:origin/main: all seven fail. Notablygemm_a8w8_mxfp8fails withRuntimeError(... HIP runtime error: invalid configuration argument ...)-- a real bad kernel launch.gemm_a8w8_blockscale_abpreshuffleraises its owngfx1250 with e8m0 scalesRuntimeError (unrelated to M=0, since my FP32-scale test tensors don't satisfy that function's arch/dtype precondition regardless of M -- this result does not by itself prove the M=0 bug for that one entry, though theif m == 0guard in this PR is placed before that check too, which is itself the behavior change requested: M=0 should not need to satisfy an arch precondition). The remaining five reach a JIT kernel build or a "no kernel registered"/"no usable config" path for the untested M=0 shape.(0, N)bf16 tensor, no backend reached.Unverified: the M>0 compute path for
gemm_a8w8_blockscale_abpreshuffleandgemm_a8w8_mxfp8(both gfx1250-only) was not exercised on this MI300X hardware. Since this PR's guard is strictly before the existing logic for M>0 (no reordering of M>0 behavior), I believe those paths are unaffected, but I have not run gfx1250 CI myself.PR-specific question
Why is the guard placed in the shared
_gemm_a8w8_bpreshuffle_into/_gemm_a8w8_blockscale_bpreshuffle_nativebodies rather than in the publicgemm_a8w8_bpreshuffle/gemm_a8w8_blockscale_bpreshufflewrappers? Because each shared body is also called directly by another already-fixed or in-scope path (gemm_a8w8_bpreshuffle_out's own M=0 check short-circuits before reaching_gemm_a8w8_bpreshuffle_intoat all, so this PR's guard there is a no-op for that path and only activates for the previously-unguardedgemm_a8w8_bpreshuffle;gemm_a8w8_blockscale's group32 branch calls_gemm_a8w8_blockscale_bpreshuffle_nativedirectly, and my separate top-level guard ingemm_a8w8_blockscalealready covers that call site, so the body-level guard is a second, deliberately redundant layer rather than the only one). Putting the check at the body level means one line protects every caller instead of duplicating it per wrapper.Changed op tests
op_tests/test_gemm_a8w8_zero_m.py(new file): one pytest case per fixed entry point (gemm_a8w8_ASM,gemm_a8w8_CK,gemm_a8w8_bpreshuffle,gemm_a8w8_blockscale,gemm_a8w8_blockscale_bpreshuffle,gemm_a8w8_blockscale_abpreshuffle,gemm_a8w8_mxfp8), using placeholder tensors that never reach a kernel for M=0. Not redundant with the existingop_tests/test_gemm_a8w8.py, which is a correctness/benchmark script (test_gemm,test_skinny_gemm, etc.) exercising M>0 shapes against a numeric reference -- it has no M=0 case, and M=0 needs only a shape/dtype assertion, not a numeric comparison, so extending it would have meant bolting an unrelated check onto an unrelated test's parametrization rather than adding a focused new one.