Repository navigation
Conversation
…eval) New torch_cuda_graph option "eval" (default off): the eval steps run compiled / captured like the train steps, as a second, forward-only program with the train flag off, on the same bounds and static buffers, captured into the memory pool of the train graph. Without it, eval runs the dynamic-shape path as before. Off by default: with it, every eval batch must fit the train bounds.
albertz
force-pushed
the
albert-torch-cuda-graph-eval
branch
from
October 14, 2026 17:17
91c2786 to
c4f4148
Compare
…-cuda-graph-eval # Conflicts: # returnn/torch/util/capture_lock.py # returnn/torch/util/graph_capture.py
# Conflicts: # returnn/torch/util/capture_lock.py
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.
New
torch_cuda_graphoption"eval": True(default off):the eval steps (
Engine.eval_model) run Inductor-compiled and CUDA-graph-captured like the train steps.GraphCapturedTrainStep, train flag off, no backward / optimizer step.It follows the same
compile/captureoptions as the train step.(
batch_size_bound,dim_capacity,packed_total_bound), checked per batch as for train.This is also what JAX
jax_static_shapesand TFtf_static_shapesdo for eval.so the eval graph needs no extra pool memory.
This is safe as the two never run concurrently, and the engine reads each one's outputs right after its replay.
_Programholder,as the eval step can mark a different set of losses than the train step.
Off by default, as an existing setup with dev seqs beyond
dim_capacitywould fail otherwise.Tests (CUDA-only, so they skip in CI), RZ H100 test node:
test_torch_engine_cuda_graph_eval: LM step with BOS / EOS, bf16,mask_padding_seqs,padded and packed with
compile, and padded with eager capture; 2 epochs with a dev eval after each.Dev scores of both epochs match the eager run, incl a loss marked only with the train flag off,
as do the train steps of epoch 2, which replay after the eval graph;
the eval graph shares the pool of the train graph.
eval);with the eval program traced with the train flag on, it fails with
KeyError: 'dev_loss_seq_ce_sq'.-k cuda_graph: 10 passed with torch 2.12 and with torch 2.7 (before the rebase onto PT graph capture: release switches bound shapes off #1996);after the rebase, torch 2.12: 11 passed (incl the PT graph capture: release switches bound shapes off #1996 test);
after the merge of master f640634, torch 2.12: 11 passed.
test_torch_engine.py, torch 2.12: 76 passed.Measured (H100 test node, torch 2.12): conformer encoder 12 x 512, 8 heads, CTC (native op), bf16,
train step compiled + captured (
capture_optimizer,warmup_steps0,mask_padding_seqs), padded, batch 30k frames / max 40 seqs,400 synthetic dev seqs of 300 to 1600 frames.
Columns: wall time of
Engine.eval_model(3 runs, after the first eval which compiles / captures),dev CTC, graph pool reserved after train + first eval, peak allocated during the timed evals.
"eval": TrueThe same probe packed is not usable yet: the packed graphc training itself gets non-finite params after the first step,
on master as well, independent of this PR (separate issue).
Not measured: a production setup.