Repository navigation
Clean up CUDA graph state after warmup failures - #3862
Conversation
Signed-off-by: Pinoeer-kingxi <13022943007@163.com>
|
The In set_capture_start() # L1643 — flag is now True
...
saved_fp8_tensors = save_fp8_tensors(modules, recipe=recipe) # L1675 — can raise
...
for module in modules:
if not isinstance(module, torch.nn.Module):
raise TypeError(f"Graphing for {type(module)} is not supported.") # L1702
wrap_autocast(module) # L1705 — patches block_cls.__call__ class-wide
...
try: # <- this PR's try starts here (~L1729)
graphed_callables = _make_graphed_callables(...)
finally:
...restore...
make_graphed_callables([torch.nn.Linear(8, 8), "not a module"], [(x,)], ...)
# raises TypeError as intended — but is_graph_capturing() is still True,
# and Linear.__call__ is still the autocast wrapper installed at L1705.A second call after that is the exact situation the PR is about ("Retrying capture on the same module can then run with stale hooks or wrappers"), just reached through the argument-validation path instead of a failing forward. Two ways to close it, both small:
Nothing here blocks the warmup-failure case the PR was written for; it is the neighbouring exit path that the same helper already knows how to handle. Two smaller notes:
|
Validate modules before changing capture state, and register cleanup as RNG snapshots, FP8 state and class wrappers are acquired. Remove inherited class overrides on exit. Run the remaining cleanup after a restore error and keep the capture failure visible to callers. Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Graph a TE Linear and its subclass, replay and release both, then calibrate a fresh eager instance. The previously leaked class wrapper suppressed real calibration after successful capture. Move inheritance coverage out of the injected warmup failure test. Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
[Medium impact] No new blocking issue was found beyond the supplied review threads. SummaryThe PR restores temporary CUDA graph state after capture and warmup finish.
Reviews (6) · Last reviewed commit: "Revert "Preserve CUDA graph capture erro..." · Reviewed by Greptile |
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
/te-ci pytorch L0 |
Close the cleanup stack explicitly on a capture failure so a secondary restore error is chained to the original failure. Restore focused tests for rejected inputs, warmup retry, and failure during cleanup. Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
This reverts commit 9c1e9c0. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL
left a comment
There was a problem hiding this comment.
hi, thanks for contributing. I prefer having less tests because we have limited budget for them, so I reverted your commit. Other things LGTM
Description
Capturing a TE Linear layer and its subclass together can leave the subclass with a temporary autocast wrapper after successful capture. A fresh eager instance then ignores its calibration context even after both graphs are reset. A warmup or capture exception can also leave temporary discovery hooks, GC disabled, cleared input gradients, or capture state behind.
Validate modules before changing capture state and register cleanup via
contextlib.ExitStackas setup acquires it. Restore inherited class dispatch and saved capture state on exit, remove discovery hooks when warmup ends, wait on the warmup stream before returning to the caller stream, and guard_none_grad_context_wrapperand_graph_context_wrapperwithtry/finally. If capture and cleanup both raise, the capture error stays primary and the cleanup error is chained to it. Capture still needs serialized host access because it temporarily changes class dispatch. Fatal CUDA errors require a process restart.Review guide
Start at
make_graphed_callables(). Check that inherited calls are resolved before any class is patched and that cleanup removes temporary overrides. Then check warmup hook ownership and the normal capture and eager calibration regression.Type of change
Validation
9c1e9c0, 13 focused CUDA Graph cases pass on one RTX A6000 with PyTorch 2.11.0+cu130 and the PR's Python graph module over TE 2.20.2 native binaries. Successful capture and rejected input regressions fail at base464df75. On7a895dc, the injected double failure exposes the FP8 restore error. This revision preserves the warmup error and its cause, restores capture state, and verifies a successful retry after a warmup failure.4d48616, its eval/checkpoint prerequisites and the graph implementation at22d4727. Downstream RFC · Earlier reproduction and logspython -m pytest -q tests/pytorch/test_cuda_graphs.py \ -k 'capture_preserves_eager_calibration or invalid_module_does_not_leave_capture_state or warmup_failure_restores_capture_state'Checklist