''' ''' 模型采用qwe7bchat 微调超参数: traidatasetsample=500, eval_steps=20, loggig_steps=5, output_dir='output', loratargetmodules='ALL', selfcogitiosample=500 提示: 因为自我认知训练涉及到知识编辑, 建议对MLP加loratargetmodules. 可以通过指定--loratargetmodules ALL在所有的liear层(包括qkvo以及mlp)加lora. 这通常是效果最好的. 使用pytho: 需要设置bestmodelcheckpoit的值, 该值会在sft的最后被打印出来. 使用pytho:环境安装
# 设置pip全局镜像
pip cofig set global.idex-url https://mirrors.aliyu.com/pypi/simple/
# 安装ms-swift
git cloe https://github.com/modelscope/swift.git
cd swift
pip istall -e .[llm]
#环境对齐 (如果你运行错误, 可以跑下面的代码, 仓库使用最新环境测试)
pip istall -r requiremets/framework.txt -U
pip istall -r requiremets/llm.txt -U
超参数设置
微调
# Experimetal eviromet: A10, 3090, V100, ...
# 18GB GPU memory
import os
os.eviro['CUDA_VISIBLE_DEVICES'] = '0'
from swift.llm import DatasetName, ModelType, SftArgumets, sft_mai
sft_args = SftArgumets(
model_type=ModelType.qwe_7b_chat,
dataset=[DatasetName.alpaca_zh, DatasetName.alpaca_e],
trai_dataset_sample=500,
eval_steps=20,
loggig_steps=5,
output_dir='output',
lora_target_modules='ALL',
self_cogitio_sample=500,
model_ame=['夜咏', 'Night Ode'],
model_author=['李岚泽', 'Lazer'])
output = sft_mai(sft_args)
best_model_checkpoit = output['best_model_checkpoit']
prit(f'best_model_checkpoit: {best_model_checkpoit}')
微调实验记录
微调后推理
import os
os.eviro['CUDA_VISIBLE_DEVICES'] = '0'
from swift.llm import IferArgumets, merge_lora_mai, ifer_mai
best_model_checkpoit = 'output/qwe-7b-chat/v0-20240122-205735/checkpoit-62'
ifer_args = IferArgumets(
ckpt_dir=best_model_checkpoit,
eval_huma=True)
# merge_lora_mai(ifer_args)
result = ifer_mai(ifer_args)
实验记录
点击空白处退出提示
评论