让远程调试生效:
VScode Remote 远程开发与调试 - 简书 (jianshu.com)
安装Remote Development插件;
ctrl+shift+p打开设置Remote-SSH-Settings,设置Remote.SSH:Show Login Terminal为true;
安装完插件后左下角会出现一个绿色的图标,点击选择,然后在最上方命令窗口Connect to Host
输入密码
让Step into(F11)生效:
在config文件里,加一条:
"justMyCode": false
{
// 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",
"stopOnEntry": true,
"justMyCode": false
}
]
}
调试tensorboard plugin:
plugin要用python setup.py develop来安装
代码里,子线程、子进程的代码,必须用pdb.set_trace()来设置断点;(提前import pdb)
which tensorboard找到其路径
python -m pdb <tensorboard路径> --logdir=./samples --port=XXXX --bind_all
pdb里面,用“b <文件绝对路径>:<行号>”来设断点
用VSCode来调试tensorboard plugin:
plugin要用python setup.py develop来安装
pip install debugpy
代码里不要使用pdb.set_trace();直接在代码上设断点;
which tensorboard找到其路径
python -m debugpy --listen 5678 /home/gaoteng/anaconda3/envs/pytorch_debug_0412/bin/tensorboard --logdir=./samples --bind_all --port 6013
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: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}",
"connect": {
"host": "localhost",
"port": 5678
}
}
]
}
有3个进程,attach进程id在中间的那个;
如何Debug PyTorch的Python&C++:
如何对Pytorch进行“深入”的DEBUG - Oldpan的个人博客
可以使用python -m pdb my_pytorch_model.py来代替文中提到的pycharm,来启动python程序;
文中提到的launch.json,是在打开pytorch源码目录之后,Debug时,手动填写的;
注意:Attach到该进程时,要等待一两分钟,才能attach完成并继续执行,看上去像死机了一样;
填写的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": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/gaoteng/anaconda3/envs/pytorch_debug_0412/bin/python",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
需要安装C++ Extension Pack,才能支持pdb的debug: