Skip to content

[GEMM] gemm_a16w16: return the empty result for M=0 before backend dispatch - #8960

Merged
zufayu merged 2 commits into
mainfrom
fix/gemm-a16w16-empty-m
Dec 2, 2026
Merged

zufayu merged 2 commits into
mainfrom
fix/gemm-a16w16-empty-m

Conversation

@srinivamd

Copy link
Copy Markdown
Contributor

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 of otype — or out, 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, so tgemm.mm, gemm_a16w16 and gemm_a16w16_out all get it.

Behaviour preserved

  • The out.dtype != otype check still runs first.
  • M>0 calls are unchanged.
  • gemm_a16w16_out's data_ptr identity check holds (out is returned).
  • The torch.compile fake already produces the same shape.
  • M=0 shapes are no longer recorded by save_shapes (AITER_TUNE_GEMM).
  • Plugin-provider dispatch is unchanged.

Test

New op_tests/test_gemm_a16w16.py -t empty: M=0 as 2-D and 3-D inputs, with and without bias and out=, 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.
  • DeepSeek-V4.1-Flash, ATOM 3c03a0bea DEP4 (EP4 + DP attention), MLPerf Endpoints Agentic:
    • without this fix: first request hangs (idle ranks crash in the lm_head GEMM);
    • with it: c32 completes — 4303/4303 requests, 0 failed, 1,471 tok/s/GPU, inline accuracy 53.92% (threshold 52.36%). Remaining concurrencies running.

Note

-t out fails on gfx1250 independently of this change (torch bf16+bias at M=128 routes to triton on gfx1250; the test expects torch).

🤖 Generated with Claude Code

…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]>
@srinivamd
srinivamd requested a review from a team November 30, 2026 20:24
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8960 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 7c90e7787677 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gemm_a16w16.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@zufayu
zufayu requested review from yzhou103 and removed request for valarLip December 1, 2026 01:17
@zufayu
zufayu requested review from xytpai and removed request for zcxjacky December 1, 2026 01:18

@zoe-cop zoe-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread op_tests/test_gemm_a16w16.py Resolved
@zufayu

zufayu commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

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.

@zufayu

zufayu commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

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:

  1. Add the K=0 docstring note @zufayu asked for — the empty-M-path test coverage itself already looks sufficient.
  2. The 5 remaining Standard Tests shards are still pending/queued, not failing — worth waiting for them to finish green.
  3. Needs an actual approval — zoe-cop only left a COMMENTED review (agreed the early-return placement is correct, raised a regression-coverage question, and noted they haven't reproduced the gfx1250 serving hang themselves). Worth getting them or another owner to convert to an explicit approve once the docstring is in.

Given the severity (first-request hang on DSV4.1-Flash DEP4), this seems worth fast-tracking through those steps rather than blocking on process.

@zufayu

zufayu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@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:

  1. K=0 docstring note still outstanding.
  2. 3/8 Standard Tests shards are red (1, 5, 6) — look unrelated to this diff, worth a re-run.
  3. No approve yet beyond zoe-cop's COMMENTED.

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]>
@zufayu

zufayu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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.

@zufayu

zufayu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@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?

@zufayu
zufayu merged commit a8fbe43 into main Dec 2, 2026
60 of 61 checks passed
@zufayu
zufayu deleted the fix/gemm-a16w16-empty-m branch December 2, 2026 09:44
zufayu added a commit to zufayu/aiter that referenced this pull request Dec 3, 2026
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
zufayu added a commit to zufayu/aiter that referenced this pull request Dec 3, 2026
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
yifehuan pushed a commit that referenced this pull request Dec 3, 2026
…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]>
yifehuan pushed a commit that referenced this pull request Dec 3, 2026
)

* 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]>
zufayu added a commit to zufayu/aiter that referenced this pull request Dec 4, 2026
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
zufayu added a commit to zufayu/aiter that referenced this pull request Dec 4, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gemm_a16w16 raises on M=0 (empty batch); hangs DP-attention serving on gfx1250 after #8031

5 participants