[草稿]利用 LLaMA Factory 微调开源大模型

[TOC]

安装 LLaMA Factory

  • 第1步,安装 git
apt install -y git
git --version
  • 第2步,安装 python 3.12.3 及最新的 pip3
curl -sL 'http://iso.sqlfans.cn/python/install_python_3123.sh' | bash
python3 --version
pip3 --version
  • 第3步,安装 conda 25.1.1
#.安装conda,按回车阅读liense,默认安装到 /root/miniconda3
cd /opt/
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

#.配置环境变量
echo 'export PATH=$PATH:/root/miniconda3/bin' >> /etc/profile
source /etc/profile
conda --version
cd /data/
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git

#.创建一个名为 llama_factory 的虚拟环境
cd /data/LLaMA-Factory
conda create --name llama_factory python=3.12.3

#.初始化虚拟环境
conda init

#.退出重连或重开⼀个终端(ubuntu安装好conda之后,新的终端界面前面会出现(bash)字样)
exit

#.激活虚拟环境
cd /data/LLaMA-Factory
conda activate llama_factory

#.安装配置文件
cd /data/LLaMA-Factory
pip3 install -e ".[torch,metrics]"
 # pip3 install -e ".[torch,metrics]" -i https://pypi.tuna.tsinghua.edu.cn/simple
 # pip3 install -r requirements.txt

#.确认 llamafactory-cli 安装成功
llamafactory-cli version

注:遇到包冲突时,可使用 pip3 install --no-deps -e ".[torch,metrics]"

  • 第5步,通过 llamafactory-cli 启动 webui
llamafactory-cli webui

模型微调及推理训练

#.分别对 Llama3-8B-Instruct 模型进行 LoRA 微调、推理和合并
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml
llamafactory-cli chat examples/inference/llama3_lora_sft.yaml
llamafactory-cli export examples/merge_lora/llama3_lora_sft.yaml

遇到的问题

  • 问题1:执行 llamafactory-cli 找不到库文件 libsndfile
  • 详情1:在 centos 7.9 系统上执行 llamafactory-cli version 报错 OSError: cannot load library 'libsndfile.so': libsndfile.so: cannot open shared object file: No such file or directory
  • 解决:先执行 yum update 否则 yum install 提示不存在 libsndfile
yum -y update
yum -y install libsndfile
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2025-02-21 19:59:16

results matching ""

    No results matching ""