微调前期准备
下载 Qwen3.5-4B 模型
首先确保已安装 Git LFS,然后克隆模型仓库。
git lfs install
git clone https://huggingface.co/Qwen/Qwen3.5-4B.git
下载 LlamaFactory
克隆 LlamaFactory 源码库。
git clone --depth 1 https://github.com/hiyouga/LlamaFactory.git
微调环境搭建
推荐使用 Miniconda 构建隔离环境。
# 清除当前 shell 会话中的 PYTHONPATH 环境变量
unset PYTHONPATH
# 安装 miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
bash Miniconda3-latest-Linux-aarch64.sh
conda config --set auto_activate_base false
source ~/.bashrc
# 接受 main 通道的条款
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
# 创建 python3.11 环境
conda create --name LlamaFactory python=3.11 -y
conda activate LlamaFactory
安装 LlamaFactory 环境依赖
进入项目目录并安装依赖。为了获得训练推理加速效果,可安装 flash-linear-attention。
cd LlamaFactory
pip install -e .
pip uninstall fla-core flash-linear-attention -y && pip install -U git+https://github.com/fla-org/flash-linear-attention
# 因为使用的是昇腾 NPU 的算力,还需要额外安装 torch-npu 和 decorator
pip install torch-npu==2.10.0rc2
pip install decorator
可以使用下面的命令验证是否安装成功:
llamafactory-cli version
显示版本号则表示安装成功。完成环境的搭建之后,还需要将昇腾的环境启动命令跑一遍:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /usr/local/Ascend/nnal/asdsip/set_env.sh
source /usr/local/Ascend/nnal/atb/set_env.sh
下载数据集
根据 LlamaFactory 的要求,我们需要把数据集放到 LlamaFactory/data 目录下。
LlamaFactory/data


