前言
之前接触多卡训练少,就算跑也是别人直接搭建起来的框架,一些细节没注意到,等到真的自己撸代码的时候才注意到。
(本文又是一篇挖坑文…
该博文可参考 https://zhuanlan.zhihu.com/p/489011749
有份多卡训练代码可以参考: https://github.com/whwu95/Text4Vis/blob/main/train.py
DNS错误
sudo vim /etc/resolv.conf
加上这两个
nameserver 10.248.98.30
nameserver 8.8.8.8
一些尝试
历史记录
制定某块卡, 在运行的py文件一开始
os.environ["CUDA_VISIBLE_DEVICES"] = "0, 1"
如果是制定cuda:1, 则是
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
记录一些logs或者保存图片一般是主进程来操作
if os.environ.get('RANK', '0') == '0':
print('I am rank 0, the master of the program')
# .... 记录logs, 保存输出图片
vscode 制定gpu调试
制定某一个gpu进行调试, 在"env"项中添加 “CUDA_VISIBLE_DEVICES”: “6”, 就是只用第6号卡的意思(从0开始编号)
然后制定参数在 args中添加
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: train",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"env": {
"CUDA_VISIBLE_DEVICES": "6"
},
"args": [
"--config",
"allweather.yml",
"--image_folder",
"'results/all_weather'"
]
}
]
}
vscode调试distributed
参考 https://blog.csdn.net/weixin_41978699/article/details/122305355
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: GoPro",
"type": "python",
"request": "launch",
"program": "/home/【用户名】/anaconda3/lib/python3.7/site-packages/torch/distributed/launch.py",
"console": "integratedTerminal",
"args": [
"--nproc_per_node=1",
"basicsr/test.py",
"-opt",
"options/test/GoPro/NAFNet-width64.yml",
],
"env": {
"CUDA_VISIBLE_DEVICES": "0"
}
}
]
}
查看服务器代理
这种情况是排除了可以联网之后再进行的,可以先ping以下baidu.com, 若都ping不上那就是连不上网的问题。
输入以下终端,若没有代理的话,什么都不输出,不然就是如下图
env|grep -i proxy
关闭代理
export http_proxy=""
export https_proxy=""
export HTTP_PROXY=""
export HTTPS_PROXY=""
就能正常下包了。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/91e104a4aa7c4aad900ba66635afebf6.png)