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

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

相关推荐
Trouville016 小时前
windows系统使用llama.cpp进行本地大模型部署
llama
棒棒的唐9 小时前
windows 直接安装llama.cpp的方法
llama
troubles maker14 小时前
LLaMA-Adapter V2: Parameter-Efficient Visual Instruction Model
llm·nlp·llama·多模态
xyz_CDragon17 小时前
把旧电脑变成AI算力:llama.cpp RPC 局域网分布式推理验证与实战
人工智能·分布式·python·rpc·llama
wengad2 天前
llama.cpp进行模型格式转换和量化
llama
小七-七牛开发者2 天前
本地模型为什么能跑起来?从 llama.cpp 量化说起
agent·llama·模型部署·ollama·本地模型
七牛云行业应用3 天前
Llama 4 实战指南:Scout/Maverick 本地部署 + API 调用完整流程【2026】
llama
Soari3 天前
llama.cpp更新(b9553):LLM inference in C/C++,本地和云端实现高性能大模型推理
c语言·c++·llama
一叶知秋dong4 天前
llama.cpp 启动脚本
linux·服务器·llama
若苗瞬5 天前
继续提速:Llama.cpp 已经正式支持 Gemma4 MTP
google·llama·gemma·qat·mtp