vscode調(diào)試launch.json常用格式完整的案例
1、簡單的模版
定義一個簡單的模版如下:
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python 調(diào)試一", // 可自定義 "type": "debugpy", "request": "launch", "program": "運行腳本的程序", // 使用.py 腳本路徑(相對路徑)、which torchrun、which deepspeed等命令查看位置 "console": "integratedTerminal", "justMyCode": false, // 調(diào)試允許進入他人的代碼 "env": { "PYTHONPATH": "${workspaceRoot}" // 設置vscode家路徑為項目根路徑, 搜索包時優(yōu)先從該目錄進行,防止發(fā)生import包錯誤 }, "args": [ // 參數(shù),每個參數(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 命令
# 加入當前目錄的絕對路徑 PYTHONPATH=$PWD export PYTHONPATH echo "當前bash執(zhí)行目錄: $PWD, 已經(jīng)將PYTHONPATH設置為: $PYTHONPATH" batch_dir=data/gpt3_generations_ceshi/ # 命令行python 進行執(zhí)行 python self_instruct/bootstrap_instructions.py \ --batch_dir ${batch_dir} \ --num_instructions_to_generate 5
命令行 python 進行執(zhí)行腳本,構建launch.json 思路
- bash 為python執(zhí)行腳本.py,直接修改"program"為.py腳本相對路徑
- 其他參數(shù)照抄
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: 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}" // 設置vscode項目根路徑,搜索包時優(yōu)先從該目錄進行,防止發(fā)生import包錯誤 }, "args": [ "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑 "--num_instructions_to_generate","5" ] } ] }
2.2、調(diào)式多個文件
與調(diào)試單個文件同理,只是重復
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ // 第一個文件 { "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}" // 設置vscode項目根路徑,搜索包時優(yōu)先從該目錄進行,防止發(fā)生import包錯誤 }, "args": [ "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑 "--num_instructions_to_generate","5" ] }, // 第二個文件 { "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}" // 設置vscode項目根路徑,搜索包時優(yōu)先從該目錄進行,防止發(fā)生import包錯誤 }, "args": [ "--batch_dir","data/gpt3_generations_ceshi",// TODO 修改官方線上數(shù)據(jù)集為自己的路徑 "--num_instructions_to_generate","5" ] } ] }
2.3、torchrun、deepspeed 調(diào)試
bash 命令
# 加入當前目錄的絕對路徑 PYTHONPATH=$PWD export PYTHONPATH echo "當前bash執(zhí)行目錄: $PWD, 已經(jīng)將PYTHONPATH設置為: $PYTHONPATH" batch_dir=data/gpt3_generations_ceshi/ # 命令行python 進行執(zhí)行 deepspeed --num_gpus 1 self_instruct/bootstrap_instructions.py \ --batch_dir ${batch_dir} \ --num_instructions_to_generate 5
命令行 deepspeed/torchrun 進行執(zhí)行腳本,構建launch.json 思路
- 構建launch.json腳本時需要找到“deepspeed”命令的路徑,bash命令行:which deepspeed,直接修改"program"為該路徑。
- self_instruct/bootstrap_instructions.py 是執(zhí)行的腳本的相對路徑,不在主目錄中,因此我們需要加入 "PYTHONPATH": "${workspaceRoot}" 指定項目目錄到環(huán)境變量中,以防代碼運行時出現(xiàn) import 錯誤
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: 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}" // 設置vscode項目根路徑,搜索包時優(yōu)先從該目錄進行,防止發(fā)生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 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: 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 了解相關屬性。 // 懸停以查看現(xiàn)有屬性的描述。 // 欲了解更多信息,請訪問: 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é)
到此這篇關于vscode調(diào)試launch.json常用格式的文章就介紹到這了,更多相關vscode調(diào)試launch.json格式內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Source?Insight?4.0.093?安裝破解詳細圖文教程
這篇文章主要介紹了Source?Insight?4.0.093?安裝破解詳細圖文教程,source?insight?4是一款非常強大的程序編輯器,如果你沒有一款合適的代碼編輯器,那么這款軟件不妨試試,可能你會喜歡2022-08-08關于解決?“Error:?listen?EACCES:?permission?denied?0.0.0.0:
這篇文章主要介紹了在開發(fā)過程中常見的錯誤Error:listenEACCES:permissiondenied0.0.0.0:80,并提供了兩種解決方法,大家可以根據(jù)需求選擇對應的方法,需要的朋友可以參考下2024-12-12Prometheus和NodeExporter安裝監(jiān)控數(shù)據(jù)說明
這篇文章主要為大家介紹了Prometheus和node?exporter安裝監(jiān)控數(shù)據(jù)說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07