关于使用vscode调试pytorch模型的DDP训练的launch.json文件修改
原始launch.json配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
修改为:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
//选取自己anaconda虚拟环境或者base环境的launch.py
"program": "/home/ubuntu/anaconda3/envs/python39/lib/python3.9/site-packages/torch/distributed/launch.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
//使用几张gpu
"--nproc_per_node=2",
//需要启动文件,在train.py中使用了argparse中默认超参数,如果需要修改则同样在args中调用,train.py之后
"train.py"
],
"env": {"CUDA_VISIBLE_DEVICES":"0,1"}
}
]
}