- Use torch.cuda.empty_cache() to clear memory cache
- Kill process using GPU. (Use nvidia-smi to find out the process’ name). If it’s python use sudo pkill python to kill it.
- You are using large batches. Try reducing the batch size.
对于第一条操作的实现:
Just put it in the file you are running while getting the error to clear cache everytime you run it. Or you can simply open Python terminal and type import torch then torch.cuda.empty_cache().