Spaces using CPU

Hi All,

I am new here. I have built a model using pytorch on a GPU. I want to create a space which leverages the model on a CPU. Is that possible? The reason I ask is because when I load the model on my computer(without GPU), the predict function throws an error

AssertionError: Torch not compiled with CUDA enabled

Appreciate any help.

hi @anisharitakula

you can use this statement to set the available device, and use torch to load to that specific define, that will make your model work on both environments CPU/GPU

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
r = torch.randn(2).to(device)

Thanks @radames !

1 Like