Kaggle/docker-python

AttributeError: module 'torch.cuda' has no attribute 'is_avaliable'

Aisuko opened this issue ยท 3 comments

๐Ÿ› Bug

# cuda for Nvidia, mps stands for Metal Performance Shaders on Apple
torch_device="cuda" if torch.cuda.is_avaliable() else "cpu"
vae.to(torch_device)
text_encoder.to(torch_device)
unet.to(torch_device)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 2
      1 # cuda for Nvidia, mps stands for Metal Performance Shaders on Apple
----> 2 torch_device="cuda" if torch.cuda.is_avaliable() else "cpu"
      3 vae.to(torch_device)
      4 text_encoder.to(torch_device)

AttributeError: module 'torch.cuda' has no attribute 'is_avaliable'

To Reproduce

Running code in this cell below
https://www.kaggle.com/code/aisuko/constructing-diffusers-sd-pipeline?scriptVersionId=134889144&cellId=8

Expected behavior

Additional context

This worked for me:

import torch
if torch.cuda.is_available():
    torch_device="cuda"
else:
    torch_device="cpu"
print(torch_device)

So I'm guessing its a syntax issue with using the inlined if statement.

There is a typo in is_avaliable

Thanks for your quick reply, I checked the environment.

import os, platform

torch_device = 'cpu'

if 'kaggle' in os.environ.get('KAGGLE_URL_BASE','localhost'):
    torch_device = 'cuda'
else:
    torch_device = 'mps' if platform.system() == 'Darwin' else 'cpu'