Fix FakeTensorDispatchCache.test_cache_default_device default-device cleanup leak#3691
Merged
Merged
Conversation
…fault device in cleanup
Contributor
There was a problem hiding this comment.
Pull request overview
Wraps the body of test_cache_default_device in a try/finally so that torch.set_default_device(None) is always called, preventing a leaked torch function mode stack that caused tearDown assertion failures.
Changes:
- Adds try/finally around default-device manipulations in the test.
- Calls
torch.set_default_device(None)in finally to restore global state.
BBBela
approved these changes
May 18, 2026
Contributor
BBBela
left a comment
There was a problem hiding this comment.
Thanks!
I attach the commit from PyTorch where this test was changed: pytorch/pytorch@c229b73
BartoszKokoszko
approved these changes
May 21, 2026
Contributor
Author
|
/merge -f "CI failures are not related to this PR fixes" |
Contributor
|
✅ PR has been successfully merged by @pponikox (force merge). |
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.
This PR fixes #3625 for
FakeTensorDispatchCache.test_cache_default_device.The test changed the global default device but did not always restored it, causing a leaked torch function mode stack in teardown. After comparing it with upstream version it turned out that there was a missing cleanup guard around default-device switching in the XPU test flow. Thus I addd try/finally block in
test_cache_default_deviceand always calltorch.set_default_device(None)in finally.