Repository navigation
Description
Summary
torch.cuda.CUDAGraph.reset() frees the cached cuBLAS/cuBLASLt workspace for the entire capture stream, not just the graph being reset. Graphs captured on one stream share that stream's single cached workspace, so resetting a subset of a stream's graphs frees a block the remaining graphs still reference — the same dangling-pointer class as #266.
Mechanism
In PyTorch 2.14.1, CUDAGraph::reset() calls clearCublasWorkspacesForStream(capture_stream_.stream()) (aten/src/ATen/cuda/CUDAGraph.cpp). The workspace cache is keyed by (handle, stream) and owns the allocation; clearing it releases the block back to the allocator while sibling graphs retain the recorded address in their captured kernel arguments.
Consequences are silent: the freed block is only observed corrupting behavior when it is reallocated and a surviving graph replays — the same presentation family as #266 (device-side fault or silent aliasing, depending on reuse).
Reproduction
On an RTX PRO 6000 (SM120, torch 2.14.1+cu132), capturing two cuBLASLt mm graphs into one graph_pool_handle() on one stream, then resetting only the first:
torch.cuda.memory_snapshot(pool)before reset: 1active_allocatedblock (the shared workspace)- After
reset(graph_a): 0 active blocks — the workspace was freed whilegraph_bis alive and still references the address graph_b.replay()still returns correct output only because the freed block had not yet been reused
The same sequence with a second MemPool allocation in between reuses the freed block, at which point graph_b's workspace contents are corrupted.
Production exposure
Preparation code already shares one stream and one graph pool across capture groups with different lifetimes. For example, ignition/recipes/qwen38_dense/bootstrap.py passes the same stream and pool to the serving capture_forwards call and to study.capture(), while ignition/bench/study.py close() later resets only the study's graphs. If that reset runs while any same-stream graph remains live and is later replayed or exported, its workspace pointer dangles. Whether a current caller actually hits this depends on the ordering of subset resets relative to serialization and replay — severity needs a lifecycle audit, not just the mechanism.
Other reset sites to audit: ignition/preparation/model.py:159, ignition/bench/observations.py:60, ignition/recipes/{glm53,qwen38}/bootstrap.py, ignition/recipes/deepseek41/contextual_selection.py:275,301, ignition/recipes/kimi31/selection_tuning.py:173, ignition/direct/executor.py:62.
Invariant
All graphs captured on one CUDA stream share that stream's workspace and therefore constitute a single lifetime group: callers must reset all of a stream's graphs together, or give separately reset groups separate streams. (PR #331 documents this constraint in capture_forwards and pins the reset behavior in tests/preparation/test_capture_cublas_workspace_cuda.py, but does not change callers.)
Fix direction
Audit the reset sites above; give each independently reset capture group its own stream (e.g. the study capture in bootstrap.py gets a dedicated stream instead of sharing the serving stream). Same-stream groups that always reset together need no change. Per-graph streams are not a viable fix — each stream's workspace is ~32 MiB on these GPUs, which does not scale across the serving catalog.
Discord: myong_acct
Activity
yatesdr commentedon Nov 19, 2026
The mechanism is in torch 2.14.1:
CUDAGraph::reset()callsclearCublasWorkspacesForStream(capture_stream_.stream())(aten/src/ATen/cuda/CUDAGraph.cpp:388). We audited everygraph.reset()inignition/on main 1a53275 for a graph on the same stream that is replayed, captured into, timed or exported after the reset, and found none:ignition/preparation/model.py:159(close)model_core.py:44before:68;host_ranks.py:470before:496-501).ignition/bench/study.py:60StudyModel.closeresets the studies and then closes the model, with no replay between (study.py:81-86); benchmark only.ignition/bench/observations.py:60ignition bench.ignition/recipes/glm53/bootstrap.py:624capture_forwardsat:628on the same stream.ignition/recipes/qwen38/bootstrap.py:732ignition/recipes/deepseek41/contextual_selection.py:275,:301_captureuses a new stream (:209); all graphs are reset together after the race, during tuning, before the serving stream exists.ignition/recipes/kimi31/selection_tuning.py:173finallyduring tuning, before the serving stream exists.ignition/direct/executor.py:62So current callers are not exposed; the constraint you state (graphs on one stream share one lifetime) holds by the order of these calls rather than by anything that enforces it. Not covered:
graph.reset()calls inqualify/,scripts/andtests/, and the internals of b12x'srace_contextsbeyond itsfinallyblock. Nothing here was run on a GPU.Isolate cuBLAS warmup workspaces from CUDA graph capture
mark-yong commentedon Nov 19, 2026
Thank you for the audit — that settles the exposure question: no current caller resets a same-stream subset while siblings stay live, so the constraint holds today by call ordering rather than by enforcement.
The remaining value of this issue is that ordering. Nothing prevents a future caller from capturing a second group on a shared stream and resetting it independently — the failure would be silent (the block only corrupts on reuse). If documenting the invariant in capture_forwards is sufficient, this can close; if the project wants the constraint enforced (for example a dedicated stream per independently reset capture group, or an assertion at reset sites), the audit table is a good starting point for where that would go.
Isolate cuBLAS warmup workspaces from CUDA graph capture (#331)