vscode调试launch.json常用格式
创始人
2025-01-16 13:04:14
0

目录

1、简单的模版

2、简单的案例 

  2.1、python 执行.py 文件

  2.2、调式多个文件

  2.3、torchrun、deepspeed 调试

  2.4、accelerate launch (模块)

3、完整的案例


1、简单的模版

定义一个简单的模版如下:

{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         {             "name": "Python 调试一",         // 可自定义             "type": "debugpy",             "request": "launch",             "program": "运行脚本的程序",  // 使用.py 脚本路径(相对路径)、which torchrun、which deepspeed等命令查看位置             "console": "integratedTerminal",             "justMyCode": false,       // 调试允许进入他人的代码             "env": {                 "PYTHONPATH": "${workspaceRoot}" // 设置vscode家路径为项目根路径, 搜索包时优先从该目录进行,防止发生import包错误             },             "args": [               // 参数,每个参数的参数值无论是否是数字都需用引号                 "--参数1","值1",                   "--model_name_or_path","facebook/opt-350m",                 "--per_device_train_batch_size", "4",                 "--per_device_eval_batch_size", "4"             ]         }     ] } 

2、简单的案例 

  2.1、python 执行.py 文件

bash 命令

# 加入当前目录的绝对路径 PYTHONPATH=$PWD export PYTHONPATH echo "当前bash执行目录: $PWD, 已经将PYTHONPATH设置为: $PYTHONPATH"  batch_dir=data/gpt3_generations_ceshi/  # 命令行python 进行执行 python self_instruct/bootstrap_instructions.py \     --batch_dir ${batch_dir} \     --num_instructions_to_generate 5  

命令行 python 进行执行脚本,构建launch.json 思路

  • bash 为python执行脚本.py,直接修改"program"为.py脚本相对路径
  • 其他参数照抄
{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         {             "name": "Python 调试",             "type": "debugpy",             "request": "launch",             "program": "self_instruct/bootstrap_instructions.py",  // .py脚本文件相对路径位置             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}" // 设置vscode项目根路径,搜索包时优先从该目录进行,防止发生import包错误             },             "args": [                 "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方线上数据集为自己的路径                 "--num_instructions_to_generate","5"                 ]         }     ] } 

  2.2、调式多个文件

与调试单个文件同理,只是重复

{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         // 第一个文件         {             "name": "Python 调试 bootstrap_instructions.py",             "type": "debugpy",             "request": "launch",             "program": "self_instruct/bootstrap_instructions.py",  // .py脚本文件相对路径位置             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}" // 设置vscode项目根路径,搜索包时优先从该目录进行,防止发生import包错误             },             "args": [                 "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方线上数据集为自己的路径                 "--num_instructions_to_generate","5"             ]         },         // 第二个文件         {             "name": "Python 调试 identify_clf_or_not.py",             "type": "debugpy",             "request": "launch",             "program": "self_instruct/identify_clf_or_not.py",  // .py脚本文件相对路径位置             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}" // 设置vscode项目根路径,搜索包时优先从该目录进行,防止发生import包错误             },             "args": [                 "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方线上数据集为自己的路径                 "--num_instructions_to_generate","5"             ]         }     ] } 

  2.3、torchrun、deepspeed 调试

bash 命令

# 加入当前目录的绝对路径 PYTHONPATH=$PWD export PYTHONPATH echo "当前bash执行目录: $PWD, 已经将PYTHONPATH设置为: $PYTHONPATH"  batch_dir=data/gpt3_generations_ceshi/  # 命令行python 进行执行 deepspeed --num_gpus 1 self_instruct/bootstrap_instructions.py \     --batch_dir ${batch_dir} \     --num_instructions_to_generate 5

命令行 deepspeed/torchrun 进行执行脚本,构建launch.json 思路

  • 构建launch.json脚本时需要找到“deepspeed”命令的路径,bash命令行:which deepspeed,直接修改"program"为该路径。
  • self_instruct/bootstrap_instructions.py 是执行的脚本的相对路径,不在主目录中,因此我们需要加入 "PYTHONPATH": "${workspaceRoot}" 指定项目目录到环境变量中,以防代码运行时出现 import 错误
{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         {             "name": "Python 调试一阶段LORA",             "type": "debugpy",             "request": "launch",             "program": "/opt/conda/envs/dsc/bin/deepspeed",  // which deepspeed 查看位置             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}" // 设置vscode项目根路径,搜索包时优先从该目录进行,防止发生import包错误             },             "args": [                 "--num_gpus", "1",                  "self_instruct/bootstrap_instructions.py",   // 给定脚本地址(相对路径)                 "--batch_dir","data/gpt3_generations_ceshi",                   "--num_instructions_to_generate","5"             ]         }     ] } 

  2.4、accelerate launch (模块)

# bash accelerate launch --config_file "examples/sft/configs/deepspeed_config_z3_qlora.yaml"  examples/sft/train.py \     --seed 100 \     --model_name_or_path "/workspace/Llama-2-7b-chat-hf" \     --dataset_name "smangrul/ultrachat-10k-chatml" \     --chat_template_format "chatml" \     --add_special_tokens False \     --append_concat_token False \     --splits "train,test" \     2>&1 | tee -a examples/sft/qlora_ds_zero3_log.out  

launch.json 

{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         {             "name": "Python ds_z3_qlora_multigpu 微调",             "type": "debugpy",             "request": "launch",             "module": "accelerate.commands.launch",          //调试accelerate launch             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}"             },             "args": [                 "--config_file", "examples/sft/configs/deepspeed_config_z3_qlora.yaml",                 "examples/sft/train.py",                 "--seed", "100",                 "--model_name_or_path", "/workspace/Llama-2-7b-chat-hf",                 "--dataset_name", "smangrul/ultrachat-10k-chatml",                 "--chat_template_format", "chatml",                 "--add_special_tokens", "False",                 "--append_concat_token", "False",                 "--splits", "train,test"               ]         }     ] } 

3、完整的案例

{     // 使用 IntelliSense 了解相关属性。      // 悬停以查看现有属性的描述。     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387     "version": "0.2.0",     "configurations": [         // py 脚本         {             "name": "Python lora 微调",             "type": "debugpy",             "request": "launch",             "program": "finetune_demo/finetune_hf.py",             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}"             },             "args": [                 "/workspace/AdvertiseGen_fix",                   "/workspace/chatglm3-6b",                 "finetune_demo/configs/lora.yaml"             ]         },         // torchrun 分布式         {             "name": "Python lora_ds 微调",             "type": "debugpy",             "request": "launch",             "program": "/opt/conda/envs/llm/bin/torchrun",             "console": "integratedTerminal",             "justMyCode": false,             "env": {                 "PYTHONPATH": "${workspaceRoot}"             },             "args": [                 "--nproc_per_node","1",                 "finetune_demo/finetune_hf.py",                 "/workspace/AdvertiseGen_fix",                   "/workspace/chatglm3-6b",                 "finetune_demo/configs/lora.yaml"             ]         }     ] } 

相关内容

热门资讯

今天下午!微信老铁13水辅助,... 今天下午!微信老铁13水辅助,潮汕雀友会辅助,总结教程(有挂细节)-哔哩哔哩1、微信老铁13水辅助辅...
详情透视!xpoker辅助!分... 详情透视!xpoker辅助!分辨真假辅助攻略(有挂教程)-哔哩哔哩小薇(辅助器软件下载)致您一封信;...
据监测!欢游互动辅助,蜀山四川... 据监测!欢游互动辅助,蜀山四川破解好友版辅助,手册教程(有挂分析)-哔哩哔哩1、蜀山四川破解好友版辅...
科普透视!wepoker有没有... 科普透视!wepoker有没有插件!每日必看辅助攻略(今日头条)-哔哩哔哩1、操作简单,无需wepo...
据权威媒体报道!雀姬辅助器,四... 据权威媒体报道!雀姬辅助器,四川家园辅助软件,讲义教程(有挂技巧)-哔哩哔哩一、四川家园辅助软件可以...
专业透视!pokemmo辅助官... 专业透视!pokemmo辅助官网!玩家必看教程辅助神器(有挂头条)-哔哩哔哩1、进入到pokemmo...
普及透视!wepoker软件安... 普及透视!wepoker软件安装包!重大通报辅助技巧(真是有挂)-哔哩哔哩暗藏猫腻,小编详细说明we...
有消息称!衢州都莱有没有辅助器... 有消息称!衢州都莱有没有辅助器,钱塘十水三挂件,攻略教程(有挂教学)-哔哩哔哩衢州都莱有没有辅助器破...
关于透视!hhpoker德州牛... 关于透视!hhpoker德州牛仔视频!总算清楚辅助技巧(有挂解惑)-哔哩哔哩1、点击下载安装,hhp...
针对!天天微友辅助器通用版,广... 针对!天天微友辅助器通用版,广东雀神智能辅助照片,学习教程(有挂教学)-哔哩哔哩1、下载好天天微友辅...