Repository navigation
Clean up CUDA graph state after warmup failures - #3862
WEIXILIN0307 wants to merge 4 commits into
Conversation
Signed-off-by: Pinoeer-kingxi <[email protected]>
|
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 <[email protected]>
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 <[email protected]>
[Medium impact] The PR appears safe to merge based on this review. SummaryThe PR restores temporary class calls, saved RNG and FP8 state, and the capture flag after capture exits. It also removes discovery hooks when warmup fails.
Reviews (2) · Last reviewed commit: "Remove verbose cleanup note from make_gr..." · Reviewed by Greptile |
Signed-off-by: Pawel Gadzinski <[email protected]>
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 exception can also leave temporary discovery hooks installed, which affects the next capture attempt.
Validate modules before changing capture state and register cleanup as setup acquires it. Restore inherited class dispatch and saved capture state on exit, and remove the discovery hooks when warmup ends. If cleanup also fails, 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
464df75and passes at181dbd5. Five focused tests pass on one RTX A6000 using the PR's Python graph module with PyTorch 2.11.0+cu130 and TE 2.20.2 native binaries.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 warmup_forward_failure or invalid_module'Checklist