Repository navigation
[Triton/Gluon] [FlyDSL] [CI] [Bugfix] Never share scratch buffers whose zero fill was recorded into a graph - #7126
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 Changes recommended
Capture handling can return buffers before their zero fill runs and retain an extra 16 MiB workspace per capture even after graph destruction, while CI skips the new regression tests.
4 open issues
What changed in this PR
This PR prevents AITER callers from sharing scratch buffers whose zero initialization was recorded into another CUDA graph. It addresses initialization safety beyond the existing private-memory-pool protection.
Changes:
- Add capture-scoped caching while preserving reuse of eagerly initialized buffers.
- Apply the cache to GEMM and top-k scratch allocations across Triton, FlyDSL, and ASM wrappers.
- Add capture-isolation and split-K hang regressions, and update the Triton cache-isolation test.
| File | Description |
|---|---|
op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py |
Reset the new counter cache for capture testing. |
op_tests/test_graph_alloc.py |
Add capture-isolation and subprocess hang regressions. |
aiter/utility/graph_alloc.py |
Add capture-ID lookup and capture-scoped caching. |
aiter/ops/triton/gemm/basic/gemm_afp8wfp8.py |
Scope split counters by capture; preserve older-torch fallback. |
aiter/ops/topk.py |
Apply capture-scoped caching to top-k workspace. |
aiter/ops/gemm_op_a8w8.py |
Isolate capture-initialized zero-bias buffers. |
aiter/ops/gemm_op_a16w16.py |
Isolate ASM semaphore workspace by capture. |
aiter/ops/flydsl/kernels/topk/topk_per_row_decode.py |
Scope cached top-k counters by capture. |
aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py |
Scope gfx950 split-K buffers by capture. |
aiter/ops/flydsl/gemm_kernels.py |
Apply capture-scoped caching to preshuffle scratch. |
aiter/ops/flydsl/gemm_a16w16_gfx1250.py |
Scope gfx1250 split-K counters by capture. |
aiter/ops/flydsl/batched_gemm_a8w8_gfx950.py |
Scope batched GEMM split counters by capture. |
Review effort: Balanced
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 |
|
Where vLLM's multi-stream reaches this GEMM, and why only inside a capture. I updated the e2e test to follow this pattern (6e0c9e6). I traced the first in-capture request for split-K buffers in a DeepSeek-V4.1-Flash DPATP2 server (vLLM main
Why fix it in AITER rather than in vLLM:
Updated test (
On MI355X: stock AITER hangs 3/3 (killed at 90 s); this PR passes 3/3. |
…orded into a graph Cached zero-initialized scratch (split-K semaphores and counters, zero bias, top-k workspaces) is built lazily with torch.zeros under persistent_alloc. When the first request for a key comes from inside a CUDA graph capture, e.g. a stream only seen while capturing, the zero fill is recorded into that graph instead of running. The buffer is then cached and handed to every later graph and eager caller with the same key, which run on uninitialized memory until the recording graph happens to replay. For the gfx950 a16w16 split-K GEMM this deadlocks: the launch tag is ticket // split_k + 1, so a semaphore word that is not a multiple of split_k makes the owner and the waiting splits derive different tags and spin forever. Seen as intermittent hangs serving DeepSeek-V4.1-Flash with vLLM on MI355X. Add capture_scoped_cache to graph_alloc: eagerly built buffers are cached and shared as before; a buffer first built inside a capture is cached for that capture only (keyed by hipStreamGetCaptureInfo's id), so the graph that zeroes it is the only user and re-zeroes it on every replay before use. Apply it to every cached zero-initialized scratch site. The caches become unbounded, which also removes LRU eviction of buffers a captured graph may still point at. Signed-off-by: Fangzhou Ai <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
….1 hits it vLLM's ROCm DeepSeek-V4.1 CSA attention forks work onto aux streams only inside graph capture, so the indexer weights_proj GEMM (bf16 [M, 5120] x [5120, 32], split-K 8) first runs on an aux stream mid-capture, once per capture size. Model that: eager warmup on the default stream only, then two captures of different M that fork the GEMM onto an aux stream with an event fork/join, and replay the graph without the recorded zero fill first. Signed-off-by: Fangzhou Ai <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… workspace, CI - capture_scoped_cache now asks HIP about the stream the builder's fill runs on (its stream argument, else the current stream of its device argument), not the ambient current device: a builder for cuda:1 called while cuda:0 is current and cuda:1 is capturing was treated as eager. - Split the preshuffle split-K buffers: the fully overwritten 16 MiB workspace stays one per (device, stream) and is never evicted; only the zero-initialized semaphore is capture-scoped. - The split-K repro checks with checkAllclose at test_flydsl_hgemm's bf16 split-K tolerances; add a two-GPU test for the target-device case. - Run op_tests/test_graph_alloc.py through pytest in aiter_test.sh (it has no __main__), and pass split_k in the private-pool test (same fix as #7039). Signed-off-by: Fangzhou Ai <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
6e0c9e6 to
1ca541f
Compare
|
CI note: the Triton MI35X shard 5 failure (
The Standard Tests that include |
|
No blocking issues @ 51bb039. One site of the same class is not covered; can it be folded in here?
Fix as for the preshuffle split here: workspace under ReachabilitySame trigger as |
…nters _fused_splitk_buffers built its per-tile arrival counters with a bare torch.zeros under lru_cache. Built first inside a capture (e.g. on an aux stream), the zero fill is recorded into that one graph, yet the buffer was handed to every later graph and eager call with the same key; the counters then never reach split_k - 1 and the tiles keep stale output. It also came from the graph's private pool, and LRU eviction could free a buffer a captured graph still points at. Split it as the preshuffle split-K buffers: the fully overwritten workspace stays one per key under functools.cache, and only the counters are capture-scoped; both come from persistent_alloc. The compile-only AOT path allocates directly, since it has no HIP stream to query. test_fused_split_k_gemm_whose_counters_are_first_used_inside_a_capture fails 3/3 on the old builder (98% mismatch) and passes with this change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
@XiaobingSuper Folded in at 50740bb. The workspace stays one per key under I reproduced it with the real |
…roed-scratch # Conflicts: # aiter/ops/flydsl/mxscale_preshuffle_kernels.py
The wheel build replays every tuned GEMM row through the runtime on FakeTensors with the GPUs hidden. Split-K rows build their semaphores through capture_scoped_cache, which asks hipStreamGetCaptureInfo which capture the stream is in; with no device that returns error 100, so 3502 rows failed and the FlyDSL GEMM AOT step raised. dry_run now answers "not capturing" for _capture_id, as it already does for torch.cuda.is_current_stream_capturing: a replay never captures. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings aiter.utility.graph_alloc.capture_scoped_cache (ROCm#7126). Signed-off-by: Jouni Hartikainen <[email protected]>


Summary
Cached zero-initialized scratch buffers (split-K semaphores/counters, zero bias, top-k workspaces) whose first request happens inside a CUDA graph capture get their
torch.zerosfill recorded into that one graph instead of executed. The buffer is still cached and handed to every later graph and eager caller with the same key, which then run on uninitialized memory until the recording graph happens to replay. For the gfx950 FlyDSL a16w16 split-K GEMM this is a deadlock. This PR addsgraph_alloc.capture_scoped_cacheand uses it at every such site.Root cause
get_split_k_buffers(stream, device, split_k)is cached per stream. In vLLM's DeepSeek-V4.1 on ROCm, the indexerweights_projGEMM (bf16[M, 5120] x [5120, 32], FlyDSL split-K 8) first runs on an aux stream inside graph capture, so its semaphores are first allocated mid-capture. A traced server shows exactly one such site per rank. The comment below gives the call path.SplitKProtocol.take_ticket) derives the launch tag asticket // split_k + 1and relies on every semaphore word being a multiple ofsplit_k. Uninitialized words are not (in the persistent pool on a GPU that ran a previous process, all 256 words were non-zero, e.g.2019269357943 ≡ 7 mod 8). The owner split and the waiting splits then derive different tags and spin forever.hgemm_bf16_..._kst4_...spinning inwait_until_initialized. It only reproduces when the recycled memory happens to be dirty, hence the intermittency._get_preshuffle_split_buffers, gfx1250_split_k_counters, the ASM a16w16 semaphore workspace, the a8w8 zero-bias buffer, the top-k workspaces / counters, the gfx950 batched a8w8 split counters, the gfx950 mxscale fused split-K (_fsk) arrival counters, and the Triton afp8wfp8 split counters. For example, a zero bias first built mid-capture would feed garbage bias to every other graph.Fix
capture_scoped_cache(inaiter/utility/graph_alloc.py) replacesfunctools.cache/lru_cacheat these sites:hipStreamGetCaptureInfo). Only the graph that recorded its zero fill ever uses it, and that graph re-zeroes it on every replay before using it, so correctness no longer depends on which graph replays first.hipStreamGetCaptureInfofails with error 100;dry_runnow stubs_capture_idas it already doesis_current_stream_capturing. A new test intests/test_flydsl_aot_replay.pycovers it.functools.cache; only the per-tile arrival counters are capture-scoped. Both now come frompersistent_alloc(before, a baretorch.zerosfrom whichever pool was active). The compile-only AOT path allocates directly.Nonemid-capture unless an eager buffer exists.Tests
op_tests/test_graph_alloc.py:test_capture_scoped_cache_keeps_capture_built_buffers_private: capture-built buffers are per capture and never returned eagerly; eager-built ones are shared with captures.test_capture_scoped_cache_checks_the_target_device_not_the_current_one(2 GPUs): a cuda:1 builder called with cuda:0 current while cuda:1 captures is capture-scoped.test_split_k_gemm_whose_semaphores_are_first_used_inside_a_capture: an end-to-end repro (gfx950) that follows vLLM's pattern:[M, 5120] x [5120, 32]split-K GEMM onto an aux stream with an event fork/join;It checks results with
checkAllcloseattest_flydsl_hgemm's bf16 split-K tolerances. It runs in a subprocess with a timeout, because the failure mode is a GPU spin.test_fused_split_k_gemm_whose_counters_are_first_used_inside_a_capture: the gfx950 mxfp8_fskGEMM (M=16, N=2304, K=6144, a tuned DSv4 row) in two aux-stream captures that share one graph pool. An earlier graph in that pool leaves 7s where the counters land, and the graph without the recorded zero fill replays first. Nothing spins, so it runs in-process..github/scripts/aiter_test.shnow runsop_tests/test_graph_alloc.pythrough pytest (the file has no__main__). The PR also carries #7039's one-linesplit_kfix for the existing private-pool test, so CI is green.Results on MI355X (gfx950), torch 2.10 ROCm:
pytest op_tests/test_graph_alloc.py(2 GPUs)_fskcapture testtest_gemm_a8w8_mxfp8_bpreshuffle.py -mnk 1/8/16,2304,6144(_fsk)pytest op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py -k "first_use_inside_capture or concurrent_streams or replay"End to end: vLLM DeepSeek-V4.1-Flash DPATP2 AgentX runs that previously stalled at first traffic or within ~20 min ran clean with the equivalent workaround applied. That covers 9 one-hour runs: DP2 c32 to c384, and DP4 c128/c256.
PR Self-Review
Reviewed revision
0b80b631fBehavior and intent
Cached scratch buffers that kernels need initialized (zeroed split-K semaphores/counters, zero bias, top-k workspaces) are no longer shared when their first request happens inside a CUDA graph capture.
torch.zerosinside a capture is recorded into that one graph, not executed. Yet the buffer was cached and handed to every other graph and eager caller, which then ran on uninitialized memory. The gfx950 a16w16 split-K ticket protocol then derives mismatched launch tags and spins forever, as seen serving DeepSeek-V4.1 in vLLM.capture_scoped_cachekeeps a capture-built buffer private to its capture, keyed by the HIP capture ID of the stream the fill runs on. That graph re-zeroes it on every replay. Eagerly built buffers are shared exactly as before.Validation and unverified scope
pytest op_tests/test_graph_alloc.py: 7 passed (2 GPUs);_fskcapture test fails 3/3 with the old builder and passes with this PR; the_fskmxfp8 GEMM shapes still pass with err 0;_fskconfig;dry_run, andtests/test_flydsl_aot_replay.pypasses 7/7;_split_k_countersand gfx942 paths are only exercised by CI);persistent_allocalready refuses mid-capture allocation;PR-specific question
graph_allocand is applied at every zero-initialized site: every such site has the same failure mode. Fixing only the split-K site would leave, for example, the zero-bias buffer feeding garbage bias to graphs.capture_begincannot cover it.Changed op tests
op_tests/test_graph_alloc.py:test_capture_scoped_cache_keeps_capture_built_buffers_privateand..._checks_the_target_device_not_the_current_onecover the cache contract. They fail before this PR because the helper does not exist; a stock builder would return the capture-built buffer to eager callers.test_split_k_gemm_whose_semaphores_are_first_used_inside_a_capturehangs (times out) before this PR. No existing test captures a split-K GEMM whose semaphores are first allocated mid-capture on a dirty pool;test_flydsl_hgemm.pyonly runs eagerly or with buffers already cached.test_fused_split_k_gemm_whose_counters_are_first_used_inside_a_capturefails before this PR (the graph without the zero fill leaves its tiles unwritten). It is the only test of the_fskcounters' first use inside a capture.test_every_cached_scratch_comes_from_the_private_poolnow also covers the mxscale fused split-K buffers.split_kargument fixes an existing failure (same change as [Test] Pass split_k to get_split_k_buffers in test_graph_alloc #7039).python3and executed nothing.op_tests/triton_tests/gemm/basic/test_gemm_afp8wfp8.py: isolation only.test_fused_split_k_first_use_inside_captureswapped in a fresh dict for the removed_split_counters_by_stream; it now swaps in a freshcapture_scoped_cachearound the same builder. Coverage is unchanged and not redundant: it is the only test of the fused Triton split-K counters' first use inside a capture.Duplicate check
#7039 (test signature fix) and #6712 (AOT semaphore dtype) touch the same area but not the capture-recorded zero fill; #5393/#5430 moved these buffers to the persistent pool but did not address initialization inside a capture.
AI assistance (Claude) was used to investigate and write this change; I reviewed it and ran the tests above.
🤖 Generated with Claude Code