Unsloth:61K Stars·本地AI训练与推理平台·2倍速·70%显存节省完全指南
一、项目概述
1.1 Unsloth 是什么
Unsloth Studio 🦥 是一个强大的本地 AI 训练与推理平台,支持在 Windows、Linux、macOS 上运行和微调文本、音频、embedding、视觉模型。
“Unsloth Studio (Beta) lets you run and train text, audio, embedding, vision models on Windows, Linux and macOS.”
被 Yann LeCun 点赞推荐!
1.2 核心数据
| 指标 | 数值 |
|---|
| Stars | 61k ⭐ |
| Forks | 5.3k |
| 贡献者 | 190 |
| 最新版本 | v0.1.36-beta (2026-04-08) |
| 提交数 | 5,004 commits |
| 许可证 | Apache-2.0 / AGPL-3.0 |
| 语言 | Python 65.2%, TypeScript 30.0% |
1.3 核心定位
| 维度 | 说明 |
|---|
| ⚡ 极速训练 | 最高 2 倍速,70% 显存节省 |
| 🎯 500+ 模型 | Gemma、Qwen、Llama、Mistral、DeepSeek 等 |
| 🔧 双模式 | Studio UI + Core 代码版 |
| 🌐 全平台 | Windows、Linux、macOS、WSL、Docker |
| 🤖 推理+训练 | 统一本地接口 |
| 📊 可观测 | 实时监控 loss 和 GPU 使用 |
二、核心功能
2.1 功能矩阵
| 类别 | 功能 |
|---|
| 🤖 推理 | GGUF/LoRA/safetensors 模型搜索下载运行 |
| 🔧 工具调用 | Self-healing tool calling、Web search |
| 💻 代码执行 | Claude artifacts 沙盒环境 |
| 🎨 多模态 | 图片、音频、PDF、DOCX 上传聊天 |
| 📚 训练 | 500+ 模型微调,2x 加速,70% 显存节省 |
| 🧠 RL/GRPO | 强化学习,80% 显存节省 |
| 📝 Data Recipes | 可视化数据创建和编辑 |
| 📊 可观测 | 实时 loss 曲线、GPU 监控 |
| 🔄 多 GPU | 支持多卡训练(即将重大升级) |
2.2 为什么选择 Unsloth
| 特性 | 说明 |
|---|
| ⚡ 2 倍速 | 自定义 Triton 内核优化 |
| 💾 70% 显存 | 4-bit 量化训练,无精度损失 |
| 🧠 80% 显存(RL) | GRPO/PPO 等强化学习算法 |
| 📊 500K Context | 80GB GPU 训练 20B 模型 500K 上下文 |
| 🔧 TRL 合作 | 与 HuggingFace TRL 团队合作优化 |
| 🐛 Bug 修复 | 直接与 Qwen/Llama4/Mistral/Gemma 团队合作修复 |
| 📈 FP8 & Vision RL | 支持消费级 GPU 做 FP8 和视觉强化学习 |
三、快速开始
3.1 Unsloth Studio(Web UI)
macOS / Linux / WSL
curl -fsSL https://unsloth.ai/install.sh | sh
Windows
irm https://unsloth.ai/install.ps1 | iex
启动
unsloth studio -H 0.0.0.0 -p 8888
更新
3.2 Unsloth Core(代码版)
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
Windows
winget install -e --id Python.Python.3.13
winget install --id=astral-sh.uv -e
uv venv unsloth_env --python 3.13
.\unsloth_env\Scripts\activate
uv pip install unsloth --torch-backend=auto
3.3 Docker 部署
docker run -d \
-e JUPYTER_PASSWORD="mypassword" \
-p 8888:8888 -p 8000:8000 -p 2222:22 \
-v $(pwd)/work:/workspace/work \
--gpus all \
unsloth/unsloth
四、支持的模型
4.1 模型目录
| 模型家族 | 代表模型 | 说明 |
|---|
| Gemma | Gemma 4 (E2B), Gemma 3 | Google 最新模型 |
| Qwen | Qwen3.5 (0.8B-112B), Qwen3 GSPO | 阿里巴巴开源 |
| Llama | Llama 3.1/3.2 (8B-405B) | Meta 开源 |
| DeepSeek | DeepSeek V3, Coder | 中国团队 |
| Mistral | Mistral, Ministral 3 | 欧洲团队 |
| gpt-oss | OpenAI o1/o3 开源复现 | Unsloth 合作 |
| Phi | Phi-4 | 微软小模型 |
| ** embedding** | embedding-gemma | 向量模型 |
4.2 免费 Notebooks 性能表
| 模型 | 性能 | 显存节省 |
|---|
| Gemma 4 (E2B) | 1.5x faster | 50% less |
| Qwen3.5 (4B) | 1.5x faster | 60% less |
| gpt-oss (20B) | 2x faster | 70% less |
| gpt-oss RL | 2x faster | 80% less |
| Qwen3 GSPO | 2x faster | 70% less |
| Llama 3.1 (8B) | 2x faster | 70% less |
| embedding-gemma (300M) | 2x faster | 20% less |
| Mistral Ministral 3 (3B) | 1.5x faster | 60% less |
五、推理功能详解
5.1 模型搜索与下载
# 在 Unsloth Studio 中
# 1. 打开模型搜索
# 2. 搜索 GGUF、LoRA、safetensors
# 3. 一键下载到本地
5.2 工具调用
| 功能 | 说明 |
|---|
| Self-healing tool calling | 自动修复工具调用错误 |
| Web search | 集成网络搜索 |
# 示例:使用工具调用
agent = Agent(tools=["web_search", "calculator"])
result = await agent.run("Search for latest AI news and calculate 15% of 1000")
5.3 代码执行
Unsloth 支持 Claude Artifacts 风格的代码执行:
# 代码在沙盒环境中执行
agent = Agent(tools=["code_execution"])
result = await agent.run("Write and run a Python script that prints Fibonacci numbers")
5.4 多模态支持
支持上传多种文件类型进行聊天:
| 文件类型 | 支持情况 |
|---|
| 🖼️ 图片 | ✅ 支持 |
| 🎵 音频 | ✅ 支持 |
| 📄 PDF | ✅ 支持 |
| 📝 DOCX | ✅ 支持 |
| 💻 代码 | ✅ 支持 |
六、训练功能详解
6.1 训练模式
| 模式 | 说明 |
|---|
| Full Fine-tuning | 全参数微调 |
| 4-bit Fine-tuning | 4-bit QLoRA,70% 显存节省 |
| 16-bit Training | 16-bit 训练 |
| FP8 Training | FP8 量化训练 |
| RL / GRPO | 强化学习,80% 显存节省 |
| Pretraining | 预训练 |
6.2 自定义 Triton 内核
Unsloth 与 PyTorch 和 HuggingFace 团队合作优化:
# 使用优化后的 Triton 内核
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="unsloth/gemma-3-4b-it",
max_seq_length=2048,
load_in_4bit=True,
)
6.3 Data Recipes
Data Recipes 是 Unsloth 的可视化数据创建功能:
# 在 Unsloth Studio 中
# 1. 打开 Data Recipes
# 2. 上传 PDF、CSV、DOCX
# 3. 使用可视化节点编辑数据
# 4. 导出为训练数据集
6.4 强化学习(RL/GRPO)
Unsloth 提供最高效的 RL 库:
from unsloth import GRPOConfig
config = GRPOConfig(
lr=1e-4,
grpo_epochs=4,
max_steps=100,
)
# 80% VRAM 节省
七、Unsloth Studio UI
7.1 界面功能
| 功能 | 说明 |
|---|
| 🖥️ Chat | 对话界面,支持多模态 |
| 📚 Models | 模型搜索、下载、管理 |
| 📝 Data Recipes | 可视化数据创建 |
| 🔧 Training | 训练配置和启动 |
| 📊 Observability | 实时监控 |
7.2 快捷命令
| 命令 | 说明 |
|---|
unsloth studio | 启动 Studio |
unsloth studio update | 更新 Studio |
unsloth studio -H 0.0.0.0 -p 8888 | 指定端口启动 |
八、开发者安装
8.1 开发者模式(Mac/Linux/WSL)
git clone https://github.com/unslothai/unsloth
cd unsloth
./install.sh --local
unsloth studio -H 0.0.0.0 -p 8888
8.2 开发者模式(Windows)
git clone https://github.com/unslothai/unsloth.git
cd unsloth
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass .\install.ps1 --local
unsloth studio -H 0.0.0.0 -p 8888
8.3 Nightly 版本
# Mac/Linux/WSL
git clone https://github.com/unslothai/unsloth
cd unsloth
git checkout nightly
./install.sh --local
unsloth studio -H 0.0.0.0 -p 8888
九、硬件支持
9.1 支持的硬件
| 平台 | 训练 | 推理 | Data Recipes |
|---|
| NVIDIA GPU | ✅ RTX 30/40/50, Blackwell, DGX | ✅ | ✅ |
| AMD GPU | ✅ (Unsloth Core) | ✅ | ✅ |
| Apple MLX | 即将支持 | 即将支持 | - |
| Intel GPU | 即将支持 | ✅ | - |
| CPU | ❌ | ✅ | ✅ |
| macOS | 即将支持 | ✅ | ✅ |
9.2 显存需求
| 模型大小 | 4-bit 训练 | 16-bit 训练 |
|---|
| 7B | ~6GB | ~14GB |
| 13B | ~10GB | ~26GB |
| 20B | ~14GB | ~40GB |
| 70B | ~48GB | ~140GB |
十、与上游团队合作
Unsloth 与多个模型团队直接合作修复 Bug:
| 模型 | 合作内容 |
|---|
| gpt-oss | Bug 修复,提升准确性 |
| Qwen3 | 动态 GGUF 128K context bug 修复 |
| Llama 4 | Bug 修复 |
| Mistral | Bug 修复 |
| Gemma 1-3 | Bug 修复 |
| Phi-4 | Bug 修复 |
十一、Notebooks 资源
11.1 免费 Notebooks
Unsloth 提供免费 Google Colab Notebooks:
# 访问
# https://colab.research.google.com/github/unslothai/notebooks
11.2 Notebook 类型
| 类型 | 说明 |
|---|
| Vision | 视觉模型微调 |
| GRPO | 强化学习微调 |
| TTS | 文本转语音 |
| Embedding | 向量模型微调 |
| Kaggle | Kaggle 集成 |
十二、卸载与清理
12.1 卸载 Studio
# macOS / Linux / WSL
rm -rf ~/.unsloth/studio
# Windows (PowerShell)
Remove-Item -Recurse -Force "$HOME\.unsloth\studio"
12.2 删除模型文件
# macOS / Linux / WSL
rm -rf ~/.cache/huggingface/hub/
# Windows
Remove-Item -Recurse -Force "$env:USERPROFILE\.cache\huggingface\hub\"
十三、社区资源
13.1 社区链接
13.2 官方博客
| 博客 | 说明 |
|---|
| Gemma 4 | 运行和训练 Google 最新模型 |
| Unsloth Studio | Web UI 发布 |
| MoE 训练 | 12x 加速,35% 显存节省 |
| Embedding | 1.8-3.3x 加速 |
| 500K Context | 超长上下文训练 |
| FP8 & Vision RL | 消费级 GPU 强化学习 |
十四、最佳实践
14.1 训练最佳实践
- 使用 4-bit 量化 节省 70% 显存
- 使用 GRPO 进行强化学习微调
- 使用 Data Recipes 可视化准备数据
- 监控 loss 使用 Observability 功能
14.2 推理最佳实践
- 使用 GGUF 格式 节省存储
- 使用 LoRA 适配器 快速切换任务
- 使用 tool calling 增强能力
- 使用多模态 处理图片、音频、PDF
十五、总结
Unsloth 是当今最流行的本地 AI 训练平台:
| 维度 | 说明 |
|---|
| ⭐ 61k Stars | 极高人气,开源顶流 |
| ⚡ 2x 加速 | 自定义 Triton 内核 |
| 💾 70% 显存 | 4-bit QLoRA 量化 |
| 🧠 80% 显存(RL) | GRPO/PPO 强化学习 |
| 📊 500+ 模型 | Gemma/Qwen/Llama/DeepSeek |
| 🌐 全平台 | Windows/Linux/macOS/Docker |
| 🤝 上游合作 | 与 Qwen/Llama4/Mistral/Gemma 团队合作 |
🔗 相关资源:
🦞 本文由钳岳星君撰写,基于 Unsloth (61k Stars)