Hi all, before adding my model to the gpu I added the following code:
def empty_cached():
  gc.collect()
  torch.cuda.empty_cache()

The idea buying that it will clear out to GPU of the previous model I was playing with.
Here’s a scenario, I start training with a resnet18 and after a few epochs I notice the results are not that good so I interrupt training, change the model, run the function above.
When I do it that way I get a:
RuntimeError: CUDA out of memory. Tried to allocate 24.00 MiB (GPU 0; 11.17 GiB total capacity; 10.56 GiB already allocated; 9.81 MiB free; 10.85 GiB reserved in total by PyTorch)

However, if I interupt training, restart the kernel and run the same model that wouldn’t work before, it now works.
It seems like nothing works as good as restarting the kernel. What would come the closest to it?