Skip to content

[OPUS] [MLA] mla_flat: supports(), min_batch() and capacity sizing - #9178

Open
nehmathe2 wants to merge 2 commits into
ROCm:mainfrom
nehmathe2:nm/opus-mla-flat-supports
Open

nehmathe2 wants to merge 2 commits into
ROCm:mainfrom
nehmathe2:nm/opus-mla-flat-supports

Conversation

@nehmathe2

@nehmathe2 nehmathe2 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #7415. A caller that captures CUDA graphs has to choose between OpusMlaFlatDecode and mla_decode_fwd before it records the call, so it needs the kernel's limits and the docstring's "When to use it" rule as code. ROCm/ATOM#2961 carried its own copy of both; review asked for them to live in aiter. This adds them to aiter/ops/opus/mla_flat.py, with no kernel or planner change:

  • unsupported_reason(num_heads, q_len, *, kv_dtype, q_dtype=None, kv_dim=576, page_size=1, kv_bytes=0, max_chunks=8): why the kernel cannot run a decode (gfx950, fp8 Q and KV, 576-wide rows, page size 1, a KV cache below 4 GiB, at most 128 * max_chunks rows a request), or None.
  • min_batch(num_heads, q_len, cp_world_size=1): the smallest batch at which "When to use it" picks this kernel, or None where mla_decode_fwd stays the choice at every batch. 2 or more query tokens: under round-robin CP from 96 rows a request at batch 1; without CP 48 or 96 heads at batch 1, 12 or 16 heads at batch 4 (16 heads at 3-4 tokens at batch 8). One token: batch 8 at 96 or more heads under CP, 48 or more without. The boundaries were measured on MI355X. It depends on the shape only, so a caller can ask it once per captured graph.
  • supports(num_heads, q_len, cp_world_size, batch, *, kv_dtype, ..., max_chunks=8): both together.
  • OpusMlaFlatDecode(max_batch, ..., max_q_len=, num_heads=): with the widest request given, item_cap defaults to item_cap_for(...), enough work items for any plan of up to max_batch such requests at any contexts, instead of 1024. Existing callers are unchanged.

Relation to #7415. #7415 left the choice to the caller ("OpusMlaFlatDecode does not choose between the paths; the caller does"), and its review thread pointed to ATOM#2961's wanted() / dcp1_shape_ok() / uses_opus_for_batch() as where the rule lived. That still holds: nothing in aiter calls these functions, mla_decode_fwd, get_mla_metadata_v1 and mla_reduce_v1 are untouched and never dispatch to the kernel, and the caller still decides whether to build a decoder and run it. What moves is the content of the rule, from a copy in ATOM to one place next to the kernel, so the limits and the measured boundaries cannot drift apart from the kernel they describe. ATOM#2961's review asked for exactly this (its item 1); its head (d8c63164) replaces those ATOM functions with calls to these and depends on this PR.

PR Self-Review

Reviewed revision

5c5cd180

Behavior and intent

Adds query functions beside the flat-row decode: the kernel's input limits (unsupported_reason), the measured "When to use it" boundaries (min_batch), both together (supports), and work-item sizing from the widest request (item_cap_for, used by OpusMlaFlatDecode when given max_q_len and num_heads). No kernel, planner or existing call path changes; nothing in aiter calls the new functions, and existing OpusMlaFlatDecode callers keep item_cap=1024.

The existing behavior was insufficient for a graph-capturing caller: the limits and boundaries existed only as docstring prose, so ATOM kept a hand copy of both, and item_cap=1024 is not enough for every plan at large batches (128 heads x 8 tokens x batch 128 under CP needs about 1200 at mixed contexts), so a caller had to size it by hand.

Validation and unverified scope

MI355X (gfx950), aiter at this revision, two toolchains: ROCm 10.1 / PyTorch 2.13 and ROCm 7.2.4 / PyTorch 2.10.

  • python3 -c "from op_tests import test_mla as t; t.check_opus_flat_supports(); t.check_opus_flat_decode()": passes on both toolchains. These are the two checks python3 op_tests/test_mla.py runs in its gfx950 block; I ran them directly rather than the whole script.
  • Removing the workgroup term from item_cap_for makes check_opus_flat_supports fail (a plan at batch 256, 8 tokens, 96 heads under CP needs 1739 items against 1578).
  • Consumer: perf(mla): opt-in opus flat-row decode for DCP8/DCP1 MTP (ATOM_OPUS_MLA) ATOM#2961 at d8c63164 against this revision: its opus tests (tests/test_opus_mla_dispatch.py, tests/model_ops/test_opus_mla_gpu.py, 85 tests) pass on both toolchains.

