Ubuntu + Anaconda + CUDA/CUDNN + 8GB nvidia显卡
# 构建虚拟环境
conda create --name xtuner0.1.9 python=3.10 -y
# 拉取 0.1.9 的版本源码
git clone -b v0.1.9 https://github.com/InternLM/xtuner
# 从源码安装 XTuner
pip install -e '.[all]'
# 安装modelscope库
pip install modelscope
# 从 modelscope 下载下载模型文件
apt install git git-lfs -y
git lfs install
git lfs clone https://modelscope.cn/Shanghai_AI_Laboratory/internlm-chat-7b.git -b v1.0.3
数据集链接:https://huggingface.co/datasets/timdettmers/openassistant-guanaco/tree/main
`# xtuner copy-cfg ${CONFIG_NAME} ${SAVE_PATH}`
本次实践拷贝文件为:
xtuner copy-cfg internlm_chat_7b_qlora_oasst1_e3 .
数据集与配置文件准备完成后的文件目录:
# 修改模型为本地路径
- pretrained_model_name_or_path = 'internlm/internlm-chat-7b'
+ pretrained_model_name_or_path = './internlm-chat-7b'
# 修改训练数据集为本地路径
- data_path = 'timdettmers/openassistant-guanaco'
+ data_path = './openassistant-guanaco'
其他超参数:
# 训练:
xtuner train ${CONFIG_NAME_OR_PATH}
# 也可以增加 deepspeed 进行训练加速:
xtuner train ${CONFIG_NAME_OR_PATH} --deepspeed deepspeed_zero2
# 后台加速运行
nohup xtuner train ./internlm_chat_7b_qlora_oasst1_e3_copy.py --deepspeed deepspeed_zero2 >>./train.log 2>&1 &
mkdir hf
export MKL_SERVICE_FORCE_INTEL=1
xtuner convert pth_to_hf ./internlm_chat_7b_qlora_oasst1_e3_copy.py ./work_dirs/internlm_chat_7b_qlora_oasst1_e3_copy/epoch_3.pth ./hf
# xtuner convert merge \
# ${NAME_OR_PATH_TO_LLM} \
# ${NAME_OR_PATH_TO_ADAPTER} \
# ${SAVE_PATH} \
# --max-shard-size 2GB
# 示例:
xtuner convert merge ./internlm-chat-7b ./hf ./merged --max-shard-size 2GB
xtuner chat ./merged --prompt-template internlm_chat
默认是float 16格式加载模型,如果需要设置4bit量化加载
# 4 bit 量化加载
# xtuner chat ./merged --bits 4 --prompt-template internlm_chat