Repository navigation
PT graph capture: release switches bound shapes off - #1996
Merged
Merged
Conversation
The bound-shape dim state (global batch dim size / capacity, template dim capacities) is process-wide and was only switched off by eval_model at the end of each train epoch. A graphc training which stopped in the middle of an epoch (exception) left it on after finalize, so a later eager engine in the same process saw the dims at their bounds.
albertz
marked this pull request as ready for review
October 14, 2026 16:10
albertz
added a commit
that referenced
this pull request
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GraphCapturedTrainStep.release(called fromEngine.finalize) now switches the bound-shape dim state off (set_bound_shapes_enabled(False)).The bound-shape dim state is process-wide:
the global
batch_dimcapacity / size and thedim_capacitycapacities on the template dims.It is enabled in
GraphCapturedTrainStep.__init__and pertrain_epoch,and was only switched off by
eval_modelat the end of each train epoch.A graphc training which stops in the middle of an epoch (an exception, e.g. inf/nan loss) left it on after
finalize,so a later eager engine in the same process saw the dims at their bounds.
The upcoming
torch_cuda_grapheval option (#1995) re-enables the bound shapes for eval and would leave them on as well.Before, an eager engine after such a graphc engine, padded or packed:
(10 =
batch_size_bound, inDim.get_maskviacopy_masked->torch.where).After
finalize, the dims are now as before the graphc engine.Affects only processes which run several engines, e.g. tests, not a normal RETURNN run.
Test:
test_torch_engine_cuda_graph_finalize_then_eager(CUDA only, so it skips in CI):graphc training stopped by an exception after the capture,
finalize, then an eager packed engine with the same dims.Run on the RZ GPU test node (H100, torch 2.12):
tests/test_torch_engine.pywith the fix: 76 passed.