> ## Documentation Index
> Fetch the complete documentation index at: https://docs.liquid.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Unsloth

> Unsloth makes fine-tuning LLMs 2-5x faster with 70% less memory through optimized kernels and efficient memory management.

<Tip>
  Use Unsloth for faster training with optimized kernels, reduced memory usage, and built-in quantization support.
</Tip>

LFM2.5 models are fully supported by Unsloth. For comprehensive guides and tutorials, see the [official Unsloth LFM2.5 documentation](https://unsloth.ai/lfm/models/tutorials/lfm2.5).

Different training methods require specific dataset formats. See [Datasets](/lfm/fine-tuning/datasets) for format requirements for [SFT](/lfm/fine-tuning/datasets#instruction-datasets-sft) and [GRPO](/lfm/fine-tuning/datasets#prompt-only-datasets-grpo).

## Notebooks

Get started quickly with these ready-to-run Colab notebooks:

<CardGroup cols={2}>
  <Card title="SFT with LoRA" href="https://colab.research.google.com/drive/1vGRg4ksRj__6OLvXkHhvji_Pamv801Ss?usp=sharing">
    Supervised fine-tuning with parameter-efficient LoRA adapters.
  </Card>

  <Card title="GRPO with LoRA" href="https://colab.research.google.com/drive/1mIikXFaGvcW4vXOZXLbVTxfBRw_XsXa5?usp=sharing">
    Reinforcement learning with Group Relative Policy Optimization.
  </Card>

  <Card title="CPT Text Completion" href="https://colab.research.google.com/drive/10fm7eNMezs-DSn36mF7vAsNYlOsx9YZO?usp=sharing">
    Continued pre-training for text completion tasks.
  </Card>

  <Card title="CPT Translation" href="https://colab.research.google.com/drive/1gaP8yTle2_v35Um8Gpu9239fqbU7UgY8?usp=sharing">
    Continued pre-training for translation tasks.
  </Card>
</CardGroup>

## Quick Start

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTConfig

# Load model with Unsloth optimizations
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="LiquidAI/LFM2.5-1.2B-Instruct",
    max_seq_length=2048,
    load_in_4bit=True,  # Enable QLoRA for memory efficiency
)

# Apply LoRA with Unsloth's optimized gradient checkpointing
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=32,
    use_gradient_checkpointing="unsloth",  # 2x faster than default
)

# Train with TRL's SFTTrainer
trainer = SFTTrainer(
    model=model,
    args=SFTConfig(output_dir="./lfm2-unsloth", num_train_epochs=1, bf16=True),
    train_dataset=dataset["train"],
    tokenizer=tokenizer,
)
trainer.train()

# Fast inference
FastLanguageModel.for_inference(model)
```

## Key Features

* **`load_in_4bit=True`**: Enable QLoRA to reduce memory by \~4x with minimal quality loss
* **`use_gradient_checkpointing="unsloth"`**: Optimized checkpointing that's 2x faster than default
* **`FastLanguageModel.for_inference()`**: Switch to optimized inference mode after training

## Tips

* **`max_seq_length`**: Set to your expected maximum sequence length; Unsloth pre-allocates memory for efficiency
* **Target modules**: Include MLP layers (`gate_proj`, `up_proj`, `down_proj`) for better quality on smaller models
* **Batch size**: Unsloth's optimizations allow larger batch sizes; experiment to maximize GPU utilization

## Resources

* [Unsloth Documentation](https://unsloth.ai/docs)
* [Unsloth LFM2.5 Tutorial](https://unsloth.ai/lfm/models/tutorials/lfm2.5)
* [Liquid AI Cookbook](https://github.com/Liquid4All/cookbook)
