-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Add torch.accelerator.device_index as accelerator's device switch context #148864
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/148864
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 1 Unrelated FailureAs of commit b43545c with merge base fc6e37c ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@pytorchbot rebase |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Successfully rebased |
@pytorchbot rebase |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Successfully rebased |
@albanD May I know if this PR is reasonable for you. |
ghstack-source-id: d07fc95 Pull Request resolved: pytorch/pytorch#148864
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.
Thanks!
Starting merge as part of PR stack under #148880 |
Rebased |
Starting merge as part of PR stack under #148880 |
1 similar comment
Starting merge as part of PR stack under #148880 |
…device for generic device context manager (#148880) Pull Request resolved: #148880 Approved by: https://github.com/EikanWang, https://github.com/albanD ghstack dependencies: #148864
# Motivation Align #152474, fix the typo on UT for XPU introduced by #148864 Pull Request resolved: #152812 Approved by: https://github.com/EikanWang, https://github.com/Skylion007
Stack from ghstack (oldest at bottom):
Motivation
We propose adding support for the Python with statement on
torch.accelerator.device_index
to enable device switching functionality. This enhancement would simplify writing device-agnostic code and provide benefits across all accelerators. Its device-specific counterparts includetorch.cuda.device
andtorch.cuda._DeviceGuard
.Design Philosophy
It accepts either an
Int
orNone
as input. WhenNone
is passed, no device switch is performed. SupportingNone
is important for compatibility, as it's possible to encounterNone
values fromtorch.device.index
.Therefore, with this PR, we can do like this
cc @albanD @EikanWang