RuntimeError: CUDA out of memory.

RuntimeError: CUDA out of memory.

Tried to allocate 156.00 MiB (GPU 0; 2.00 GiB total capacity; 499.29 MiB already allocated; 111.65 MiB free; 742.00 MiB reserved in total by PyTorch)

看似超出GPU所占的内存不大,本地的GPU资源应该完全够用的,然而,在pytorch训练过程中,由于梯度下降等神经网络参数的反向传播和正向参数,会占用大量GPU内存,因此还是减小batch吧。有能力的话买一块更大的GPU

解决办法:

  • 缩小batch,即减少单词训练的样本大小
  • 释放显存:torch.cuda.empty_cache()
  • 切换为CPU运行

显存爆了,你得知道它具体用到哪里了?
win10下可以通过nvidia-smi.exe来查看GPU的利用率即使用情况。
nvcc --version可以获得本机GPU的版本。
参考
https://blog.csdn.net/qq_28660035/article/details/80688427

你可能感兴趣的:(机器学习之路)