llama-factory项目GitHub地址:GitHub - hiyouga/LLaMA-Factory: Unified Efficient Fine-Tuning of 100+ LLMs & VLMs (ACL 2024)
wsl-Ubuntu:
1.获取项目
git clone https://github.com/hiyouga/LLaMA-Factory.gitcd LLaMA-Factory/
2.安装环境
# 创建一个环境
conda create -n llama-f python==3.10
# 激活环境 conda activate不行的话就用source activate
conda activate llama-f
安装包:
pip install -e ".[torch,metrics]"
可用的额外依赖项:torch、torch-npu、metrics、deepspeed、liger-kernel、bitsandbytes、hqq、eetq、gptq、awq、aqlm、vllm、galore、apollo、badam、adam-mini、qwen、minicpm_v、modelscope、openmind、swanlab、quality
解决包冲突
冲突:
解决:
pip install --no-deps -e .
(选用)额外报错:缺少Rust和Cargo
报错:
Installing build dependencies ... doneGetting requirements to build wheel ... donePreparing metadata (pyproject.toml) ... errorerror: subprocess-exited-with-error× Preparing metadata (pyproject.toml) did not run successfully.│ exit code: 1╰─> [6 lines of output]Cargo, the Rust package manager, is not installed or is not on PATH.This package requires Rust and Cargo to compile extensions. Install it throughthe system's package manager or via https://rustup.rs/Checking for Rust toolchain....[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.
解决:
Rust官方提供了一个非常方便的安装脚本,可以通过以下命令安装Rust和Cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
运行后,脚本会提示你选择安装选项。默认情况下,直接按回车键选择默认安装即可
配置环境变量
source $HOME/.cargo/env
如果想永久生效,可以将以下内容添加到你的Shell配置文件
nano ~/.bashrc 然后到最后一行添加:
export PATH="$HOME/.cargo/bin:$PATH"
用命令使配置生效
source ~/.bashrc
验证:
rustc --version
cargo --version
3. 启动
环境配置完后就可以通过命令启动webui界面,并通过网页访问
llamafactory-cli webui
然后在网页输入:
http://localhost:7860/
就进去了,可以进行微调操作
Windows:
前面的clone和 环境以及 pip install -e ".[torch,metrics]"这些都是一样的
Windows缺少Rust和Cargo:
-
打开 PowerShell 或 命令提示符(以管理员身份运行)。
-
运行以下命令下载并安装
rustup
:winget install --id Rustlang.Rustup
如果
winget
不可用(例如在较旧的 Windows 版本中),可以使用以下命令:curl -sSf https://sh.rustup.rs | sh
如果提示没有
curl
,可以先安装curl
:winget install curl.curl
-
安装过程中,会提示你选择安装选项。直接按回车键选择默认安装即可
安装完成后,rustup
会自动将 Rust 的工具链添加到系统的 PATH
环境变量中。
验证安装
rustc --version
cargo --version
启动:
Windows启动webui界面命令:
python src/webui.py
也进来了:
还有一些环境变量,可以在执行python src/webui.py前执行,比如:
set USE_MODELSCOPE_HUB=1:
该变量用于指定是否使用ModelScope Hub。ModelScope Hub是一个模型托管平台,设置为1
表示启用该功能。
export CUDA_VISIBLE_DEVICES=0:
该变量用于控制可见的GPU设备。CUDA_VISIBLE_DEVICES=0
表示仅使用第一个GPU。
TRANSFORMERS_CACHE=*****:
-
指定Hugging Face模型的缓存路径。
-
示例:
set TRANSFORMERS_CACHE=C:\cache\transformers
等等好多,可以自行选择使用