微调前期准备
下载模型与工具
首先确保已安装 git-lfs,然后克隆 Qwen3.5-4B 模型仓库:
git lfs install
git clone https://modelers.cn/Qwen-AI/Qwen3.5-4B.git
接着获取 LlamaFactory 源码。建议使用官方地址以保证稳定性:
git clone --depth 1 https://github.com/hiyouga/LlamaFactory.git

搭建微调环境
推荐使用 Miniconda 隔离 Python 环境,避免依赖冲突。
# 清除当前 shell 会话中的 PYTHONPATH 环境变量
unset PYTHONPATH
# 安装 miniconda (以 Linux aarch64 为例)
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 和 r 通道的条款
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
安装依赖
进入项目目录安装核心依赖。若需获得训练推理加速效果,可额外安装 flash-linear-attention。
cd LlamaFactory
pip install -e .
# 可选:安装 flash-linear-attention
pip uninstall fla-core flash-linear-attention -y && pip install -U git+https://github.com/fla-org/flash-linear-attention
# 昇腾 NPU 算力适配
pip install torch-npu==2.10.0rc2
pip install decorator
验证安装是否成功:
llamafactory-cli version








