# How to return back to cpu from gpu?

**URL:** <https://discuss.pytorch.org/t/how-to-return-back-to-cpu-from-gpu/36207>\
**Category:** Uncategorized\
**Created:** [February 2, 2019, 5:40am UTC](https://discuss.pytorch.org/t/how-to-return-back-to-cpu-from-gpu/36207 "2019-02-02T05:40:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahsa\_Afsharizade](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mahsa_afsharizade/32/5286_2.png) [@Mahsa\_Afsharizade](https://discuss.pytorch.org/u/Mahsa_Afsharizade)\
**Post date:** [February 2, 2019, 5:40am UTC](https://discuss.pytorch.org/t/how-to-return-back-to-cpu-from-gpu/36207/1 "2019-02-02T05:40:15Z")

</div>

Hi I have a text classifier in pytorch and I want to use GPUs to increase running speed.  
I have used this part of code to check CUDA and use it:

```auto
    if torch.cuda.device_count() > 1:
        print("Let's use", torch.cuda.device_count(), "GPUs!")
        my_rnn_model = nn.DataParallel(my_rnn_model)

    if torch.cuda.is_available():
        my_rnn_model.cuda()

```

Now I want to return back to use cpu (instead of gpu). So I cleared this part of code. But it does’nt work and I receive this error:  
`RuntimeError: cuda runtime error (8) : invalid device function at /opt/conda/conda-bld/pytorch_1503963423183/work/torch/lib/THC/THCTensorCopy.cu:204`  
Would you please guide me how can I return back to cpu running?

---

<div class="post-metadata">

**Author:** ![vabh](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/v/898d66/32.png) [@vabh](https://discuss.pytorch.org/u/vabh)\
**Post date:** [February 2, 2019, 9:39am UTC](https://discuss.pytorch.org/t/how-to-return-back-to-cpu-from-gpu/36207/2 "2019-02-02T09:39:48Z")

</div>

You can have a construct like this:

```auto
if torch.cuda.is_available():
  device = 'cuda'
else:
  device = 'cpu'
model.to(device)

```

To move between CPU and GPU, use the .to(device) function with the appropriate value for device

---

<div class="post-metadata">

**Author:** ![Mahsa\_Afsharizade](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mahsa_afsharizade/32/5286_2.png) [@Mahsa\_Afsharizade](https://discuss.pytorch.org/u/Mahsa_Afsharizade)\
**Post date:** [February 2, 2019, 11:32am UTC](https://discuss.pytorch.org/t/how-to-return-back-to-cpu-from-gpu/36207/4 "2019-02-02T11:32:25Z")

</div>

Thanks. I think I should migrate to Pytorch version 0.4 because my current version is 0.2.0-4.
