Unsloth
Unsloth adapts model loading and training operations around the PyTorch, Transformers, PEFT and TRL ecosystem. Follow a supervised LoRA or QLoRA run to see where the base model stays frozen, where gradients flow, and why specialized kernels help.
Training examples
A tokenizer turns formatted examples into token IDs. The collator builds batches, attention masks and labels. Label masking determines which positions contribute to supervised loss; a wrong chat template or mask changes the task the model learns.
- Training examples Trainer loopBatched tensors
One pass through the system.
Select a step to highlight the components involved in the diagram.
Why it is built this way.
Memory savings come from several different places
Quantization shrinks stored base weights; LoRA shrinks trainable state; checkpointing reduces saved activations. They solve different problems. Longer sequences or larger microbatches can still exhaust device memory, and checkpointing adds recomputation.
Fast paths have compatibility boundaries
Fused operations work for supported models and settings. Changing adapter targets, precision, hardware or library versions may change the selected implementation. Validate numerical behavior and throughput on the actual training configuration.
Smaller updates still need good evaluation
Adapter rank is a capacity choice, not a quality guarantee. Data leakage, incorrect labels and overfitting remain possible. Keep a held-out set and compare the exported artifact against the in-training model.
Read the implementation.
unsloth/models/loader.pyStart at model loading, architecture selection and compatibility checks.
unsloth/kernels/fast_lora.pyFollow custom autograd functions for low-rank projection operations.
unsloth/save.pyInspect saving, merging and supported export paths.
Go deeper with the official docs
- Unsloth: fine-tuning LLMs
- Unsloth: LoRA hyperparameters and tradeoffs
- Unsloth model implementation
- Unsloth low-rank autograd implementation
Educational diagrams, synthesized from the linked project documentation. Components and boundaries vary by version and deployment.