LLaMA-Factory
Llama-Factory 是基于 transformers 库开发的训练、微调、推理一体化平台,支持预训练、指令监督微调、奖励模型训练、PPO 训练、DPO 训练、KTO 训练、ORPO 训练等多种训练范式。它允许使用 Accelerate 或 DeepSpeed 作为训练加速后端。
使用 Llama-Factory 进行微调非常简单,其核心优势在于强大的数据处理与训练配置能力。只要按照官方文档配置好环境,直接运行对应的脚本即可。
安装部署
容器安装
推荐使用 Docker 快速构建环境,避免依赖冲突:
git clone https://github.com/hiyouga/LlamaFactory.git
cd LlamaFactory
cd docker/docker-cuda/
# Build the image
docker build -f ./docker/docker-cuda/Dockerfile \
--build-arg PIP_INDEX=https://pypi.org/simple \
--build-arg EXTRAS=metrics \
-t llamafactory:latest
# Run the container
docker run -dit --ipc=host --gpus=all \
-p 7860:7860 \
-p 8000:8000 \
--name llamafactory \
llamafactory:latest
# Enter the container
docker exec -it llamafactory bash
编译安装
如果需要在宿主机直接安装:
cd workspace
git clone https://github.com/hiyouga/LlamaFactory.git
docker run -d --network=host --restart=always --name=llamafactory-dev \
--gpus=all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 \
-v "$PWD":/workspace -w /workspace \
nvcr.io/nvidia/pytorch:25.08-py3 \
tail -f /dev/null
docker exec -it -u root llamafactory-dev bash
# 创建配置目录
mkdir -p ~/.pip
# 创建配置文件
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
EOF
pip uninstall -y torch torchvision torchaudio nvidia-cublas nvidia-cudnn-cu12
pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple --index-url https://download.pytorch.org/whl/cu130
pip install --upgrade nvidia-cublas nvidia-cudnn-cu13
cd LlamaFactory
pip install -e '.[torch,metrics]'


