-
Notifications
You must be signed in to change notification settings - Fork 24.7k
update get_default_device to also respect torch.device ctx manager #148621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/148621
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 2 PendingAs of commit c3ccbc2 with merge base 5fbaa04 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Ping @albanD |
if hasattr(_GLOBAL_DEVICE_CONTEXT, "device_context"): | ||
device = _GLOBAL_DEVICE_CONTEXT.device_context.device | ||
from torch.overrides import _get_current_function_mode_stack | ||
from torch.utils._device import DeviceContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused now what's the difference between torch._GLOBAL_DEVICE_CONTEXT and torch.utils._device.CURRENT_DEVICE ?
And if we change all access to respect the later, should we just delete the first one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, I think _GLOBAL_DEVICE_CONTEXT
is required to correctly implement the set_default_device
with DeviceContext
(it holds the DeviceContext object on which enter and exit is called)
Lines 1205 to 1218 in ece1658
global _GLOBAL_DEVICE_CONTEXT | |
if hasattr(_GLOBAL_DEVICE_CONTEXT, "device_context"): | |
device_context = _GLOBAL_DEVICE_CONTEXT.device_context | |
if device_context is not None: | |
device_context.__exit__(None, None, None) | |
if device is None: | |
device_context = None | |
else: | |
from torch.utils._device import DeviceContext | |
device_context = DeviceContext(device) | |
device_context.__enter__() | |
_GLOBAL_DEVICE_CONTEXT.device_context = device_context |
Actually looking at _device.py, I am not sure if CURRENT_DEVICE
is needed for implementation.
But I think this (or above) refactoring can be addressed in a separate PR, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gentle ping :)
Gentle ping :) Running into this bug as well. |
@albanD gentle ping :) |
@pytorchbot merge |
Merge failedReason: Not merging any PRs at the moment because there is a merge blocking https://github.com/pytorch/pytorch/labels/ci:%20sev issue open at: Details for Dev Infra teamRaised by workflow job |
@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 |
Merge failedReason: 6 jobs have failed, first few of them are: linux-binary-manywheel / manywheel-py3_9-cuda11_8-build / build, linux-binary-manywheel / manywheel-py3_9-cuda12_4-build / build, linux-binary-manywheel / manywheel-py3_9-cuda12_6-build / build, linux-binary-manywheel / manywheel-py3_9-cuda12_8-build / build, linux-binary-libtorch-cxx11-abi / libtorch-cpu-shared-with-deps-cxx11-abi-build / build Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge -r |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Successfully rebased |
001abe1
to
fcf1b45
Compare
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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
@pytorchbot merge -r |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
@pytorchbot merge -r |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Successfully rebased |
fcf1b45
to
c3ccbc2
Compare
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 |
this PR did not make it into 2.7.1, right? |
…ytorch#148621) Fixes pytorch#131328 Pull Request resolved: pytorch#148621 Approved by: https://github.com/ezyang
…ytorch#148621) Fixes pytorch#131328 Pull Request resolved: pytorch#148621 Approved by: https://github.com/ezyang
Fixes #131328