当前位置: 首页 > article >正文

vscode里几种程序调试配置

标题调试python嵌入的c++代码,例如

import torch
from torch.utils.cpp_extension import loadtest_load = load(name='test_load', sources=['test.cpp'],extra_cflags=['-O0', '-g'],#extra_cflags=['-O1'],verbose=True,
)
a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
result = test_load.add(a, b)
print(result)  # Should print tensor([5, 7, 9])
#include <torch/extension.h>// 定义一个简单的加法函数
at::Tensor add(at::Tensor a, at::Tensor b) {int size = a.size(0);int dim = a.dim();printf("size: %d, dim: %d\n", size, dim);return a + b;
}PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {m.def("add", &add, "Add two tensors");
}

launch.json配置

{"version": "0.2.0","configurations": [																																																																																																																																																																																																																																																																																																																																																																																																																		{"name": "(gdb) Launch test","type": "cppdbg","request": "launch","program": "/root/miniconda3/bin/python","args": ["test.py"],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": 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 test","type": "cppdbg","request": "launch","program": "/root/miniconda3/bin/python","console": "integratedTerminal","args": ["test.py"],"cwd": "${workspaceFolder}","MIMode": "gdb","env": {"PATH": "/root/miniconda3/bin/:$PATH","LD_LIBRARY_PATH": "$PWD:extensions/aec/lib/:$LD_LIBRARY_PATH","CUDA_VISIBLE_DEVICES": "0,1,2,3,4,5,6,7"}}]
}

标题调试torchrun启动代码

bash启动脚本是这样

#!/bin/bash
. /root/miniconda3/etc/profile.d/conda.sh
conda activate /root/miniconda3
export LD_LIBRARY_PATH=$PWD:extensions/lib/:/myso:$LD_LIBRARY_PATH
export PATH=$PWD:extensions/lib/:$PATH
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 --master_port=25642 debug.py

调试配置需要先配置tasks.json激活环境,然后配置launch.json
launch.json

{"version": "0.2.0","configurations": [{"name": "Python: noise_gen_debug","type": "python","request": "launch","program": "/root/miniconda3/bin/torchrun","args": ["--nproc_per_node=1","--master_port=25642","debug.py"],"console": "integratedTerminal","env": {"LD_LIBRARY_PATH": "${workspaceFolder}:${workspaceFolder}/extensions/lib/:/root/myso:${env:LD_LIBRARY_PATH}","CUDA_VISIBLE_DEVICES": "0"}}]
}

tasks.json 里先激活虚拟环境

{"version": "2.0.0","tasks": [{"label": "setup-conda","type": "shell","command": "source /root/miniconda3/etc/profile.d/conda.sh && conda activate /root/miniconda3"}]
}

标题调试python启动ddp代码

#!/bin/bash
export PATH=/root/miniconda3/bin/:$PATHexport LD_LIBRARY_PATH=$PWD/extensions/lib/:$LD_LIBRARY_PATH
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
python xspeech/bin/ddp_train_debug.py --train_conf=conf/test.yaml --data_conf=conf/test.cfg --gpus=1
{// 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: Debug ddp_train_test.py","type": "python","request": "launch","program": "${workspaceFolder}/xspeech/bin/ddp_train_test.py","console": "integratedTerminal","python": "/root/miniconda3/bin/python","args": ["--train_conf=conf/test.yaml", "--data_conf=conf/test.cfg", "--gpus=1"],"justMyCode": false,"env": {"PATH": "/root/miniconda3/bin/:$PATH","LD_LIBRARY_PATH": "$PWD:extensions/lib/:$LD_LIBRARY_PATH","CUDA_VISIBLE_DEVICES": "0,1,2,3,4,5,6,7"}}]
}

标题调试已经编译好的c++程序

