llama-factory部署微调方法(wsl-Ubuntu & Windows)

llama-factory项目GitHub地址:GitHub - hiyouga/LLaMA-Factory: Unified Efficient Fine-Tuning of 100+ LLMs & VLMs (ACL 2024)

wsl-Ubuntu:

1.获取项目

python 复制代码
git clone https://github.com/hiyouga/LLaMA-Factory.git

cd LLaMA-Factory/ 

2.安装环境

python 复制代码
# 创建一个环境
conda create -n llama-f python==3.10
# 激活环境 conda activate不行的话就用source activate
conda activate llama-f

安装包:

python 复制代码
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

解决包冲突

冲突:
解决:
python 复制代码
pip install --no-deps -e .

(选用)额外报错:缺少Rust和Cargo

报错:
python 复制代码
Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: 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 through
      the 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:

python 复制代码
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

运行后,脚本会提示你选择安装选项。默认情况下,直接按回车键选择默认安装即可

配置环境变量
python 复制代码
source $HOME/.cargo/env

如果想永久生效,可以将以下内容添加到你的Shell配置文件

nano ~/.bashrc 然后到最后一行添加:

python 复制代码
export PATH="$HOME/.cargo/bin:$PATH"

用命令使配置生效

python 复制代码
source ~/.bashrc
验证:
python 复制代码
rustc --version
cargo --version

3. 启动

环境配置完后就可以通过命令启动webui界面,并通过网页访问

python 复制代码
llamafactory-cli webui

然后在网页输入:

python 复制代码
http://localhost:7860/

就进去了,可以进行微调操作

Windows:

前面的clone和 环境以及 pip install -e ".[torch,metrics]"这些都是一样的

Windows缺少Rust和Cargo:

  1. 打开 PowerShell命令提示符(以管理员身份运行)。

  2. 运行以下命令下载并安装 rustup

    python 复制代码
    winget install --id Rustlang.Rustup

    如果 winget 不可用(例如在较旧的 Windows 版本中),可以使用以下命令:

    python 复制代码
    curl -sSf https://sh.rustup.rs | sh

    如果提示没有 curl,可以先安装 curl

    python 复制代码
    winget install curl.curl
  3. 安装过程中,会提示你选择安装选项。直接按回车键选择默认安装即可

安装完成后,rustup 会自动将 Rust 的工具链添加到系统的 PATH 环境变量中。

验证安装

python 复制代码
rustc --version
cargo --version

启动:

Windows启动webui界面命令:

python 复制代码
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

等等好多,可以自行选择使用

相关推荐
blackoon882 天前
DeepSeek R1大模型微调实战-llama-factory的模型下载与训练
llama
johnny2332 天前
大模型微调理论、实战:LLaMA-Factory、Unsloth
llama
闲看云起3 天前
从 GPT 到 LLaMA:解密 LLM 的核心架构——Decoder-Only 模型
gpt·架构·llama
小草cys4 天前
在树莓派集群上部署 Distributed Llama (Qwen 3 14B) 详细指南
python·llama·树莓派·qwen
咕咚-萌西5 天前
联邦学习论文分享:Towards Building the Federated GPT:Federated Instruction Tuning
llama·联邦学习·指令微调
relis6 天前
解密llama.cpp中的batch与ubatch:深度学习推理优化的内存艺术
深度学习·batch·llama
relis6 天前
解密llama.cpp:Prompt Processing如何实现高效推理?
prompt·llama
GEO_JYB7 天前
BERT家族进化史:从BERT到LLaMA,每一次飞跃都源于对“学习”的更深理解
学习·bert·llama
AI大模型7 天前
大模型开发实战:使用 LLaMA Factory 微调与量化模型并部署至 Ollama
程序员·llm·llama