微调前期准备
下载 Qwen3.5-4B 模型
# 首先保证已安装 git-lfs
git lfs install
git clone https://huggingface.co/Qwen/Qwen3.5-4B.git
下载 Llama-Factory
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
# 加载 conda 配置
source ~/.bashrc
# 接受 main 通道的条款
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
# 接受 r 通道的条款
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 环境依赖
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 的算力,所以我们还需要额外装一个 torch-npu 和 decorator
pip install torch-npu==2.10.0rc2
pip install decorator
可以使用下面的命令验证是否安装成功:
llamafactory-cli version









