VSCode Debug
VSCode Debug配置
Python Debug#
需要装插件
pylance
和python
.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
- Select Debug -> Add Configuration to add custom debug configuration (drop-down, path-input, etc...)
- 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"},
}
]
}
作者:攻城狮?
出处:https://www.cnblogs.com/daiSir/p/17509089.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)