Repository navigation
[dynamo] Preserve Inductor deterministic config during tracing - #198572
AnkitNakhawa wants to merge 1 commit into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198572
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit a64cc92 with merge base 3fd0a85 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@claude review these changes |
|
Claude finished @jansel's task in 57s —— View job The fix is correct and I'd approve it; my only request is a small cleanup in the new test. PR Review: #198572SummaryDynamo's Testing
RecommendationApprove, after the small test cleanup above. The one-line core change is correct and consistent with the existing handler for traced I did not run the tests locally; this review is based on reading the code. |
|
I also checked the Applying this PR's restoration change at With
This checks configuration propagation with a small CPU function only. I did not test GPU execution or loading a saved AOT artifact. Minimal reproduction for the AOT pathRun in a fresh process: TORCHINDUCTOR_DETERMINISTIC=1 python repro.pyimport torch
import torch._inductor.config as config
import torch._inductor.graph as graph
seen = []
original_init = graph.GraphLowering.__init__
def record_init(self, *args, **kwargs):
seen.append(config.deterministic)
original_init(self, *args, **kwargs)
graph.GraphLowering.__init__ = record_init
def f(x):
return (
x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + 1e-6)
).sum()
torch.compile(f, fullgraph=True).aot_compile(
((torch.randn(8, 64),), {})
)
print(seen, config.deterministic)Before the change: With the change applied: |
|
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
2cdc76a to
a64cc92
Compare
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ch#198572) Fixes pytorch#198563 Dynamo restores the deterministic-algorithms global state after tracing by calling the public `torch.use_deterministic_algorithms` API. That API also updates `torch._inductor.config.deterministic`, so the cleanup unintentionally overwrites an independently configured Inductor value, including `TORCHINDUCTOR_DETERMINISTIC=1`. Restore the C++ global flag directly during Dynamo cleanup. This retains the saved `mode` and `warn_only` state without changing the separate Inductor config. The regression test uses the eager backend and CPU tensors, so it does not require CUDA. Test plan: - `python test/dynamo/test_misc.py MiscTests.test_deterministic_algorithms_mutated MiscTests.test_inductor_deterministic_preserved MiscTests.test_deterministic_algorithms_warn_only_mutated MiscTests.test_deterministic_algorithms_warn_only_compile_time_value` - repository RUFF and PYFMT adapters on the changed files - exact `TORCHINDUCTOR_DETERMINISTIC=1` reproduction against the 2026-09-24 CPU nightly Pull Request resolved: pytorch#198572 Approved by: https://github.com/williamwen42
…204320) **Context** #198572 already changed Dynamo's `preserve_global_state` to restore the deterministic-algorithms state with `torch._C._set_deterministic_algorithms` instead of `torch.use_deterministic_algorithms`, so deterministic mode set through Inductor alone (`TORCHINDUCTOR_DETERMINISTIC=1` / `config.deterministic = True`) is no longer turned off after the first compiled frame. This PR builds on that. **Change** - `preserve_global_state` also saves `torch._inductor.config.deterministic` before compiling a frame and restores it afterwards, so a compile can no longer leave Inductor's deterministic flag changed for later frames (e.g. through a `torch.use_deterministic_algorithms` call made during compilation). - `torch.set_deterministic_debug_mode` now goes through `torch.use_deterministic_algorithms`, so it sets Inductor's deterministic flag the same way `use_deterministic_algorithms` does (#165950). Behavior change: `"warn"`/`"error"` (1/2) turn on Inductor's deterministic mode, which skips on-device benchmarking and can be slower, and `"default"` (0) turns it off, including when it was set with `TORCHINDUCTOR_DETERMINISTIC=1`. **Test plan** - `test_compile_does_not_leak_deterministic_mode` (`test/inductor/test_deterministic.py`): a change to Inductor's flag during compilation does not persist past the frame. - `test_deterministic_flag_survives_compile` and the Dynamo tests: deterministic mode set through Inductor alone stays on across frames and in the backward compile. - `test_set_deterministic_debug_mode_sets_inductor_flag`: each debug mode sets Inductor's flag to match. - `test/dynamo/test_misc.py -k "deterministic or global_state"`. This change was authored with an AI assistant (Claude Code), with the change and tests reviewed in the session. Pull Request resolved: #204320 Approved by: https://github.com/drisspg
Fixes #198563
Dynamo restores the deterministic-algorithms global state after tracing by calling the public
torch.use_deterministic_algorithmsAPI. That API also updatestorch._inductor.config.deterministic, so the cleanup unintentionally overwrites an independently configured Inductor value, includingTORCHINDUCTOR_DETERMINISTIC=1.Restore the C++ global flag directly during Dynamo cleanup. This retains the saved
modeandwarn_onlystate without changing the separate Inductor config.The regression test uses the eager backend and CPU tensors, so it does not require CUDA.
Test plan:
python test/dynamo/test_misc.py MiscTests.test_deterministic_algorithms_mutated MiscTests.test_inductor_deterministic_preserved MiscTests.test_deterministic_algorithms_warn_only_mutated MiscTests.test_deterministic_algorithms_warn_only_compile_time_valueTORCHINDUCTOR_DETERMINISTIC=1reproduction against the 2026-09-24 CPU nightlycc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98