一 Finetune 简介
增强预训练:基座模型学到新知识
指令跟随微调:instructed LLM,对话模板
LoRA:减少显存开销,在原本的Linear旁增加一个分支Adapter
QLoRA:粗略加载模型,在GPU和CPU间调度
二 XTuner
适配多种生态和多种硬件
1.安装
激活环境 conda activate xtuner0.1.9 拉取 0.1.9 的版本源码 git clone -b v0.1.9 https://github.com/InternLM/xtuner 从源码安装 XTuner pip install -e '.[all]'
2.微调
准备配置文件
xtuner copy-cfg internlm_chat_7b_qlora_oasst1_e3 .
模型下载
通过软链的方式,将模型文件挂载到家目录下
ln -s /share/temp/model_repos/internlm-chat-7b ~/ft-oasst1/
数据集下载
cp -r /root/share/temp/datasets/openassistant-guanaco .
修改配置文件
修改其中的模型和数据集为 本地路径
开始微调
xtuner train ./internlm_chat_7b_qlora_oasst1_e3_copy.py --deepspeed deepspeed_zero2
得到的 PTH 模型转换为 HuggingFace 模型
将 HuggingFace adapter 合并到大语言模型
与合并后的模型对话
微调前: xtuner chat ./internlm-chat-7b/ --prompt-template internlm_chat --bits 4
微调后:xtuner chat ./merged --prompt-template internlm_chat --bits 4