Skip to content

Fix FakeTensorDispatchCache.test_cache_default_device default-device cleanup leak#3691

Merged
chuanqi129 merged 6 commits into
intel:mainfrom
pponikox:dev/pponikox/PYTORCHDGQ-8982
May 25, 2026
Merged

Fix FakeTensorDispatchCache.test_cache_default_device default-device cleanup leak#3691
chuanqi129 merged 6 commits into
intel:mainfrom
pponikox:dev/pponikox/PYTORCHDGQ-8982

Conversation

@pponikox
Copy link
Copy Markdown
Contributor

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_device and always call torch.set_default_device(None) in finally.

@pponikox pponikox self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 13:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@BBBela BBBela left a comment

Choose a reason for hiding this comment

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

Thanks!
I attach the commit from PyTorch where this test was changed: pytorch/pytorch@c229b73

Copilot AI review requested due to automatic review settings May 19, 2026 08:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@pponikox pponikox added disable_e2e Disable all e2e test jobs for the PR disable_distributed Disable distributed UT test jobs for the PR labels May 22, 2026
@pponikox
Copy link
Copy Markdown
Contributor Author

/merge -f "CI failures are not related to this PR fixes"

@chuanqi129 chuanqi129 merged commit 0f1f88d into intel:main May 25, 2026
22 of 23 checks passed
@chuanqi129
Copy link
Copy Markdown
Contributor

✅ PR has been successfully merged by @pponikox (force merge).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disable_distributed Disable distributed UT test jobs for the PR disable_e2e Disable all e2e test jobs for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New failing test case FakeTensorDispatchCache,test_cache_default_device

5 participants