VSCode Debug

VSCode Debug配置

Python Debug

需要装插件 pylancepython

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: demo",
            "type": "python",
            "request": "launch",
            "program": "demo.py",
            "console": "integratedTerminal",
            "justMyCode": true, # false可以允许调试库代码
            "args": [],
            "cwd": "${workspaceFolder}/demo",
            "env": {
                "task": "panoptic", // 添加临时环境变量
                "CUDA_VISIBLE_DEVICES": "1",
                "PYTHONWARNINGS": "ignore" //能够忽略python warning, 相当于执行python -W
            }
        },
        {
            "name": "Python: Test current file",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "console": "integratedTerminal",
            "justMyCode": false,
            "cwd": "${workspaceFolder}",
            "env": {},
            "args": [
                "${file}",
                "-s",
                "--no-cov", // 添加该行可以对pytest打断点,去掉该行可以统计覆盖率。
            ],

        },
    ]
}

Shell debug

需要装插件 Bash Debug

  1. Select Debug -> Add Configuration to add custom debug configuration (drop-down, path-input, etc...)
  2. Select Debug -> Start Debugging (F5) to start debugging

Cpp debug

pass

远程debug

使用Debugpy

Debugpy——如何使用VSCode调试无法直接执行的Python程序 - 知乎
[VSCode] 使用 debugpy 模組,遠端除錯 Python 程式 | EPH 的程式日記

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 远程调试",
            "type": "python",
            "request": "attach",
            "listen": {
                "host": "0.0.0.0",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}", 
                    "remoteRoot": "."
                }
            ]
        }
    ]
}

在 vscode 设置中搜索Debugpy还可以设置 Just My Code

pytorch分布式训练debug

VS Code中如何调试pytorch分布式训练脚本torch.distributed_钱彬 (Qian Bin)的博客-CSDN博客

分布式训练命令

export CUDA_VISIBLE_DEVICES=0,1
python -m torch.distributed.launch --nproc_per_node=2 tools/train.py --model bisenetv2

该命令相应的debug配置文件

{
    // 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: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "/home/dl/anaconda3/lib/python3.7/site-packages/torch/distributed/launch.py",//可执行文件路径
            "console": "integratedTerminal",
            "args": [
                "--nproc_per_node=1",
                "tools/train.py",
                "--model",
                "bisenetv1",
            ],
            "env": {"CUDA_VISIBLE_DEVICES":"0"},
        }
    ]
}
posted @ 2023-06-27 15:50  攻城狮?  阅读(33)  评论(0编辑  收藏  举报