Documentation Index
Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
Use this file to discover all available pages before exploring further.
Unsloth 集成
Unsloth 为 LoRA 微调提供优化的训练,显著减少训练时间和内存使用。要求
| 要求 | 详情 |
|---|---|
| 安装 | pip install unsloth |
| 支持的训练器 | 仅 default、sft |
| 支持的模型 | llama、mistral、gemma、qwen2 |
| 平台 | 推荐 Linux |
支持的模型架构
Unsloth 针对特定模型系列进行了优化:| 架构 | 示例模型 |
|---|---|
llama | Llama 2、Llama 3、Llama 3.1、Llama 3.2 |
mistral | Mistral 7B、Mistral Nemo |
gemma | Gemma、Gemma 2 |
qwen2 | Qwen 2、Qwen 2.5 |
快速开始
参数
| 参数 | CLI 标志 | 默认值 | 描述 |
|---|---|---|---|
unsloth | --unsloth | False | 启用 Unsloth 以加快训练 |
use_sharegpt_mapping | --use-sharegpt-mapping | False | 使用 Unsloth 的 ShareGPT 映射而不是转换 |
Python API
与量化结合
Unsloth 与 int4 和 int8 量化配合使用以减少内存使用:工作原理
当启用 Unsloth 并满足要求时:- 使用 Unsloth 库的
FastLanguageModel进行优化的模型加载 - 应用优化的梯度检查点(
use_gradient_checkpointing="unsloth") - 自动配置 LoRA 目标模块:
q_proj、k_proj、v_proj、o_proj、gate_proj、up_proj、down_proj - 与 PEFT 集成以进行高效的适配器训练
回退行为
如果无法使用 Unsloth,训练将继续使用标准 transformers/PEFT:- Unsloth 未安装:记录警告,继续不使用 Unsloth
- 不支持的模型类型:记录警告,继续不使用 Unsloth
- 不支持的训练器:不应用 Unsloth(仅支持 SFT)
ShareGPT 映射
使用--use-sharegpt-mapping 保留 ShareGPT 格式而不是转换:
下一步
LoRA/PEFT
高效微调技术
Quantization
使用量化减少内存