
Unsloth Tutorial: Fine-Tune a Small LLM on Free Colab and Run It in Ollama
Also available in Hindi: यह लेख हिंदी में पढ़ें
Fine-tuning used to need expensive GPUs. Unsloth, an open-source library, lets you train a small model on the free T4 GPU in Google Colab and then run the result on your own computer with Ollama. Hugging Face's TRL docs describe it as up to 2x faster with up to 80% less VRAM, and it works with TRL's SFTTrainer.
Before you start: do you need fine-tuning?
Fine-tuning teaches a model a style, format or narrow task. To answer from your documents, start with RAG. The Unsloth docs say the dataset matters most: usually two columns, question and answer, and well-structured data beats a pile of raw documents.
The workflow
- Open an Unsloth notebook from its docs and connect the free T4 GPU. Run every cell in order. Do not skip any.
- Load a 4-bit instruct model. Unsloth suggests beginners start with a small instruct model such as Llama 3.1 (8B). Instruct models need less data than base models.
load_in_4bit = Trueis QLoRA, which cuts memory use about 4x. - Add LoRA adapters. LoRA trains small extra matrices instead of every weight. The notebooks use
r = 16andlora_alpha = 16. - Train.
max_steps = 60is a quick test. For a real run, usenum_train_epochs = 1. Unsloth recommends 1 to 3 epochs. More can overfit. - Export and run (below).
Read the training loss
A loss around 0.5 to 1.0 is often a good sign, though it depends on your data. If it does not fall, change your settings or data. If it drops to 0, the model is probably memorizing, so check it on examples it has not seen.
Save it for Ollama
The LoRA adapter alone is about 100 MB. For Ollama or llama.cpp, export GGUF:
model.save_pretrained_gguf("my_model", tokenizer, quantization_method = "q4_k_m")
q4_k_m is a popular, smaller choice. q8_0 keeps more quality but the file is bigger. Export can take 5 to 10 minutes. Unsloth's Ollama notebook also creates the Modelfile with your chat template, so you can run ollama create and then ollama run.
Prefer no code? Unsloth Studio is a newer web interface for training and exporting.
Already running models locally? Read where Ollama stores models, the best tools to run LLMs locally and our LM Studio local API guide, or see the Unsloth tool page.
Sources
- Fine-tuning LLMs guide, Unsloth Docs
- Google Colab, Unsloth Docs
- How to fine-tune Llama-3 and use it in Ollama, Unsloth Docs
- Saving to GGUF, Unsloth Docs
- Unsloth integration, Hugging Face TRL Docs
- Importing a model, Ollama Docs
FAQ
Is Unsloth free?
The open-source library is free. You can train on Colab's free T4 GPU, Kaggle or your own GPU.
Which model should a beginner use?
A small instruct model, such as Llama 3.1 (8B) in 4-bit.
How many epochs should I train?
Test with 60 steps, then train 1 to 3 epochs. More can overfit.
Can I run the fine-tuned model offline?
Yes. Export to GGUF and load it in Ollama or llama.cpp.