Repository navigation
[FlyDSL] qkv chain: one counter set per (device, stream), as the split-K GEMM semaphore (fixes recapture exhaustion) - #9074
Conversation
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
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]>
There was a problem hiding this comment.
🟡 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
…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]>
…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]>
…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]>
There was a problem hiding this comment.
🔵 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
…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]>

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 raisedmore than 512 counter sets, and the caller fell back to eager for good (ATOM:_recapture_cudagraphs_if_neededsetsenforce_eager = True).Change
_countersis 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 itshipStreamGetCaptureInfoctypes 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'sgraph_capture()), so their captures share the stream's set ("warm").Performance (gfx950 MI355X, one GPU,
origin/mainvs 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.
torch.cuda.graph's own side stream, on which nothing ran eagerly.PR Self-Review
Reviewed revision
236de68d9aBehavior 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_allocpattern (as_get_preshuffle_split_semaphore), so any number of capture / destroy / recapture cycles work. Two things are given up, and the docstring states both:The kernel is unchanged.
Validation and unverified scope
Validated on gfx950 MI355X (
rocm/atom-dev:nightly_202612011644, FlyDSL 0.5.3, one GPU), withqkv_chain.pyswapped between main and this PR:python -m pytest op_tests/test_flydsl_qkv_chain.py: 197 passed, 64 skipped.-k "recapture or many_graphs or concurrently or graph_replay"): passed 3 of 3 repeated runs at 236de68.test_chain_recapture_does_not_leak_counters[8|64]fail withRuntimeError: qkv_chain_cooperative_insert: more than 512 counter sets on cuda:0.tests/test_minimax_m3_qkv_chain_recapture_gpu.py, 50 sleep/wake cycles throughrelease_cudagraphs→_recapture_cudagraphs_if_needed):enforce_eager)Unverified:
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.pyadds three tests, none redundant with the existing canonical ones (test_chain_graph_replay_matches_eagercaptures one graph once):test_chain_recapture_does_not_leak_counters[8, 64]test_chain_many_graphs_replay_seriallytorch.cuda.graph. Every capture is asserted to reuse the stream's eager-built set, and each replay, interleaved with eager calls, equals eager.test_chain_graphs_of_two_streams_replay_concurrentlytest_chain_graph_replay_matches_eagerstill captures ontorch.cuda.graph's own side stream, so it covers the capture-scoped ("cold") path.black / ruff clean.
🤖 Generated with Claude Code