# About torch.cuda.empty\_cache()

**URL:** <https://discuss.pytorch.org/t/about-torch-cuda-empty-cache/34232>\
**Category:** Uncategorized\
**Created:** [January 9, 2019, 9:16am UTC](https://discuss.pytorch.org/t/about-torch-cuda-empty-cache/34232 "2019-01-09T09:16:25Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![michaelklachko](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/michaelklachko/32/541_2.png) [@michaelklachko](https://discuss.pytorch.org/u/michaelklachko)\
**Post date:** [June 28, 2020, 9:12am UTC](https://discuss.pytorch.org/t/about-torch-cuda-empty-cache/34232/12 "2020-06-28T09:12:32Z")

</div>

In my case, I perform a lot of computation outside of the graph (under `torch.no_grad` context), where many large tensors are being computed or randomly generated at every forward pass.

I just inserted four `torch.cuda.empty_cache()` calls throughout my ops at every forward pass, which resulted in ~20% slowdown, but I’m able to increase my batch size from 9 to 14, which is a good trade-off for me. So far I haven’t run into any issues, and the model (custom VGG-like network) trains fine.

I empty the cache immediately after I delete a tensor with `del` command.

Could you suggest any additional measures or alternatives to save memory?

---

_[View the full topic](https://discuss.pytorch.org/t/about-torch-cuda-empty-cache/34232)._