Unverified: the boundaries on gfx950 parts other than MI355X (unmeasured; the docstring says so); new timings (none taken here: the one-token cells and the 16-head 3-4 token boundary come from #7415's measurements)

…r the flat-row decode

A caller that captures CUDA graphs has to choose between OpusMlaFlatDecode and
mla_decode_fwd before recording, so it needs the kernel's limits and the
"When to use it" rule as code, not prose. ATOM had a copy of both
(ROCm/ATOM#2961); this puts them next to the kernel.

- unsupported_reason(num_heads, q_len, *, kv_dtype, q_dtype, kv_dim,
  page_size, kv_bytes): why the kernel cannot run a decode (gfx950, fp8 Q and
  KV, 576-wide rows, page size 1, a KV cache below 4 GiB, at most
  128 * max_chunks rows a request), or None.
- min_batch(num_heads, q_len, cp_world_size): the smallest batch at which the
  docstring's guidance picks this kernel, or None where mla_decode_fwd stays
  the choice. Shape only, so it can be asked once per captured graph.
- supports(num_heads, q_len, cp_world_size, batch, *, kv_dtype, ...): both.
- OpusMlaFlatDecode(max_q_len=, num_heads=) sizes item_cap from the widest
  request (item_cap_for: one item per (request, chunk) unit, one per XCD
  boundary across a request's chunks, one per workgroup), so no plan of up to
  max_batch such requests raises. Without them item_cap stays 1024.

No kernel or planner change. op_tests/test_mla.py checks the selection table,
each limit, and that a sized decoder plans batches up to 256 at uniform,
skewed and ragged contexts under 8-way round-robin CP and without CP.
@nehmathe2
nehmathe2 requested a review from a team December 3, 2026 19:42
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Lightweight PR hygiene checks

🚦 Update: Heavy CI review gate:

  • 🔒 GPU-heavy PR CI is gated on the current PR review state.
  • ⏸️ Before the latest revision is approved, heavy workflows such as Aiter Test, Triton Test, Flash Attention Integration, and OPUS Test stop at the CI gate and do not consume GPU runners.
  • ▶️ After a non-author approves the current revision, the approval event can start the gated heavy workflows.
  • 🔁 Pushing a new commit invalidates the previous approval for CI purposes; the latest revision needs approval again before heavy CI runs.
  • 🏷️ ci:* labels select which extra tests to run, but labels do not bypass the review gate.
  • ✅ Pushes to main, scheduled runs, and manually dispatched workflows keep their normal behavior.

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 9178 --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.

@github-actions github-actions Bot added the OPUS label Dec 3, 2026
@aiter-bot

aiter-bot commented Dec 3, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 5c5cd18057bf · 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 ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_mla.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.

@fangche123

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 6 review(s); expect to start in about 73 min. The box reviews up to 4 PRs at a time.

@aiter-bot aiter-bot 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.

ROCm/aiter PR #9178 — [OPUS] [MLA] mla_flat: supports(), min_batch() and capacity sizing fo…

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0) and no idle GPU on this box (all 8 at ~98% use, torch.cuda unavailable in this environment), though the single test target op_tests/test_mla.py existed — environment gap, not a PR defect.
Perf (advisory): NOT RUN — perf triage required the target's harness (python3 op_tests/test_mla.py) but the same environment gap applies (no idle GPU, torch.cuda unavailable); the PR itself makes no perf claim.
Size: 225 lines / 2 files
Design (advisory): the kernel-selection rule moves out of ATOM's private copy into aiter as query functions beside the kernel, and item_cap turns from a hand-picked 1024 into a closed-form worst-case count — the caller still decides, only the rule's content changes address.
Human: recommend Andreas Karatzas review whether min_batch's hard-coded selection table — in particular its deliberate exclusion of the one-token-per-request cells where the module's own measurements say opus wins from batch 8, and its MI355X-only measurements answering for every gfx950 — is the right contract for a caller that routes on supports() alone.

📝 [inferred] min_batch's thresholds are MI355X measurements (the module docstring scopes them "on MI355X at 8k and 131k tokens of context"), but supports() answers on any gfx950 and the mechanical consumer cannot see the qualifier that lives only in the docstring — on another gfx950 part the batch and head-count boundaries are unmeasured. Reviewer should ask whether the boundaries hold on the other gfx950 SKUs, or whether supports() should scope its answer to MI355X.

📝 [verified] nothing in aiter calls supports()/min_batch()/unsupported_reason()/item_cap_for() or passes the new max_q_len/num_heads kwargs, so until ATOM#2961 replaces its own wanted()/dcp1_shape_ok()/uses_opus_for_batch() copies with calls to these, the exported rule activates nothing and no CI exercises it end to end — the table can drift from the kernel unobserved in the meantime. Reviewer should ask for the ATOM#2961 consumer to land before the guidance table and the kernel drift apart.

2 finding(s) posted inline, on the lines they are about:

  • aiter/ops/opus/mla_flat.py:106 — min_batch (aiter/ops/opus/mla_flat.py:106) returns None for every q_len < 2, but the module's own measured…
  • aiter/ops/opus/mla_flat.py:117 — supports() (aiter/ops/opus/mla_flat.py:117) does not forward the max_chunks parameter that unsupported_reason…

Comment thread aiter/ops/opus/mla_flat.py Outdated
``mla_decode_fwd`` stays the choice at every batch ("When to use it" above). The answer
depends on the shape only, so a caller that captures CUDA graphs per batch can ask it once
per graph."""
if q_len < 2:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [verified] min_batch (aiter/ops/opus/mla_flat.py:106) returns None for every q_len < 2, but the module's own measured table (mla_flat.py:42-44) says that with one token per request opus wins 1.02-2.77x from batch 8 at 96 or more heads with CP and at 48 or more heads without — so a supports()-based caller (the ATOM CUDA-graph path this PR is written for) never routes single-token decode, the most common decode shape, to the faster kernel, and min_batch's docstring claim that None means "mla_decode_fwd stays the choice at every batch" contradicts the table it cites while op_tests/test_mla.py locks the dropped cells in ((96, 1, 8): None). Author must encode the one-token exception in min_batch, or state in both docstrings that it is deliberately excluded so the exported rule and the measured table agree.

return None


def supports(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 [verified] supports() (aiter/ops/opus/mla_flat.py:117) does not forward the max_chunks parameter that unsupported_reason itself takes (mla_flat.py:75), so a decoder built with a non-default max_chunks — e.g. OpusMlaFlatDecode(max_batch, max_chunks=4) — gets supports() answers computed for the default 8: supports(96, 9, 8, 32, kv_dtype=fp8) says True while 9*96=864 rows exceeds that decoder's 512 and plan() raises at plan time. Reviewer should ask whether supports() needs a max_chunks passthrough or a docstring note that it describes the default decoder.

…ks in supports

Review of ROCm#9178:

- min_batch now takes one token per request from batch 8 at 96 or more heads
  with CP and at 48 or more without, as the "When to use it" table says; it
  returned None for every q_len below 2, which contradicted the table.
  check_opus_flat_decode gains one-token shapes (96 and 128 heads with CP,
  48 and 96 without) against the reference.
- min_batch keeps 16 heads at 3-4 tokens without CP on mla_decode_fwd below
  batch 8 (0.92-1.00x of the default path at batch 4, 1.05-1.11x at batch 8),
  as committed in the review of ROCm#7415; the docstring's table now lists it.
- supports() passes max_chunks to unsupported_reason, so it answers for a
  decoder built with a non-default max_chunks.
- min_batch's docstring says the boundaries were measured on MI355X and are
  unmeasured on other gfx950 parts.
@nehmathe2 nehmathe2 changed the title [OPUS] [MLA] mla_flat: supports(), min_batch() and capacity sizing fo… [OPUS] [MLA] mla_flat: supports(), min_batch() and capacity sizing Dec 4, 2026
nehmathe2 added a commit to nehmathe2/ATOM that referenced this pull request Dec 4, 2026
aiter's min_batch (ROCm/aiter#9178) now also takes one query token a request
from batch 8 at wide head counts. OpusMla.takes keeps ATOM to the MTP decode
this PR validates: buckets of one query token stay on mla_decode_fwd.

The DCP1 kernel check runs at aiter's smallest batch for each shape (batch 8
for 16 heads at 3-4 tokens, which aiter now keeps on mla_decode_fwd below it).
zufayu added a commit that referenced this pull request Dec 4, 2026
…runcated watchdog read, size the agent timeouts for the 4-lane pool (#9201)

* [CI] review-bot: read WORK out of a binary fetch log, retry a stalled watchdog read, size the agent timeouts for the 4-lane pool

Three failure modes from the 2026-12-04 outage (6 failed runs, 01:24-03:02):

- run_one.sh extracted WORK= from the tee'd fetch log with a bare grep, so a PR
  with binary artifacts (OPUS .co blobs put NULs in that log) made grep answer
  "binary file matches" instead of the match -- a fetch that SUCCEEDED was
  reported as "fetch produced no WORK dir" on every retry (#8283/#7979/#7983).
  grep -a reads the log as text.

- watchdog.py caught only HTTPError, so a 30s socket timeout crashed the
  watchdog with a bare TimeoutError and failed a run whose review had already
  published a green card (#9178). A stalled GET is now retried (3 attempts,
  5s backoff); a POST is never retried, because a retried comment can land
  twice, and a failed POST degrades to 0, which the caller already warns about.

- AITER_AGENT_TIMEOUT=2400s was sized for one review at a time; the 4-lane
  pool serves four through the same GLM endpoint and workers measured 25-40+
  min under that load, so 2400s timed out live while the backend answered
  normally (#8983/#8541). Defaults now 3300s/agent and 6900s/run (115 min,
  still under the job's timeout-minutes of 120; check_prompts.py asserts it).

watchdog_test.py gains real-socket transport checks (the retry lives below the
_get/_post seam its fakes replace) with a mutation guard; _fetchfail_test.sh
gains the binary-log case. selftest: 156 green / 0 red.

Co-Authored-By: Claude Code <[email protected]>

* watchdog: retry a truncated response body, not just a stalled read

A response that dies mid-body raises http.client.IncompleteRead -- an
HTTPException, not an OSError -- so the OSError-only retry net added for
the 2026-12-04 stall let it escape unretried and unnamed: the same
bare-traceback crash one layer up, and _post's RuntimeError guard could
not degrade it either. Name the family in the catch so a truncated GET is
retried like a stalled one and a truncated POST degrades to 0.

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants