Skip to main content

Unsloth Integration

Unsloth provides optimized training for LoRA fine-tuning, significantly reducing training time and memory usage.

Requirements

Unsloth only works with SFT training (--trainer sft or --trainer default). DPO, ORPO, PPO, and other trainers are not supported.

Supported Model Architectures

Unsloth is optimized for specific model families: Other model architectures will fall back to standard training with a warning.

Quick Start

Parameters

Python API

With Quantization

Unsloth works with int4 and int8 quantization for reduced memory usage:

How It Works

When Unsloth is enabled and requirements are met:
  1. Uses FastLanguageModel from Unsloth library for optimized model loading
  2. Applies optimized gradient checkpointing (use_gradient_checkpointing="unsloth")
  3. Automatically configures LoRA target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
  4. Integrates with PEFT for efficient adapter training

Fallback Behavior

If Unsloth cannot be used, training continues with standard transformers/PEFT:
  • Unsloth not installed: Warning logged, continues without Unsloth
  • Unsupported model type: Warning logged, continues without Unsloth
  • Unsupported trainer: Unsloth not applied (only SFT supported)

ShareGPT Mapping

Use --use-sharegpt-mapping to preserve ShareGPT format instead of converting:

Next Steps

LoRA/PEFT

Efficient fine-tuning techniques

Quantization

Reduce memory with quantization