vscode調(diào)試launch.json常用格式完整的案例
1、簡單的模版
定義一個(gè)簡單的模版如下:
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python 調(diào)試一", // 可自定義
"type": "debugpy",
"request": "launch",
"program": "運(yùn)行腳本的程序", // 使用.py 腳本路徑(相對路徑)、which torchrun、which deepspeed等命令查看位置
"console": "integratedTerminal",
"justMyCode": false, // 調(diào)試允許進(jìn)入他人的代碼
"env": {
"PYTHONPATH": "${workspaceRoot}" // 設(shè)置vscode家路徑為項(xiàng)目根路徑, 搜索包時(shí)優(yōu)先從該目錄進(jìn)行,防止發(fā)生import包錯(cuò)誤
},
"args": [ // 參數(shù),每個(gè)參數(shù)的參數(shù)值無論是否是數(shù)字都需用引號
"--參數(shù)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 執(zhí)行.py 文件
bash 命令
# 加入當(dāng)前目錄的絕對路徑
PYTHONPATH=$PWD
export PYTHONPATH
echo "當(dāng)前bash執(zhí)行目錄: $PWD, 已經(jīng)將PYTHONPATH設(shè)置為: $PYTHONPATH"
batch_dir=data/gpt3_generations_ceshi/
# 命令行python 進(jìn)行執(zhí)行
python self_instruct/bootstrap_instructions.py \
--batch_dir ${batch_dir} \
--num_instructions_to_generate 5
命令行 python 進(jìn)行執(zhí)行腳本,構(gòu)建launch.json 思路
- bash 為python執(zhí)行腳本.py,直接修改"program"為.py腳本相對路徑
- 其他參數(shù)照抄
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python 調(diào)試",
"type": "debugpy",
"request": "launch",
"program": "self_instruct/bootstrap_instructions.py", // .py腳本文件相對路徑位置
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTHONPATH": "${workspaceRoot}" // 設(shè)置vscode項(xiàng)目根路徑,搜索包時(shí)優(yōu)先從該目錄進(jìn)行,防止發(fā)生import包錯(cuò)誤
},
"args": [
"--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑
"--num_instructions_to_generate","5"
]
}
]
}
2.2、調(diào)式多個(gè)文件
與調(diào)試單個(gè)文件同理,只是重復(fù)
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// 第一個(gè)文件
{
"name": "Python 調(diào)試 bootstrap_instructions.py",
"type": "debugpy",
"request": "launch",
"program": "self_instruct/bootstrap_instructions.py", // .py腳本文件相對路徑位置
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTHONPATH": "${workspaceRoot}" // 設(shè)置vscode項(xiàng)目根路徑,搜索包時(shí)優(yōu)先從該目錄進(jìn)行,防止發(fā)生import包錯(cuò)誤
},
"args": [
"--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑
"--num_instructions_to_generate","5"
]
},
// 第二個(gè)文件
{
"name": "Python 調(diào)試 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}" // 設(shè)置vscode項(xiàng)目根路徑,搜索包時(shí)優(yōu)先從該目錄進(jìn)行,防止發(fā)生import包錯(cuò)誤
},
"args": [
"--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑
"--num_instructions_to_generate","5"
]
}
]
}
2.3、torchrun、deepspeed 調(diào)試
bash 命令
# 加入當(dāng)前目錄的絕對路徑
PYTHONPATH=$PWD
export PYTHONPATH
echo "當(dāng)前bash執(zhí)行目錄: $PWD, 已經(jīng)將PYTHONPATH設(shè)置為: $PYTHONPATH"
batch_dir=data/gpt3_generations_ceshi/
# 命令行python 進(jìn)行執(zhí)行
deepspeed --num_gpus 1 self_instruct/bootstrap_instructions.py \
--batch_dir ${batch_dir} \
--num_instructions_to_generate 5命令行 deepspeed/torchrun 進(jìn)行執(zhí)行腳本,構(gòu)建launch.json 思路
- 構(gòu)建launch.json腳本時(shí)需要找到“deepspeed”命令的路徑,bash命令行:which deepspeed,直接修改"program"為該路徑。
- self_instruct/bootstrap_instructions.py 是執(zhí)行的腳本的相對路徑,不在主目錄中,因此我們需要加入 "PYTHONPATH": "${workspaceRoot}" 指定項(xiàng)目目錄到環(huán)境變量中,以防代碼運(yùn)行時(shí)出現(xiàn) import 錯(cuò)誤
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python 調(diào)試一階段LORA",
"type": "debugpy",
"request": "launch",
"program": "/opt/conda/envs/dsc/bin/deepspeed", // which deepspeed 查看位置
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTHONPATH": "${workspaceRoot}" // 設(shè)置vscode項(xiàng)目根路徑,搜索包時(shí)優(yōu)先從該目錄進(jìn)行,防止發(fā)生import包錯(cuò)誤
},
"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.outlaunch.json
{
// 使用 IntelliSense 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python ds_z3_qlora_multigpu 微調(diào)",
"type": "debugpy",
"request": "launch",
"module": "accelerate.commands.launch", //調(diào)試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 了解相關(guān)屬性。
// 懸停以查看現(xiàn)有屬性的描述。
// 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// py 腳本
{
"name": "Python lora 微調(diào)",
"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 微調(diào)",
"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"
]
}
]
}總結(jié)
到此這篇關(guān)于vscode調(diào)試launch.json常用格式的文章就介紹到這了,更多相關(guān)vscode調(diào)試launch.json格式內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Elasticsearches通過坐標(biāo)位置實(shí)現(xiàn)對附近人的搜索
這篇文章主要為大家介紹了Elasticsearches使用坐標(biāo)位置實(shí)現(xiàn)對附近人的搜索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04
Elasticsearch在應(yīng)用中常見錯(cuò)誤示例解析
這篇文章主要為大家介紹了Elasticsearch在應(yīng)用中常見錯(cuò)誤示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04
Mac下更換Homebrew鏡像源的實(shí)現(xiàn)方法
本文主要介紹了Mac下更換Homebrew鏡像源的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-07-07

