Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.get_default_device() gets error while torch.set_default_device() doesn't #126632

Closed
hyperkai opened this issue May 19, 2024 · 4 comments
Closed

Comments

@hyperkai
Copy link

馃悰 Describe the bug

torch.get_default_device() gets error while torch.set_default_device() doesn't as shown below:

import torch

torch.set_default_device(device='cuda:0')
torch.get_default_device() # Error

AttributeError: module 'torch' has no attribute 'get_default_device'

Versions

import torch

torch.__version__ # 2.2.1+cu121
@hyperkai hyperkai changed the title torch.get_default_device() gets error torch.get_default_device() gets error while torch.set_default_device() doesn't May 19, 2024
@spzala
Copy link
Contributor

spzala commented May 19, 2024

@hyperkai hello, with the latest main (torch.__version__ 2.4.0a0+git7899034), I couldn't reproduce the error. I get the output cuda:0 when print(torch.get_default_device()) Please verify and if you are okay, we can close this issue. Thanks!

@hyperkai
Copy link
Author

Thanks @spzala. I upgraded PyTorch from 2.2.1+cu121 to 2.3.0, then torch.get_default_device() works as shown below:

import torch

torch.set_default_device(device='cuda:0')
torch.get_default_device() # device(type='cuda', index=0)

torch.__version__ # 2.3.0

@drisspg
Copy link
Contributor

drisspg commented May 20, 2024

I am going to close this since it looks like it was solved on newer versions of pytorch

@drisspg drisspg closed this as completed May 20, 2024
@spzala
Copy link
Contributor

spzala commented May 20, 2024

Thanks for the quick reply and verifying with the newer version @hyperkai !! @drisspg sounds good to me, thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants