Skip to content

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

Closed
HansRobo wants to merge 1 commit into
tier4-mainfrom
feat/closed-loop-compile-bitexact
Closed

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

Conversation

@HansRobo

@HansRobo HansRobo commented Jul 30, 2026

Copy link
Copy Markdown
Member

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.

@HansRobo HansRobo changed the title feat(closed_loop): torch.compile を opt-in で導入する(eager とビット一致・epoch wall −11.0%) feat(closed_loop): torch.compile を opt-in で導入する(eager とビット一致・フル規模 -51.4%) Jul 30, 2026
@HansRobo
HansRobo marked this pull request as draft July 31, 2026 00:08
@HansRobo
HansRobo force-pushed the feat/closed-loop-compile-bitexact branch from 1067918 to 413c679 Compare July 31, 2026 00:28
@HansRobo HansRobo changed the title feat(closed_loop): torch.compile を opt-in で導入する(eager とビット一致・フル規模 -51.4%) feat(closed_loop): opt-in torch.compile for evaluation, bit-identical to eager Jul 31, 2026
@HansRobo
HansRobo force-pushed the feat/closed-loop-compile-bitexact branch from 413c679 to c54cd24 Compare July 31, 2026 05:35
@HansRobo HansRobo changed the title feat(closed_loop): opt-in torch.compile for evaluation, bit-identical to eager perf(closed_loop): torch.compile the evaluation forward pass Jul 31, 2026
@HansRobo
HansRobo force-pushed the feat/closed-loop-compile-bitexact branch from c54cd24 to 7825f62 Compare July 31, 2026 05:38
@SakodaShintaro

Copy link
Copy Markdown

Is this PR compatible with the following PR?
#314

@HansRobo

Copy link
Copy Markdown
Member Author

@SakodaShintaro
Maybe yes
This PR compiles only the evaluation path, so it takes the branch your if not self.training: guard keeps

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 force-pushed the feat/closed-loop-compile-bitexact branch from 7825f62 to 510317b Compare July 31, 2026 07:17
@HansRobo
HansRobo marked this pull request as ready for review July 31, 2026 07:21
@SakodaShintaro
SakodaShintaro requested a review from yhisaki July 31, 2026 07:36

@MasatoSaeki MasatoSaeki left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this PR works well.

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.

4 participants