Skip to content

[Fix] topk_per_row_argmax: return early on zero rows - #6471

Merged
yitingw1 merged 4 commits into
mainfrom
yitingw1/topk-argmax-zero-rows
Oct 13, 2026
Merged

yitingw1 merged 4 commits into
mainfrom
yitingw1/topk-argmax-zero-rows

Conversation

@yitingw1

@yitingw1 yitingw1 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

topk_select on a zero-row input launches its FlyDSL kernels with a zero-sized grid: every backend puts rows on a grid dimension (observed: argmax (31, 0, 1) / (0, 1, 1), small_k and radix stream (0, 1, 1), decode (0, 4, 1)). HIP rejects it with hipErrorInvalidValue; the FlyDSL runtime only prints the failure, so the next kernel on the stream raises HIP error: invalid argument far from the cause.

Where it hits. ATOM's rejection sampler calls topk_select(target_probs, 1), and with relaxed acceptance topk_select(probs, 10, sorted=True, tie="low", return_value=True). On a step with no drafts to verify, target_probs has 0 rows and the server dies. torch.argmax, which topk_select replaced there, returns an empty result for zero rows.

Technical Details

aiter/ops/topk_select.py _dispatch: return when rows == 0. It is the single entry to every backend, so one guard covers all of them. Validation runs before it and post-processing (values gather, sort, offset) after it, both fine on empty tensors; idx stays [0, topk].

Test Plan

op_tests/test_topk_select.py gains test_zero_rows (also run from main()). Each case is warmed at one row, so the empty call takes the cached launch, then followed by a probe kernel and a sync:

  • argmax: fp32 / bf16 / fp16 at n = 2048 (single-pass) and n = 129280 (split);
  • small_k (k=16, n=2048), radix stream (k=512, n=32768), decode (k=10, n=129280, sorted + tie="low" + return_value);
  • a caller passing output_idx, output_idx_offset, end and sorted_index.

Test Result

MI355X (gfx950), 10 cases:

aiter result
without this change 10 / 10 fail (hipErrorInvalidValue)
with this change 10 / 10 pass

Submission Checklist

Rows ride a grid dimension, so an empty batch launched a zero-sized grid.
HIP rejects that with hipErrorInvalidValue, which the FlyDSL runtime only
prints; the next kernel on the stream then raises. topk_select(k=1) routes
here, and ATOM's rejection sampler hit it on a P/D producer step that had
no drafts to verify. torch.argmax returns an empty result for zero rows.

test_topk_select gains test_zero_rows: fp32/bf16/fp16 at widths 2048
(single-pass launch) and 129280 (split launch), each followed by a probe
kernel. It fails on every case without this change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@yitingw1
yitingw1 requested a review from a team October 13, 2026 07:29
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6471 --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.

@github-actions github-actions Bot changed the title [Fix][FlyDSL] topk_per_row_argmax: return early on zero rows [FlyDSL] [Fix] topk_per_row_argmax: return early on zero rows Oct 13, 2026
yitingw1 and others added 3 commits October 13, 2026 07:48
The previous commit guarded only the k=1 argmax. small_k, radix stream and
decode also put rows on a grid dimension and launch a zero-sized grid on an
empty batch (hipErrorInvalidValue), e.g. the k=10 sorted+values call a
relaxed-acceptance rejection sampler makes. Guard once in _dispatch; the
argmax guard stays for direct callers.

test_zero_rows now covers argmax at fp32/bf16/fp16 x {2048, 129280}, small_k
(k=16), stream (k=512), decode (k=10, sorted + tie=low + return_value) and a
caller passing output_idx, output_idx_offset, end and sorted_index. Each shape
is warmed at one row first, so the empty call takes the cached launch. With
the _dispatch guard removed, the four non-argmax cases fail.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
topk_select._dispatch is the only caller and now returns on zero rows for
every backend, so the per-kernel guard is redundant. With only the _dispatch
guard all ten test_zero_rows cases pass; with neither guard all ten fail.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot changed the title [FlyDSL] [Fix] topk_per_row_argmax: return early on zero rows [Fix] topk_per_row_argmax: return early on zero rows Oct 13, 2026
@github-actions github-actions Bot removed the FlyDSL label Oct 13, 2026
@yitingw1
yitingw1 merged commit 0f6686c into main Oct 13, 2026
@yitingw1
yitingw1 deleted the yitingw1/topk-argmax-zero-rows branch October 13, 2026 14:29
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.

2 participants