1.问题

报错:cuda out of memory

2.解决方法

2.1.batchsize大小

设置batchsize大小能有效地防止cuda溢出错误,但调的太小会影响训练效率和质量。

2.2.pytorch版本问题

我在跑一个字体风格迁移(mcgan)的项目中时,很容易报cuda溢出的错,开始参考网上许多意见,也大多是对batchsize的建议,然而我将batchsize设置成1仍然报这个错,最后在网上发现某个建议是可行的:将pytorch从0.4.1版本升级到1.1.0版本。

2.2.1.对应版本

pytorch:0.4.1 → 1.1.0
cuda:9.0

2.2.2.用清华镜像更新

添加Anaconda的清华镜像和设置搜索时显示通道地址

conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
config --set show_channel_urls yes

进行更新

conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0

2.2.3.运行成功

RuntimeError: CUDA out of memory

参考来源: https://blog.csdn.net/weixin_43155243/article/details/91855612

相关文章: