torch.device.__enter__
does not affect get_default_device
despite taking precedence over set_default_device
#148874
Labels
module: python frontend
For issues relating to PyTorch's Python frontend
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
🐛 Describe the bug
Using a
torch.device
as a context manager takes precedence overset_default_device
, but this isn't reflected by the return value ofget_default_device
.I feel like calling
__enter__
on theDeviceContext
created intorch.device
's C++__enter__
implementation and__exit__
in the C++__exit__
implementation might be a solution.pytorch/torch/csrc/Device.cpp
Lines 179 to 197 in 00199ac
pytorch/torch/utils/_device.py
Lines 100 to 104 in 00199ac
pytorch/torch/__init__.py
Lines 1134 to 1147 in 00199ac
cc: @ezyang
Versions
torch==2.6.0
cc @albanD
The text was updated successfully, but these errors were encountered: