# Spaces using CPU

**URL:** <https://discuss.huggingface.co/t/spaces-using-cpu/39462>\
**Category:** Spaces\
**Created:** [May 11, 2023, 4:30am UTC](https://discuss.huggingface.co/t/spaces-using-cpu/39462 "2023-05-11T04:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anisharitakula](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@anisharitakula](https://discuss.huggingface.co/u/anisharitakula)\
**Post date:** [May 11, 2023, 4:30am UTC](https://discuss.huggingface.co/t/spaces-using-cpu/39462/1 "2023-05-11T04:30:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [May 11, 2023, 4:41am UTC](https://discuss.huggingface.co/t/spaces-using-cpu/39462/2 "2023-05-11T04:41:03Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![anisharitakula](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@anisharitakula](https://discuss.huggingface.co/u/anisharitakula)\
**Post date:** [May 11, 2023, 4:47am UTC](https://discuss.huggingface.co/t/spaces-using-cpu/39462/3 "2023-05-11T04:47:08Z")

</div>

Thanks @radames !
