# Unable to clear CUDA cache

**URL:** <https://discuss.pytorch.org/t/unable-to-clear-cuda-cache/69990>\
**Category:** nlp\
**Created:** [February 17, 2020, 2:56am UTC](https://discuss.pytorch.org/t/unable-to-clear-cuda-cache/69990 "2020-02-17T02:56:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vr25](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/vr25/32/18944_2.png) [@vr25](https://discuss.pytorch.org/u/vr25)\
**Post date:** [February 17, 2020, 2:56am UTC](https://discuss.pytorch.org/t/unable-to-clear-cuda-cache/69990/1 "2020-02-17T02:56:26Z")

</div>

Hi,

I am trying to clear the CUDA cache using torch.cuda.empty\_cache() but it is unable to clear it.

Following are the code and the error:

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/f/b/fb4a1e78bd74536ccadc3f163dc3f0784ad476c6.png)

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/e/c/ec4f6e6c83e8a33d59db67fa096e1185863faf96.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [February 17, 2020, 5:22am UTC](https://discuss.pytorch.org/t/unable-to-clear-cuda-cache/69990/2 "2020-02-17T05:22:41Z")

</div>

`empty_cache` will only release the unused and cached memory.  
If the parameters and activations need more memory, you will run into an OOM error nevertheless.  
You could try to lower the batch size or alternatively use [`torch.utils.checkpoint`](https://pytorch.org/docs/stable/checkpoint.html) to trade compute for memory.
