Unsloth

unslothai/unsloth 访问 GitHub ↗
🔤 Python ★ 74269 ⑂ 0 weekly #15 (+2987) 抓取 2026-08-22

一句话简介

一个用于加速大语言模型微调与推理的 Python 库,通过优化显存占用和训练速度,让开源模型在消费级硬件上也能高效运行。

标签

  • 大语言模型
  • 模型微调
  • 推理加速
  • Python
  • 开源工具

适用应用场景

  • 在单卡 GPU 上微调 Llama 等大模型
  • 降低 LLaMA、Qwen 等模型的推理显存占用
  • 快速对开源模型进行 LoRA/QLoRA 微调
  • 在本地硬件部署量化大模型

README 中文摘要

项目概述

Unsloth 是一款面向本地 AI 模型运行与训练的工具,提供桌面应用、Web UI 与代码库三种形态,覆盖大语言模型、扩散模型、嵌入模型、音频模型与多模态模型。其核心目标是降低显存占用、加快训练速度,并简化本地部署流程。

核心特性

运行与构建

  • 支持 Kimi K3、MiniMax-H3、Qwen3.8、DeepSeek-V4、Gemma 4 等多种模型,以及图像/视频扩散模型。
  • 智能体与工具:通过 OpenAI 兼容 API 与 Anthropic 兼容接口接入 Claude Code、Codex、MCP 等,支持工具调用与代码执行。
  • 搜索与 RAG:支持私有无限网页搜索、深度研究与检索增强生成。
  • 硬件适配:支持 CPU、Apple Silicon、NVIDIA、AMD、Intel、Vulkan 以及多 GPU 配置。
  • 远程访问:通过 Cloudflare HTTPS 隧道安全暴露本地模型,也可提供 OpenAI 兼容 API。

训练与导出

  • 微调加速:相比基线实现 2 倍训练速度、节省 70% 显存且无精度损失。
  • 训练方法:覆盖 LoRA、QLoRA、全参数微调、预训练、强化学习(RL、GRPO、DPO)以及 FP8 训练。
  • 导出格式:支持 GGUF、NVFP4、FP8 等部署格式。
  • 数据集:通过 Data Recipes 从 PDF、CSV、DOCX 等文件构建训练数据。

安装方式

Unsloth Desktop(推荐)

基于 Tauri 的原生桌面应用,无需额外配置。提供 Windows、macOS、Ubuntu(deb)、Linux(AppImage)、Linux(Arm64)的安装包,也可通过以下命令自动安装:

# macOS / Linux / WSL
curl -fsSL https://unsloth.ai/install.sh | sh

# Windows PowerShell
irm https://unsloth.ai/install.ps1 | iex

Unsloth Studio(Web UI)

跨平台 Web 界面,支持 NVIDIA RTX 30/40/50、Blackwell、DGX Spark、macOS(MLX 与 GGUF)、AMD(Windows/WSL/Linux)、Intel XPU。安装命令同上。

通过环境变量可在安装前指定 GGUF 推理后端:

export UNSLOTH_LLAMA_CPP_BACKEND=vulkan   # 可选 cpu / cuda / rocm / vulkan / auto
curl -fsSL https://unsloth.ai/install.sh | sh

Vulkan 后端对缺少 ROCm PyTorch 支持的旧 AMD 显卡(Polaris、RDNA 1)尤为重要,可在 GPU 上运行 GGUF 推理。

Unsloth Core(代码库)

适合集成到现有 Python 项目:

# Linux / WSL
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv unsloth_env --python 3.13
source unsloth_env/bin/activate
uv pip install unsloth --torch-backend=auto

也提供 Docker 镜像 unsloth/unsloth

关键 CLI 用法

启动 Web UI

unsloth studio -p 8888              # 本地访问
unsloth studio -H 0.0.0.0 -p 8888   # 局域网访问
unsloth studio --secure -p 8888     # 通过 Cloudflare HTTPS 公网访问
unsloth studio -H 0.0.0.0 --cloudflare  # 局域网 + 公网 HTTPS

--secure 模式仅通过隧道发布,原始端口保持私有;首启动时会强制修改管理员密码。

接入智能体

unsloth start claude      # 连接 Claude Code
unsloth start codex       # 连接 OpenAI Codex
unsloth start hermes      # 连接 Hermes Agent
unsloth start openclaw    # 连接 OpenClaw
unsloth start opencode    # 连接 OpenCode

# 作为本地子智能体
unsloth start claude --as-subagent --model unsloth/model-GGUF:quant

高级安装选项

通过环境变量控制安装行为:

UNSLOTH_NO_TORCH=1        # 仅 GGUF,跳过 PyTorch
UNSLOTH_SKIP_AUTOSTART=1  # 跳过安装后自动启动
UNSLOTH_PYTHON=3.12       # 固定 Python 版本
UNSLOTH_STUDIO_HOME=/abs/path  # 自定义安装路径
UNSLOTH_CPU_THREADS=8     # 限制原生线程数

训练与硬件支持

Unsloth 提供覆盖主流模型的免费 Notebook(Colab / Kaggle),包括 Llama 3.1/3.2、Qwen3.5、Gemma 4、Mistral Ministral 3、Orpheus-TTS、embeddinggemma 等,标注了相对基线的速度提升与显存节省比例。

通过 MoE 优化、RoPE 与 MLP 的 Triton 内核、Padding-Free + Packing 等技术,在长上下文(已验证 500K 上下文 + 80GB GPU)与 MoE 模型(DeepSeek、GLM、Qwen、gpt-oss,最高 12 倍速度 + 35% 显存节省)场景下取得显著加速。

卸载

# macOS / Linux / WSL
curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/main/scripts/uninstall.sh | sh

# Windows
irm https://raw.githubusercontent.com/unslothai/unsloth/main/scripts/uninstall.ps1 | iex

模型缓存位于 ~/.cache/huggingface/hub/,卸载脚本不会自动删除。

摘要更新于 2026-08-22 00:33:57 · 原文 31499 字符 · md5 2c2df4982280…