Unsloth 是一个非常受欢迎的开源 LLM 微调工具,以”2-5x 更快、减少 70% 显存占用”著称。近日,Unsloth 官方宣布与 NVIDIA 达成合作,训练速度进一步提升 25%,同时新增了对 Qwen3、Llama 4、Gemma 3 等最新模型的支持。
项目地址
- 官网:https://unsloth.ai/
- GitHub:https://github.com/unslothai/unsloth
- 博客文章:https://unsloth.ai/blog/nvidia-collab
- 文档:https://docs.unsloth.ai/
与 NVIDIA 合作的意义
训练速度提升 25%
Unsloth 此前已经比原生 PyTorch 训练快 2-5 倍,这次与 NVIDIA 的合作进一步优化了底层计算:
- 针对 NVIDIA GPU 的 CUDA 内核优化
- 更好的内存管理和数据流水线
- 利用 NVIDIA 的 Tensor Core 加速
- 减少训练过程中的内存碎片
对于已经在用 NVIDIA GPU(尤其是 4090、A100、H100)的用户来说,这次更新意味着同样的硬件可以更快地完成微调任务。
新增模型支持
Unsloth 现在支持以下最新模型:
- Qwen3:通义千问最新一代开源模型
- Llama 4:Meta 最新发布的开源大模型
- Gemma 3:Google 最新开源模型
- DeepSeek:深度求索系列模型
- Mistral:法国 AI 公司的开源模型
支持的微调方法包括 LoRA、QLoRA、全量微调(full fine-tuning)。
快速上手
安装
# 推荐使用 pip 安装
pip install unsloth
# 或者从 GitHub 安装最新版
pip install git+https://github.com/unslothai/unsloth.git
基本用法
from unsloth import FastLanguageModel
# 加载模型(4-bit 量化,节省显存)
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="unsloth/Qwen3-8B-bnb-4bit",
max_seq_length=2048,
dtype=None, # 自动检测
load_in_4bit=True,
)
# 添加 LoRA 适配器
model = FastLanguageModel.get_peft_model(
model,
r=16,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
lora_alpha=16,
lora_dropout=0,
bias="none",
use_gradient_checkpointing="unsloth",
random_state=3407,
)
训练
from trl import SFTTrainer
from transformers import TrainingArguments
trainer = SFTTrainer(
model=model,
tokenizer=tokenizer,
train_dataset=dataset,
dataset_text_field="text",
max_seq_length=2048,
args=TrainingArguments(
per_device_train_batch_size=2,
gradient_accumulation_steps=4,
warmup_steps=5,
max_steps=60,
learning_rate=2e-4,
fp16=not torch.cuda.is_bf16_supported(),
bf16=torch.cuda.is_bf16_supported(),
logging_steps=1,
output_dir="outputs",
),
)
trainer.train()
适合谁用?
- AI 应用开发者:需要微调模型来适配特定任务
- 站长和开发者:想训练自己的 AI 客服、知识库助手
- 数据科学家:需要在特定领域数据上微调模型
- AI 爱好者:想在消费级显卡上体验 LLM 微调
硬件要求
| 微调方式 | 最低显存 | 推荐显卡 |
|---|---|---|
| QLoRA (4-bit) | 6GB | RTX 3060、RTX 4060 |
| LoRA (16-bit) | 16GB | RTX 4090、A100 |
| 全量微调 | 24GB+ | A100、H100 |
注意事项
- Unsloth 目前主要支持 NVIDIA GPU,AMD GPU 的支持还在开发中
- QLoRA 微调对显存要求低,但效果可能不如全量微调
- 微调数据的质量比数量更重要——少量高质量数据往往比大量低质量数据效果好
- 微调后的模型记得保存和备份,避免丢失训练成果
- 具体支持的模型列表和参数以官方文档为准
简评
Unsloth 是目前开源 LLM 微调工具中最好用的之一。它把复杂的 CUDA 优化和内存管理封装成了简单的 API,让普通开发者也能在消费级显卡上微调大模型。这次与 NVIDIA 的合作进一步提升了性能,值得关注。
如果你有微调 LLM 的需求(比如训练自己的 AI 客服、特定领域的知识库助手),Unsloth 绝对是首选工具。
来源
- Unsloth × NVIDIA 合作公告 — Unsloth 官方博客
- Unsloth GitHub 仓库











Timothy Gowers Blog – A Recent Experience with ChatGPT 5.5 Pro


暂无评论内容