Skip to content

perf(closed_loop): torch.compile the evaluation forward pass - #7

Merged
HansRobo merged 1 commit into
HansRobo:tier4-mainfrom
tier4:feat/closed-loop-compile-bitexact
Aug 12, 2026
Merged

perf(closed_loop): torch.compile the evaluation forward pass#7
HansRobo merged 1 commit into
HansRobo:tier4-mainfrom
tier4:feat/closed-loop-compile-bitexact

Conversation

@HansRobo

Copy link
Copy Markdown
Owner

Original PR: tier4#342

Compiles the encoder and the DiT for the duration of a closed-loop evaluation. Full-scale evaluation goes from 2,869 s to 1,443 s — 1.99x.

Measured over four sites and both object modes, 64,227 steps, identical in both arms, with eight evaluations running concurrently on one node with 28 cores and one GPU each — the configuration closed-loop validation runs in. Spread over four repeats was 0.6% before and 0.1% after. The baseline ran with the MHA fastpath already disabled; that switch on its own moved wall time within ±0.3%.

Closed-loop metrics shift by the last float32 bit — a compiled model cannot take nn.MultiheadAttention's fused fastpath, and the loop amplifies the difference into its own next input.

What changed

New scenario_generation/inference_compile.py. compiled_for_inference() compiles and restores the model on exit — the training loop hands over its live model, and a leftover wrapper would put _orig_mod. prefixes in the next checkpoint. mark_inference_step() opens one cudagraph step per inference.

For reviewers

The fastpath switch is entered inside compiled_for_inference() rather than left to the caller: it is not in dynamo's guard set, so setting it after compilation leaves the traced graph in place while the flag reads back as changed.

inductor was tried and rejected — a second source of numeric difference on top, and no faster.

Compile the encoder and the DiT with the cudagraphs backend for the duration of a
closed-loop evaluation. Full-scale evaluation runs about 2x faster.

A compiled model cannot take nn.MultiheadAttention's fused fastpath, so it rounds
differently in the last float32 bit. A closed loop feeds that back into its own next
input, so closed-loop metrics shift once.
@HansRobo
HansRobo requested a review from yhisaki August 12, 2026 02:41
@HansRobo
HansRobo merged commit 496efde into HansRobo:tier4-main Aug 12, 2026
HansRobo added a commit that referenced this pull request Aug 27, 2026
Compile the encoder and the DiT with the cudagraphs backend for the duration of a
closed-loop evaluation. Full-scale evaluation runs about 2x faster.

A compiled model cannot take nn.MultiheadAttention's fused fastpath, so it rounds
differently in the last float32 bit. A closed loop feeds that back into its own next
input, so closed-loop metrics shift once.
HansRobo added a commit that referenced this pull request Aug 27, 2026
Compile the encoder and the DiT with the cudagraphs backend for the duration of a
closed-loop evaluation. Full-scale evaluation runs about 2x faster.

A compiled model cannot take nn.MultiheadAttention's fused fastpath, so it rounds
differently in the last float32 bit. A closed loop feeds that back into its own next
input, so closed-loop metrics shift once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants