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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module 'torch' has no attribute 'accelerator' #3263

Open
shandatascience opened this issue Jan 25, 2025 · 2 comments
Open

module 'torch' has no attribute 'accelerator' #3263

shandatascience opened this issue Jan 25, 2025 · 2 comments
Labels
bug core Tutorials of any level of difficulty related to the core pytorch functionality intro

Comments

@shandatascience
Copy link

shandatascience commented Jan 25, 2025

Add Link

Link to the tutorial on the website - https://pytorch.org/tutorials/beginner/basics/quickstart_tutorial.html#creating-models

Describe the bug

Below piece of code is returning
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu" print(f"Using {device} device")

When running using google colab throws the below error
`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in <cell line: 0>()
----> 1 device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
2 print(f"Using {device} device")
3
4 # Define model
5 class NeuralNetwork(nn.Module):

/usr/local/lib/python3.11/dist-packages/torch/init.py in getattr(name)
2560 return importlib.import_module(f".{name}", name)
2561
-> 2562 raise AttributeError(f"module '{name}' has no attribute '{name}'")
2563
2564

AttributeError: module 'torch' has no attribute 'accelerator'`

Correct code:
`if torch.cuda.is_available():
device = torch.device("cuda")
device_name = torch.cuda.get_device_name(0)

elif torch.backends.mps.is_available():
device = torch.device("mps")

else:
device = torch.device("cpu")

print(f"Using {device} device")`

Describe your environment

Platform: Google Colab
Cuda: Yes
Pytorch Version: 2.5.1+cu121

cc @subramen @albanD @jbschlosser

@svekars svekars added intro core Tutorials of any level of difficulty related to the core pytorch functionality labels Jan 27, 2025
@albanD
Copy link
Contributor

albanD commented Jan 27, 2025

Hey!
This is expected as this tutorial is for the 2.6 release that will come out a bit later this week !
@svekars I think it's ok to keep this as is?

@svekars
Copy link
Contributor

svekars commented Jan 27, 2025

Sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core Tutorials of any level of difficulty related to the core pytorch functionality intro
Projects
None yet
Development

No branches or pull requests

3 participants