{"version": "0.2.0","configurations": [{"name": "(gdb) Launch","type": "cppdbg","request": "launch","program": "${workspaceFolder}/build/test-debug","args": [ "model.pkg", "test.conf", "data/test.lst", "10", "2", "1"],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}

settings.json

{"files.associations": {"thread": "cpp"}
}

调试wekws代码:
启动脚本

  torchrun --standalone --nnodes=1 --nproc_per_node=$num_gpus \wekws/bin/train.py --gpus $gpus \--config $config \--train_data data/train/data.list \--cv_data data/dev/data.list \--model_dir $dir \--num_workers 8 \--num_keywords $num_keywords \--min_duration 50 \--seed 666 \--dict ./dict \$cmvn_opts \${checkpoint:+--checkpoint $checkpoint}
fi

在启动脚本之前,实际上还会运行一下环境变量, . path.sh, 但这部分变量配置到launch.json里。

export PATH=$PWD:$PATH# NOTE(kan-bayashi): Use UTF-8 in Python to avoid UnicodeDecodeError when LC_ALL=C
export PYTHONIOENCODING=UTF-8
export PYTHONPATH=../../../:$PYTHONPATH

vscode打开wekws/examples/hi_xiaowen/s0目录
launch.json配置

{"version": "0.2.0","configurations": [{"name": "Python: train.py","type": "python","request": "launch","program": "/root/envs/wekws/bin/torchrun","args": ["--nproc_per_node=1","--master_port=25000","--standalone","--nnodes=1","wekws/bin/train.py","--gpus=0","--config=conf/ds_tcn.yaml","--train_data=data/train/data.list","--cv_data=data/dev/data.list","--model_dir=exp_test","--num_workers=1","--num_keywords=2","--min_duration=50","--seed=666","--dict=dict"],"console": "integratedTerminal","env": {"LD_LIBRARY_PATH": "${workspaceFolder}:${workspaceFolder}/extensions/aec/lib/:${env:LD_LIBRARY_PATH}","CUDA_VISIBLE_DEVICES": "0","PYTHONIOENCODING": "UTF-8","PYTHONPATH": "${workspaceFolder}/../../../:${env:PYTHONPATH}","PATH": "${workspaceFolder}:$PATH"}}]
}

tasks.json配置

{"version": "2.0.0","tasks": [{"label": "setup-conda","type": "shell","command": "source /root/miniconda3/etc/profile.d/conda.sh && conda activate /root/envs/wekws"}]
}
http://www.lryc.cn/news/2387716.html

相关文章:

  • RAGFlow源码安装操作过程
  • Unity使用XCharts动态配置数据——折线图(LineChart)
  • 【HITCSAPP 哈工大计算机系统期末大作业】 程序人生-Hello’s P2P
  • DAY9 热力图和箱线图的绘制
  • 如何查看 GitLab 内置的 PostgreSQL 版本?
  • VR 技术与病毒分离鉴定:一场奇妙的邂逅​
  • 解释一下NGINX的反向代理和正向代理的区别?
  • 数学笔记一:标量、向量和矩阵基本概念辨析
  • vue3获取两个日期之间的所有时间
  • Python 实现简易版的文件管理(结合网络编程)
  • 元组可以比较大小吗?一次返回多个值?编程语言的元组?声明变量一定需要指定类型吗?
  • PXC集群
  • 线程安全问题的成因
  • 零基础远程连接课题组Linux服务器,安装anaconda,配置python环境(换源),在服务器上运行python代码【3/3 适合小白,步骤详细!!!】
  • 字节跳动BAGEL-7B-MoT模型开源:多模态AI技术的新范式与行业涟漪
  • Ubuntu静态IP配置信息查看命令
  • unity实现wasd键控制汽车漫游
  • Python优雅执行SSH命令:10种方法+虚拟环境深度实践
  • Linux TCP与Socket与IO多路复用(Epoll)
  • LINUX安装运行jeelowcode后端项目(命令行)
  • 嵌入式高级工程师面试全解:从 malloc 到 kernel panic 的系统知识梳理
  • 机器学习第二十七讲:Kaggle → 参加机器学习界的奥林匹克
  • C++(初阶)(二十)——封装实现set和map
  • 【MySQL】06.内置函数
  • 企业微信内部网页开发流程笔记
  • 智慧在线判题OJ系统项目总体,包含功能开发思路,内部中间件,已经部分知识点
  • 【MySQL】2-MySQL索引P2-执行计划
  • 云电脑显卡性能终极对决:ToDesk云电脑/顺网云/海马云,谁才是4K游戏之王?
  • 11 接口自动化-框架封装之统一请求封装和接口关联封装
  • influxdb时序数据库