What if CUDA is out of memory?
This article is to share with you what to do when CUDA runs out of memory. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The editor repeated that the boss project found that GPU could not run, and made the following error:
RuntimeError: CUDA out of memory.
It seems that the simplest and roughest way is to reduce batch_size, slow is more than a little bit, but at least can run!
Add: Pytorch GPU has plenty of memory but shows out of memory solution
When testing a pytorch code, it shows that there is not enough memory, but the network framework is obviously very simple, and there is no problem running with CPU, but GPU keeps prompting out of memory.
Find a lot of methods on the Internet are not working, and finally I think it may be the pytorch version of the problem, the original pytorch version is 0.4.1, so I uninstalled this version, and then installed pytorch2.1.0, the program can miraculously run, there will be no more OOM prompts. Although we don't know the exact reason, let's mark it first.
The specific process is as follows:
Uninstall the old version of pytorch:
Conda uninstall pytorch
To install pytorch2.1.0, according to the method on the official website, my CUDA version is 9.0:
Conda install pytorch torchvision cudatoolkit=9.0-c pytorch
The great task has been completed!
Thank you for reading! This is the end of this article on "what to do with CUDA out of memory". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!