Skip to content

[FlyDSL] qkv chain: one counter set per (device, stream), as the split-K GEMM semaphore (fixes recapture exhaustion) - #9074

Merged
ganyi1996ppo merged 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/qkv-chain-counter-lifetime
Dec 2, 2026
Merged

ganyi1996ppo merged 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/qkv-chain-counter-lifetime

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

qkv_chain_cooperative_insert (the one-launch MiniMax-M3.1 QKV front, #8607) took a new epoch-counter set from a fixed 512-set pool for every CUDA-graph capture (keyed by HIP capture ID) and never gave one back. A framework that destroys and recaptures its graphs ran out after 512 captures: RL rollout sleep/wake recaptures every decode graph, and 12 of the default capture sizes use the one-launch tier. Capture then raised more than 512 counter sets, and the caller fell back to eager for good (ATOM: _recapture_cudagraphs_if_needed sets enforce_eager = True).

Change

_counters is now built the way the generic split-K GEMM builds its semaphore (gemm_kernels._get_preshuffle_split_semaphore): @capture_scoped_cache + persistent_alloc, one zeroed set per (device, stream). Eager launches and the captures on that stream share the set. The 512-set pool, the capture-ID keying and its hipStreamGetCaptureInfo ctypes wrapper are gone (qkv_chain.py: +14 / −69).

This is safe with one set per stream because of the kernel's epoch protocol (unchanged). Each call adds 16 to every head counter and its owners wait for the full epoch, so after any completed call the set is a multiple of 16 and the next stream-ordered call needs no reset. Recapturing graphs on a stream therefore allocates nothing new.

Contract (module docstring), the same as the split-K GEMM's: launches sharing a stream's set run in that stream's order, and graphs captured on one stream must not be replayed concurrently. Graphs captured on different streams have different sets.

From capture_scoped_cache: if a stream has had no eager call before its first capture, the capture gets a capture-scoped set. That set is zeroed by one fill node recorded into the graph (measured below as "cold") and kept per capture. Frameworks run an eager warmup forward on the capture stream right before recording (ATOM: ModelRunner.capture_cudagraph, under aiter's graph_capture()), so their captures share the stream's set ("warm").

Performance (gfx950 MI355X, one GPU, origin/main vs this PR)

Method: both modules were loaded in one process and timed in alternating order (15 rounds, median). Times are in us; 1-64 rows run the one-launch tier, 96 and 128 the split path.

  • "warm": captured on the stream the eager calls ran on.
  • "cold": torch.cuda.graph's own side stream, on which nothing ran eagerly.
  • "x1": one chain call per graph; "x60": 60 calls per graph, like a decode step's layers.
rows eager main eager PR warm x1 main warm x1 PR warm x60 main warm x60 PR cold x1 main cold x1 PR
1 90.42 90.38 10.12 10.10 287.8 288.0 9.89 14.18
8 90.96 90.90 10.93 10.96 341.7 339.8 10.80 15.10
32 91.22 91.07 12.56 12.51 426.8 423.5 12.32 16.53
64 91.72 91.58 14.88 14.79 556.5 557.8 14.44 18.81
96 106.06 106.18 16.12 16.13 631.5 632.3 15.77 15.79
128 104.82 104.83 17.62 17.55 725.8 727.0 17.20 17.22
  • Warm (the framework pattern): equal to main.
  • Cold: +4.3 to 4.4 us per replay at 1-64 rows, from the recorded zero fill. This is the split-K semaphore's existing behaviour.
  • Eager: unchanged.

PR Self-Review

Reviewed revision

236de68d9a

Behavior and intent

The qkv chain's cross-workgroup counter set used to be per graph capture, from a 512-set pool that was never returned, so the 513th capture on a device failed. It is now per (device, stream), built by aiter's existing capture_scoped_cache + persistent_alloc pattern (as _get_preshuffle_split_semaphore), so any number of capture / destroy / recapture cycles work. Two things are given up, and the docstring states both:

  • Concurrent replay of graphs captured on the same stream is no longer promised; it is not promised for the split-K GEMM either.
  • A capture on a stream with no prior eager call records one zero fill into its graph.

The kernel is unchanged.

Validation and unverified scope

Validated on gfx950 MI355X (rocm/atom-dev:nightly_202612011644, FlyDSL 0.5.3, one GPU), with qkv_chain.py swapped between main and this PR:

Unverified:

  • gfx942/gfx1250: the kernels are gfx950-only, and the tests skip elsewhere.
  • No end-to-end serving A/B: the warm graph replay time equals main, so none was run.
  • Concurrent replay of graphs captured on one stream is not tested, because it is outside the contract.

PR-specific question

Why per (device, stream) rather than per capture? Per capture needs either a pool that grows with every capture (the bug) or a way to free a set when its graph is destroyed (an earlier revision used HIP user objects for that). The split-K GEMM already settled the trade-off with a per-stream scratch helper, and the epoch protocol makes stream-ordered reuse correct without a reset, so the chain reuses that helper.

Changed op tests

op_tests/test_flydsl_qkv_chain.py adds three tests, none redundant with the existing canonical ones (test_chain_graph_replay_matches_eager captures one graph once):

  • test_chain_recapture_does_not_leak_counters[8, 64]
    • Covers: 600 capture / replay / destroy cycles on a stream with an eager warmup; parity against eager every 50 cycles; a graph kept alive throughout; the capture reusing the stream's eager-built set.
    • On main: fails with the 512-set error. No existing test destroys or recaptures graphs.
  • test_chain_many_graphs_replay_serially
    • Covers: graphs at 1/8/32/64/96 rows sharing one memory pool. Setup, eager warmups, captures, replays and eager calls all run on one dedicated stream passed to torch.cuda.graph. Every capture is asserted to reuse the stream's eager-built set, and each replay, interleaved with eager calls, equals eager.
    • Why it's needed: guards the "one set per stream" reuse across several graphs and both tiers, which no existing test does.
  • test_chain_graphs_of_two_streams_replay_concurrently
    • Covers: each graph is captured on its own warmed stream and asserted to reuse that stream's set; the two sets differ; replayed at the same time, both stay equal to eager.
  • The existing test_chain_graph_replay_matches_eager still captures on torch.cuda.graph's own side stream, so it covers the capture-scoped ("cold") path.
    • Why it's needed: guards the part of the concurrency contract that remains.

black / ruff clean.

🤖 Generated with Claude Code

…is destroyed

The one-launch QKV front chain (qkv_chain_cooperative_insert) gave every CUDA
graph capture its own epoch-counter set from a fixed 512-set pool and never
returned it. A framework that destroys and recaptures its graphs (RL rollout
sleep / wake recaptures every decode graph) ran out after 512 captures:
"more than 512 counter sets", and the caller fell back to eager mode.

Each capture's set is now owned by the graph: a HIP user object retained by
the captured graph runs libc sem_post (no HIP call, no Python) once the graph
and every executable instantiated from it are destroyed, and the next set
request returns that set to the pool. The pool now bounds the graphs alive at
once, not the captures ever made. No kernel, launch or graph-node change: the
counters still need no reset, eager calls keep one set per stream, and
separate graphs still never share a set (concurrent replay stays correct).

Tests: 600 capture / replay / destroy cycles with parity to eager and a graph
kept alive throughout; graphs of 1-96 rows replayed interleaved on one stream;
two graphs replayed concurrently on two streams.

Co-Authored-By: Claude <[email protected]>
@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot December 2, 2026 11:41
@github-actions

github-actions Bot commented Dec 2, 2026

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 9074 --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 FlyDSL label Dec 2, 2026
@aiter-bot

aiter-bot commented Dec 2, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 236de68d9a68 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The qkv chain's cross-workgroup counter set used to be per graph capture, from a 512-set pool that was never returned, so the 513th capture on a device failed. It is now per (device, stream), built by aiter's existing `capture_scoped_cache` + `persistent_alloc` pattern (as `_get_preshuffle_split_semaphore`), so any number of capture / destroy / recapture cycles work. Two things are given up, and the docstring states both:
- Concurrent replay of graphs captured on the same stream is no longer promised; it is not promised for the split-K GEMM either.
- A capture on a stream with no prior eager call records one zero fill into its graph.

The kernel is unchanged.

Validation and unverified scope

Validated on gfx950 MI355X (`rocm/atom-dev:nightly_202612011644`, FlyDSL 0.5.3, one GPU), with `qkv_chain.py` swapped between main and this PR:
- `python -m pytest op_tests/test_flydsl_qkv_chain.py`: 197 passed, 64 skipped.
- The 7 graph tests (`-k "recapture or many_graphs or concurrently or graph_replay"`): passed 3 of 3 repeated runs at 236de68d9a.
- On main, `test_chain_recapture_does_not_leak_counters[8|64]` fail with `RuntimeError: qkv_chain_cooperative_insert: more than 512 counter sets on cuda:0`.
- ATOM's recapture test (ROCm/ATOM#3810, `tests/test_minimax_m3_qkv_chain_recapture_gpu.py`, 50 sleep/wake cycles through `release_cudagraphs` → `_recapture_cudagraphs_if_needed`):
  - main: fails at the 39th wake (512-set error, falls back to `enforce_eager`)
  - this PR: passes 3 of 3
- The performance table above.

Unverified:
- gfx942/gfx1250: the kernels are gfx950-only, and the tests skip elsewhere.
- No end-to-end serving A/B: the warm graph replay time equals main, so none was run.
- Concurrent replay of graphs captured on one stream is not tested, because it is outside the contract.

PR-specific question

Why per (device, stream) rather than per capture? Per capture needs either a pool that grows with every capture (the bug) or a way to free a set when its graph is destroyed (an earlier revision used HIP user objects for that). The split-K GEMM already settled the trade-off with a per-stream scratch helper, and the epoch protocol makes stream-ordered reuse correct without a reset, so the chain reuses that helper.

Changed op tests

`op_tests/test_flydsl_qkv_chain.py` adds three tests, none redundant with the existing canonical ones (`test_chain_graph_replay_matches_eager` captures one graph once):
- `test_chain_recapture_does_not_leak_counters[8, 64]`
  - Covers: 600 capture / replay / destroy cycles on a stream with an eager warmup; parity against eager every 50 cycles; a graph kept alive throughout; the capture reusing the stream's eager-built set.
  - On main: fails with the 512-set error. No existing test destroys or recaptures graphs.
- `test_chain_many_graphs_replay_serially`
  - Covers: graphs at 1/8/32/64/96 rows sharing one memory pool. Setup, eager warmups, captures, replays and eager calls all run on one dedicated stream passed to `torch.cuda.graph`. Every capture is asserted to reuse the stream's eager-built set, and each replay, interleaved with eager calls, equals eager.
  - Why it's needed: guards the "one set per stream" reuse across several graphs and both tiers, which no existing test does.
- `test_chain_graphs_of_two_streams_replay_concurrently`
  - Covers: each graph is captured on its own warmed stream and asserted to reuse that stream's set; the two sets differ; replayed at the same time, both stay equal to eager.
- The existing `test_chain_graph_replay_matches_eager` still captures on `torch.cuda.graph`'s own side stream, so it covers the capture-scoped ("cold") path.
  - Why it's needed: guards the part of the concurrency contract that remains.

black / ruff clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

ganyi1996ppo added a commit to ganyi1996ppo/ATOM that referenced this pull request Dec 2, 2026
Drives MemoryManagerMixin's own release_cudagraphs ->
_recapture_cudagraphs_if_needed 50 times on decode graphs (default capture
sizes up to 128 rows) that run aiter's qkv_chain_insert, and checks that the
runner never falls back to enforce_eager and that a replay after the last wake
equals the eager call at 1/8/64/128 rows. Before ROCm/aiter#9074 aiter never
returned a destroyed graph's counter set, so the 42nd wake's recapture failed
("more than 512 counter sets") and the runner went eager for good; ATOM
itself manages no counters. GPU only (gfx950); skips on the CPU job.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Completed graph sets are reclaimed only during capture, so new eager-stream allocations can incorrectly report pool exhaustion even after all graphs have been destroyed.

1 open issue
What changed in this PR

This PR makes CUDA graphs own their QKV-chain counter sets, allowing destroyed graphs’ sets to be reused instead of exhausting the fixed pool during recapture.

Changes:

  • Adds graph-lifetime tracking through HIP user objects and native semaphores.
  • Adds recapture, serial replay, and concurrent replay tests without changing GPU kernels.
File Description
op_tests/​test_flydsl_qkv_chain.py Tests counter reuse and graph replay correctness.
aiter/​ops/​flydsl/​kernels/​qkv_chain.py Tracks graph-owned counter sets and reclaims released storage.

Review effort: Balanced

Comment thread aiter/ops/flydsl/kernels/qkv_chain.py Resolved
…t-K GEMM semaphore

Replace the 512-set pool and the HIP user-object reclamation with the helper
pattern the generic split-K GEMM already uses for its semaphore
(gemm_kernels._get_preshuffle_split_semaphore): capture_scoped_cache +
persistent_alloc, one zeroed set per (device, stream), shared by eager launches
and the captures on that stream. The epoch protocol (each call adds 16 to every
head counter) needs no reset between stream-ordered launches, so recapturing
graphs allocates nothing new. Contract as the split-K GEMM's: launches sharing a
stream's set run in stream order; graphs captured on one stream are not replayed
concurrently. Kernel unchanged.

Tests: the 600-cycle recapture test now runs on one stream with an eager warmup
(as frameworks capture) and checks the capture reuses the stream's set; the
concurrent test now captures on two streams (separate sets).

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 12:10
@ganyi1996ppo ganyi1996ppo changed the title [FlyDSL] qkv chain: return a CUDA graph's counter set when the graph is destroyed (fixes recapture exhaustion) [FlyDSL] qkv chain: one counter set per (device, stream), as the split-K GEMM semaphore (fixes recapture exhaustion) Dec 2, 2026
ganyi1996ppo added a commit to ganyi1996ppo/ATOM that referenced this pull request Dec 2, 2026
…rm docstring

ROCm/aiter#9074 now keeps the chain's counters as one set per (device, stream),
shared by eager calls and captures on that stream (the split-K GEMM semaphore
pattern). The GPU recapture test now captures the way ModelRunner does under
graph_capture(): a new stream per pass, and per bucket an eager warmup forward
on it, then the recording on it. warm()'s docstring no longer cites the old
"first call inside capture raises" counter-pool rule; warm-up still compiles
every row count before serving.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test mixes graph-capture and eager execution streams, leaving shared eager-built counters across different row-count graphs untested.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_flydsl_qkv_chain.py Resolved
…ream's set is reused

test_chain_many_graphs_replay_serially now runs setup, eager warmups,
captures, replays and eager calls on one dedicated stream and passes it to
torch.cuda.graph, asserting every capture reuses the stream's eager-built set;
the two-stream test asserts the same per stream. The recapture test's final
check records a call instead of an empty graph. The existing single-graph
replay test keeps torch.cuda.graph's own side stream (the capture-scoped path).

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because the test comparator bypasses required mismatch diagnostics, and allocation-free recapture depends on undocumented stream warmup.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@ganyi1996ppo
ganyi1996ppo merged commit 9b1dc90 into ROCm:main Dec 2, 2026
81 of 88 checks passed
zhuyuhua-v pushed a commit to ROCm/ATOM that referenced this pull request Dec 3, 2026
…ed decode, default-on): fused qkv GEMM + q/k/index RMSNorm + partial RoPE + NVFP4 insert via aiter qkv_chain_insert (#3810)

* [M3] decode: 17-64 row QKV front chain, quantize in the linear + one-launch GEMM/norm/RoPE/insert in the attention op (ATOM_M3_QKV_CHAIN, default off)

For 17-64 row pure-decode steps (TP4, NVFP4 K/V and index caches) a sparse layer's qkv_proj only runs the MXFP8 activation
quantizer and the attention op's rope_cache runs aiter's one-launch QKV GEMM + q/k/index RMSNorm + RoPE + NVFP4 insert
(qkv_chain_cooperative_insert) on the parked codes. Decided at run time inside two custom ops; other rows keep today's path.
Needs the paired aiter PRs (feature-detected, a no-op without them).

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

* [M3] qkv chain: review fixes (token-graph, preshuffle, eligibility, weight-cache key, per-thread hand-off) + black

- take(): never inside a token graph (TR_HYBRID decode replays the captured quantizer without the Python hand-off)
- chain only with a preshuffled weight (qkv_front gate + load-time check, else chain off for the layer)
- eligibility: native 1x32 MXFP8 qkv weights only (linear_ok), forward keys on _qkv_chain_scale existing
- ATOM_M3_QKV_CHAIN added to the weight-cache key
- hand-off slot is thread-local (TBO decode micro-batches)
- black formatting of the PR files

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

* [M3] decode: QKV front chain window 17-64 -> 17-128 rows (split-3 GEMM + reduce-insert), feature-detected

With an aiter that has qkv_chain_insert / code_rows the chain serves 65-128 rows through the split chain; the quantizer pads to
code_rows(m); warm-up covers the three 65-128 row configs. Without it the window stays 17-64. ATOM_M3_QKV_CHAIN still gates it.

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

* [M3] qkv chain: one-shot 'chain active' log (layer census, row window, aiter features, per-reason decision tally over the first 1000 python-side calls)

Counters live only where Python runs (warm-up, eager, graph capture); graph replay is untouched.

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

* test: the census log test pins the stage-1 window

* [M3] qkv chain: review fixes round 2 (import before the preshuffle branch, gfx950 gate, refuse TR_HYBRID record/replay via ForwardContext.tr_graph, ruff BLE001/S110)

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

* MiniMax-M3 QKV front chain: re-point the activation quantizer to the plain row-major contract (#8607), floor 1

ROCm/aiter#8607 removed the standalone mxfp8_quant_shuffled module and changed the
chain's activation contract: qkv_chain_cooperative_insert / qkv_chain_split_insert now
read the PLAIN quantizer's row-major E4M3 codes [m,K] + 1x32 E8M0 scales [m,K/32]
(no (16,16) relayout). available() therefore returned False on current aiter and the
feature was inert.

- Re-point: new _front_quant(x2) = per_group_quant_hip(x2, quant_dtype=dtypes.fp8,
  group_size=32, scale_type=dtypes.fp8_e8m0) -- exactly aiter's own gemm_a8w8_qkv_front
  call; replaces mxfp8_quantize_shuffled(x2, code_rows(m)) at both the qkv_front and warm
  sites (the (m+15)//16*16 tiling is now internal to aiter). available() checks
  aiter.ops.quant instead of the removed module, so it is True on current aiter.
- Lower the engage floor MIN_ROWS 17 -> 1 (keep 64 coop / 128 split ceiling): the
  front-chain bench shows the fused path winning 22-28% at M=1-16, the dominant M3.1
  decode band.

KEPT ATOM_M3_QKV_CHAIN default-off: the shuffled->row-major activation layout change is
correctness-sensitive and CANNOT be GPU-validated today (the aiter front feature is not
built in any reachable container). Flip to default-on only after a GPU relL2 / op-test
confirms the QKV front output.

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

* MiniMax-M3 QKV chain: default-on (remove ATOM_M3_QKV_CHAIN), fix stale 17-row window text + warm tiers

The QKV front chain is a measured-good decode path, so it ships default-on with
no opt-in flag (feature-detected: aiter has the chain ops and the GPU is gfx950),
matching the project's default-on-no-flag convention.

- Remove the `ATOM_M3_QKV_CHAIN` env var: `enabled()` is now `available() and
  _is_gfx950()`; drop it from `envs.py` and from the weight-cache key `_ENV_VARS`
  (the weight layout now varies only by stable arch / aiter availability, not a
  user toggle); reword the flag-named comments/log lines to "M3 QKV chain".
- The row window was already lowered to 1..128 in code (`MIN_ROWS = 1`,
  `SPLIT_MAX_ROWS = 128`); fix the remaining stale "17-64" docstring/comment text
  and the row-window tests, which still asserted the old 17-row floor (they were
  masked because the aiter import-guard skips the module on a non-GPU runner).
- Warm the 32-code tier again: with the floor at 1 the coop warm set
  `(MIN_ROWS, 33, 49)` covered code tiles 16/48/64 and dropped 32 (m=17-32); use
  `(MIN_ROWS, 17, 33, 49)` -> 16/32/48/64 so every in-window tile compiles at load.

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

* M3 QKV chain: arch gate uses live GPU (get_gfx_runtime), fix stale activation-layout docstring

- `_is_gfx950()` now probes `get_gfx_runtime()` instead of `get_gfx()`. aiter's own
  guidance: get_gfx_runtime detects the live GPU and is for runtime dispatch /
  code-path selection, while get_gfx follows the GPU_ARCHS build arch. Since the
  chain is now default-on, this arch guard is the primary gate and must follow the
  real device (it also handles the AOT-replay case internally).
- Module docstring: the activation quantizer is `per_group_quant_hip` (row-major
  e4m3 codes [m, K] + 1x32 E8M0 scales [m, K/32], no relayout), not the old
  (16,16)-tile / AITER-shuffled layout — matches the merged aiter #8607 contract.
- Drop the inaccurate "16-row code tile" wording from the warm() comment (the
  merged entries take [m, K] row-major activation, no code tiling).

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

* M3 QKV chain: gate the qkv_front forward branch on the layer's own _qkv_chain, not just the cached scale

The forward branch selected the deferred-QKV chain path whenever `_qkv_chain_scale`
was present. But the weight cache can hand that attribute to a client whose kv dtype
is not chain-eligible (`_qkv_chain=False`) — the cache key omits kv_cache_dtype, so an
FP8-cache client can reuse an NVFP4 sibling's prepared weight and receive its
`_qkv_chain_scale`. That client would then enter the NVFP4-only chain insert and fail
decode. Gate the branch on `getattr(self, "_qkv_chain", False)` as well, matching the
weight-prep guard that produces the scale (linear.py:1462).

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

* M3 QKV chain: light up the full 1-128 window — fix split_available probe + per-m coop/split dispatch

The merged aiter #8607 serves 65-128 rows with a real split kernel
(`qkv_chain_split_insert` -> `mxfp8_gemm_decode_splitk`, ROWS=(65,128)), but ATOM's
`split_available()` probed a `code_rows` symbol that #8607 never exported, so it was
always False and the 65-128 path was dead (window capped at 64).

- `split_available()` now probes the real entry `qkv_chain_split_insert` (and drops the
  vestigial `code_rows` / (16,16)-tile model: both merged entries take plain row-major
  `[m, K]` activation from `per_group_quant_hip`, no tiling).
- Dispatch is now per-m, not per-`split_available()`: `_chain_entry(m)` returns
  `qkv_chain_cooperative_insert` for 1-64 and `qkv_chain_split_insert` for 65-128
  (each aiter entry raises outside its own row range). Applied in both `run_chain` and
  the load-time `warm()` loop (the old code picked the split entry for every m, which
  would have raised for the 1-64 warm rows).
- Window is now the full 1-128 default-on (coop 1-64, split 65-128); `max_rows()` = 128
  when the split entry is present.

NOTE: the 65-128 split path has not yet had an ATOM-level GPU numeric run (the aiter
kernel is aiter-CI-tested; the ATOM integration for 65-128 is not yet exercised e2e).
A one-time relL2/op-test of the 65-128 path should run before/at merge.

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

* [M3] QKV front chain: M3-owned path, no aiter probing, aiter's dispatch, per-step decision

Addresses the review of de32196:
- import aiter.ops.flydsl.kernels.qkv_chain directly; drop available() /
  split_available() / aiter_features() / _is_gfx950() (NVFP4 caches are
  already gfx950-only in minimax_m3/config.py)
- gate on aiter's chain_supported(m) and call qkv_chain_insert; drop
  COOP_MAX_ROWS / SPLIT_MAX_ROWS / _chain_entry
- LinearBase untouched: MiniMaxM3SparseAttention.forward calls the M3 op
  minimax_m3_qkv_front over its own qkv weight; codes are parked on the
  layer's own attention impl (one slot per TBO micro-batch), no thread-local
- chain-scale prep + warm-up in MiniMaxM3SparseAttention.post_load, run by
  both load paths (end of load_model and a weight-cache hit) via
  run_post_load_hooks
- warm every row count qkv_chain_insert serves (1-128, all split tiers incl.
  121-128), once per device
- the step decision is MiniMaxM3SparseMetadata.qkv_chain (decode, set at
  build); per call only tr_graph and chain_supported(m); drop the census log
- CPU-lane tests via aiter_stub over the real wiring

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

* test: M3 QKV chain rope_cache consumes the codes of its own micro-batch id (1 as well as 0)

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

* [M3] QKV chain: post_load decides qkv_chain afresh on every load (a weight-cache hit restores the exporter's flag)

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

* [M3] QKV chain: run post-load hooks in the serving process, not inside load_weights

The weight-cache daemon loads through load_weights; a hook run there (the
chain's warm-up: aiter's counter pool, the warmed-device set) would be
exported to every client as a process change. ModelRunner runs the hooks
after a checkpoint load (model and drafter), the client after a cache hit.

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

* [M3] QKV chain: pin where post_load hooks run; document the fused insert's octet slot contract

- tests/test_weight_cache.py: the daemon's _DaemonLoad (through the real
  load_weights -> load_model) runs no post_load; a checkpoint load through
  ModelRunner._build_and_load_model / _build_and_load_drafter runs each
  hook exactly once; a cache hit (load_from_cache / load_drafter_from_cache)
  runs each hook exactly once.
- rope_cache_chain: state the 8-slot octet contract of aiter's fused insert
  (rows sharing an octet are written as one consecutive run), narrower than
  fused_qknorm_idxrqknorm's.

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

* [M3] QKV chain: eligibility requires the qkv weight to be aiter's chain shape (N x K)

A layer with the TP4 head layout and NVFP4 caches but another hidden size
(e.g. 8192) passed linear_ok/layer_ok and then failed in warm() (aiter's
qkv_chain_insert validates weight == (N, K)). linear_ok now compares the
weight shape against aiter's exported N, K (aiter has no shape predicate);
such a layer keeps its linear.

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

* [M3] QKV chain: a step that does not take the chain pays nothing per layer; test the drafter-warmup flag; aiter's ROT

- MiniMaxM3Model decides once per step (_qkv_chain_step): eagerly, the step's
  sparse-metadata flag and aiter's chain_supported(rows); while compiling,
  always (the op decides at run time). The decision is handed down
  (decoder layer -> attention); a step that cannot take the chain calls
  qkv_proj directly, with no op, config lookup or import.
- qkv_chain_step (sparse_attn.py, no FlyDSL import) reads the per-step flag
  before anything else; takes_chain = qkv_chain_step() and chain_supported(m).
- post_load binds takes_chain / quant_activation on the layer: no import on
  the per-layer path; MiniMaxM3Model.post_load binds the row window only when
  a layer is eligible.
- layer_ok uses aiter's ROT instead of 64.
- CPU-lane tests: the per-step decision, the model handing one decision to
  every layer, the decoder handing it to attention, the row-window binding,
  and prepare_mtp_decode building qkv_chain=False on a dummy (warmup) step.

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

* test: the drafter-warmup metadata case gives the launch grid a real cdiv on the CPU job

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

* [M3] QKV chain scope: eager forward only (eager decode, CUDA-graph captured decode); compiled code holds no chain

The maintainer's option (b) for the cost of non-chain steps:
- MiniMaxM3Model._qkv_chain_step is False while compiling: compiled code
  never routes through qkv_front, so a compiled step pays nothing for it.
- The chain-layer qkv front is a plain method again (no custom op, no
  static_forward_context entry): only the eager forward reaches it.
- support_torch_compile asks an optional model hook, runs_eager(*args,
  **kwargs), once per call and runs the eager forward when it is True.
  MiniMaxM3Model.runs_eager is True for a CUDA-graph capture (in_hipgraph)
  of a decode step the chain takes, so the captured decode graph records
  the chain; every other compiled step runs the compiled code.
- CPU-lane tests: never in compiled code, the capture hook's cases, the
  wrapper running the eager forward only where the model asks, routing
  through qkv_front.
- docs: compilation guide (the hook), model ops guide (the scope).

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

* [M3] QKV chain: SGLang's sparse forward takes the decoder's qkv_chain; bind the capture hook only to an enabled chain layer

- atom/plugin/sglang/models/minimax_m3.py: _sparse_forward_native_for_sglang
  accepts (and ignores) the qkv_chain the decoder layer passes on every
  step; it raised TypeError for every M3 sparse model under SGLang.
- run_post_load_hooks runs children before their parent, so
  MiniMaxM3Model.post_load binds the row window only when a layer's own
  post_load enabled the chain: an eligible layer whose weight is not
  preshuffled no longer makes decode captures run the eager forward.
- CPU-lane tests for both and for the hook order.

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

* [M3] QKV chain: bind each sparse layer's qkv route at post_load; main's call signatures

MiniMaxM3Model, MiniMaxM3DecoderLayer, MiniMaxM3Attention and the SGLang
sparse-forward override keep main's signatures: no per-step qkv_chain
keyword is threaded through the layer calls. MiniMaxM3SparseAttention.forward
calls self.project_qkv, a plain attribute bound to the qkv linear's __call__
at build and by post_load, or to qkv_front on a layer post_load enables the
chain on. qkv_front reads torch.compiler.is_compiling() and the step flag
itself (takes_chain), so compiled code traces the qkv linear only; its
fallback calls the linear through a bound attribute too. The model forward
no longer reads the step flag; runs_eager (captured decode) reads it once.

CPU-lane tests pin the binding (init, post_load reset/enable, forward route,
compiling / pre-quantized fallback, no kwarg on any layer call, SGLang
signature); 13 mutants of the binding each fail a test.

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

* [M3] QKV chain: GPU test of repeated rollout graph release / recapture

Drives MemoryManagerMixin's own release_cudagraphs ->
_recapture_cudagraphs_if_needed 50 times on decode graphs (default capture
sizes up to 128 rows) that run aiter's qkv_chain_insert, and checks that the
runner never falls back to enforce_eager and that a replay after the last wake
equals the eager call at 1/8/64/128 rows. Before ROCm/aiter#9074 aiter never
returned a destroyed graph's counter set, so the 42nd wake's recapture failed
("more than 512 counter sets") and the runner went eager for good; ATOM
itself manages no counters. GPU only (gfx950); skips on the CPU job.

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

* [M3] QKV chain: recapture test captures as capture_cudagraph does; warm docstring

ROCm/aiter#9074 now keeps the chain's counters as one set per (device, stream),
shared by eager calls and captures on that stream (the split-K GEMM semaphore
pattern). The GPU recapture test now captures the way ModelRunner does under
graph_capture(): a new stream per pass, and per bucket an eager warmup forward
on it, then the recording on it. warm()'s docstring no longer cites the old
"first call inside capture raises" counter-pool rule; warm-up still compiles
every row count before serving.

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

* [M3] QKV chain: a weight-discarding sleep frees the chain's weight scale

The chain's shuffled weight scale is GPU memory outside the parameters
(about 0.47 MiB per chain layer), so it stayed allocated through a rollout
sleep that discards the weights. MiniMaxM3SparseAttention and
MiniMaxM3Model now define release_weight_memory / resume_weight_memory
(the MemoryManagerMixin contract): the release drops the scale and binds
the qkv linear back, and the model unbinds its chain row window. The scale
is derived from the weights, so only a load (post_load) enables the chain
again. CPU tests; 4/4 mutants of the release hooks fail them.

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

---------

Co-authored-by: Claude <[email protected]>
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.

4 participants