Replay autocast state during deferred graph capture - #24
Merged
aryan5v merged 3 commits intoAug 1, 2026
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
GPU evidence
LTX diagnostic job 981 isolated the failure: discovery packaged the second subgraph boundary as bfloat16 while live FastVideo export observed float32. The existing artifact failed closed with input_signature_mismatch and zero candidate calls. This change fixes the generic capture-context omission; it contains no LTX/model-specific branch.
Validation
Greptile Summary
This PR fixes a dtype mismatch during deferred graph capture by snapshotting the ambient autocast state at profiling time and replaying it when
finalize()triggers the actual export or Dynamo trace. Without the fix,mmand similar numerically sensitive operations acquired the ambient dtype at export time (outside the user'storch.autocastblock) rather than the dtype they had during the real forward._AutocastStatedataclass and_observe_autocast_state()to snapshot per-device enabled/dtype/cache state; stores the snapshot in_ShapeVariant.observed_autocaston first shape-key encounter._capture_autocast()context manager (used alongside_capture_forward_contextin_trace) to replay the observed state viaExitStack; both cleanup paths infinalize()now clearobserved_autocastalongside the other live references.aten.mm.defaultnodes.Confidence Score: 5/5
Safe to merge. The autocast-replay logic is tightly scoped, correctly cleaned up in both the success and error paths, and directly validated by a new regression test.
The change is minimal and self-contained: it snapshots thread-local autocast state during the profiling forward and replays it via a properly scoped ExitStack during deferred export. Both cleanup paths in finalize already clear the field. The new test exercises the exact failure scenario described in the PR and confirms the exported IR dtype matches the observed state. No correctness issues were found.
Files Needing Attention: fastvideo/tests/optimization/test_fx_capture.py — the parametrized stable-metadata test is not updated to verify observed_autocast cleanup for symbolic and dynamo modes.
Important Files Changed
Sequence Diagram
sequenceDiagram participant User participant FXCaptureSession participant _ShapeVariant participant _observe_autocast_state participant _capture_autocast User->>FXCaptureSession: "model(inputs) inside torch.autocast(cpu, bf16)" FXCaptureSession->>_observe_autocast_state: "snapshot autocast state" _observe_autocast_state-->>FXCaptureSession: "_AutocastState(cpu enabled bf16, cuda disabled fp16)" FXCaptureSession->>_ShapeVariant: "store observed_autocast" Note over User,FXCaptureSession: User exits autocast context User->>FXCaptureSession: "session.finalize()" FXCaptureSession->>_capture_autocast: "enter with observed_autocast" _capture_autocast->>_capture_autocast: "ExitStack: enter autocast cpu bf16" _capture_autocast->>_capture_autocast: "ExitStack: enter autocast cuda disabled" FXCaptureSession->>FXCaptureSession: "torch.export / Dynamo trace sees bf16" _capture_autocast->>_capture_autocast: "ExitStack exits, autocast restored" FXCaptureSession->>_ShapeVariant: "observed_autocast = None" FXCaptureSession-->>User: "payload with bf16 IR nodes"Reviews (2): Last reviewed commit: "[test]: document canonical IR dtype form..." | Re-trigger Greptile