free up the memory allocation cuda pytorch?

  RuntimeError: CUDA out of memory. Tried to allocate 12.00 MiB (GPU 1;
  11.91 GiB total capacity; 10.12 GiB already allocated; 21.75 MiB free; 56.79 MiB cached)


I encountered the preceding error during pytorch training. 
I'm using pytorch on jupyter notebook. Is there a way to free up the gpu memory in jupyter notebook?

I had the same issue sometime back.
There are generally two way I go about.

Decrease the batch size

Sometimes, even when I had decrease the batch size to '1', this issue persists. Then I changed my approach as follows.

Decrease the image size ( or patch size, depending upon your implementation). Decreasing the image size, also gives in space for you to increase your batch size.

But second approach is not recommended because we want the network to learn different features of image in relation to each other. Decreasing the image size decreases the scope of network learning finer details. ( Depending upon on your need you would need to alter it).
