【E-02】内存不足RuntimeError: CUDA out of memory. Tried to allocate 16.00 MiB (GPU 0; 2.00 GiB total capacity; 1.34 GiB already allocated; 14.76 MiB free; 1.38 GiB reserved in total by PyTorch)

原因一:找到错误点,增加以下语句:

with torch.no_grad():

    outputs = Net_(inputs) ---错误代码的位置。

   

原因二:GPU没有选对

os.environ["CUDA_VISIBLE_DEVICES"] = "0, 2, 3"

查看性能,发现NVIDIA的只有GPU1,所以改成如下:

os.environ["CUDA_VISIBLE_DEVICES"] = "0"

若是不能在GPU上跑,直接改到CPU上跑,修改如下:

os.environ["CUDA_VISIBLE_DEVICES"] = "-1"

 

不过,这种问题,还是GPU内存不足引起的。应该购买或租用高性能显卡,减少时间的浪费。

posted @ 2020-07-26 20:36  忆凡人生  阅读(41393)  评论(0编辑  收藏  举报