Skip to content

[Bugfix] gemm_a16w16: return an empty result for M=0 - #8879

Closed
qichu-yun wants to merge 1 commit into
mainfrom
qichu/gemm-a16w16-zero-rows
Closed

qichu-yun wants to merge 1 commit into
mainfrom
qichu/gemm-a16w16-zero-rows

Conversation

@qichu-yun

Copy link
Copy Markdown
Contributor

Summary

_gemm_a16w16 returns an empty [*A.shape[:-1], N] result (or the caller's out) when the input has no rows, before the tuned-config lookup.

Motivation

On gfx1250, DeepSeek-V4.1-Flash served with DP attention + EP (DEP4, ATOM_DP_LM_HEAD_MODE=allgather) stops at the first batch: three of the four DP ranks raise in the LM head GEMM and the fourth waits for them.

File "aiter/tuned_gemm.py", line 791, in flydsl_gemm
File "aiter/ops/flydsl/gemm_kernels.py", line 326, in flydsl_hgemm
File "aiter/ops/flydsl/gemm_a16w16_tdm.py", line 70, in gemm_a16w16_tdm
File "aiter/ops/flydsl/kernels/gemm_a16w16_tdm_gfx1250.py", line 98, in validate_gemm_gfx1250_config
ValueError: dimensions, tiles, stages, wave counts and WMMA sizes must be positive integers

The failing call is M=0, N=129280, K=5120 (BF16): a DP rank with no tokens in the step still runs the LM head, with zero rows. Since #8031 the tuned gfx1250 rows for this shape name the FlyDSL TDM HGEMM, whose config check rejects M=0. Before #8031 the same call returned an empty result.

Changes

  • aiter/tuned_gemm.py: _gemm_a16w16 returns early for M=0, so no backend sees an empty input and the result does not depend on which kernel a tuned row names.
  • op_tests/test_gemm_a16w16.py: new -t zero case.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Tested on MI455X (gfx1250); see below.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Internal early return; no API or documented behavior changes.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None

PR Self-Review

Reviewed revision

To be filled from the automated PR Self-Review comment.

Behavior and intent

tgemm.mm / gemm_a16w16 with zero rows returned an empty result before #8031 and raises on gfx1250 after it, for every shape whose tuned row names the TDM kernel. It now returns the empty result for any backend.

Validation and unverified scope

Direct call tgemm.mm(x[M, 5120], w[129280, 5120]) on one MI455X, with the DeepSeek-V4.1-Flash BF16 tuned-config list:

aiter M=0 M=1, 4, 64
2989e550f (before #8031) ok, empty ok
9da592818 (main, 2026-11-27) ValueError ok
9da592818 with #8031 reverted ok, empty ok
9da592818 + this change ok, empty ok

End to end on one MI455X node (4 GPUs), image rocm/fw-bringup-mlperf:gfx1250-atom-ci455-20261128 (ATOM 380aeb8a0, aiter 9da592818), DeepSeek-V4.1-Flash DEP4 server:

  • main: GSM8K stops at the first batch (reproduced twice); the MLPerf Endpoint c64 bench cannot run.
  • main + this change: GSM8K completes; MLPerf Endpoint c64 2270.56 tok/s/GPU, 10962/10962 samples successful.

Commands: python3 op_tests/test_gemm_a16w16.py -t zero passes; black --check and ruff check pass on both files. -t out fails on gfx1250 with and without this change (torch bf16+bias: routed to triton), unrelated. Not run on gfx942 / gfx950.

PR-specific question

To be answered after the automated PR Self-Review comment.

Changed op tests

op_tests/test_gemm_a16w16.py: test_gemm_zero_rows (-t zero) runs M=0 for a 2-D [0, 5120] and a 3-D [2, 0, 5120] input against the 129280 x 5120 LM head weight, with and without out=, and checks the result shape, dtype and that out is returned. No existing case covers M=0.

A data-parallel rank with no tokens in a step still runs its LM head with
zero rows. Since #8031 the gfx1250 BF16 rows for DeepSeek-V4.1-Flash's LM
head (N=129280, K=5120) name the FlyDSL TDM HGEMM, whose config check
rejects M=0, so DP attention + EP serving stops at the first batch.

Return the empty [*, N] result (or the caller's out) before the tuned
lookup, so no backend sees M=0. op_tests/test_gemm_a16w16.py -t zero
covers 2-D and 3-D inputs with and without out=.
@qichu-yun
qichu-yun requested a review from a team November 28, 2026 13:29
@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 8879 --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.

qichu-yun added a commit to ROCm/ATOM that referenced this pull request Nov 28, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision fa6c8ee0b210 · 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 — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — PR-specific question is too short to show concrete reasoning (9 units; need 14)

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 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This looks like the same fix as #8960 (same root cause: M=0 dummy steps on gfx1250 get routed to FlyDSL TDM, whose validator rejects a zero-dim input, hanging the serving rank's collective — see #8958).

#8960 lands the early-return at the same call site but with broader test coverage (all tuned backends, 2D/3D, bias/out=, plus an end-to-end c32 validation run), so I'd suggest consolidating on that one to avoid two PRs touching the same guard. Happy to help reconcile if there's something here that #8960 is missing — otherwise might be worth closing this in favor of #8960 once it merges.

@qichu-yun

Copy link
Copy Markdown
Contributor Author

@zufayu Agreed, #8960 is the same fix with broader coverage. I'll close this one once #8960 merges.

@qichu-yun

Copy link
Copy Markdown
Contributor Author

Closing in favor of #8960.

@qichu-yun qichu-yun closed this Dec 1, 2026
@qichu-yun
qichu-yun deleted the qichu/gemm-a16w16-zero-rows branch December 1, 2026 09:02
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.

4 participants