首页 前端知识 vscode调试launch.json常用格式

vscode调试launch.json常用格式

2024-05-27 09:05:30 前端知识 前端哥 842 710 我要收藏

目录

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"
]
}
]
}
复制

转载请注明出处或者链接地址:https://www.qianduange.cn//article/9664.html
标签
ide
评论
还可以输入200
共0条数据,当前/页
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!