使用swift进行微调
'''
export NPROC_PER_NODE=3
export CUDA_VISIBLE_DEVICES=1,2,3,5
/opt/conda/envs/LM/bin/python finetuning/train_sft.py
'''
import os,sys
from utils.debug.debug import enable_remote_debug
enable_remote_debug(12345)
import time
from swift.llm import InferArguments, merge_lora, infer_main
from swift.llm import SftArguments, sft_main
# print('os.environ:', os.environ.get('RANK'))
# os.environ['CUDA_VISIBLE_DEVICES'] = '1,2,3,5'
# os.environ['NPROC_PER_NODE'] = '2'
# origin dataset train
# mix dataset train
train_dataset_path_chartqa =
trian_dataset_path_docvqa_train_10k=
# val dataset origin
val_dataset_path =
os.environ['NCCL_P2P_DISABLE']="1"
os.environ['NCCL_IB_DISABLE']="1"
now =time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
sft_args = SftArguments(
model_type='minicpm-v-v2_5-chat',
sft_type='lora',
dataset=[train_dataset_path_chartqa],
val_dataset=[val_dataset_path],
batch_size=1,
eval_steps=100,
num_train_epochs=3,
output_dir =f'./output/finetune/swift/{now}',
)
output = sft_main(sft_args)
best_model_checkpoint = output['best_model_checkpoint']
print(f'best_model_checkpoint: {best_model_checkpoint}')
当代码中使用如下方法时,并不生效,会出现oom的问题。
# os.environ['CUDA_VISIBLE_DEVICES'] = '1,2,3,5'
# os.environ['NPROC_PER_NODE'] = '2'
运行代码使用环境变量进行运行
NPROC_PER_NODE=3 CUDA_VISIBLE_DEVICES=1,2,3,5 python /home/app/examples/lb/san_nuo/finetuning/lora_swift/train_sft_swift.py
调试代码使用debugpy配置launch.json文件进行调试,