Export Your Fine-Tune to GGUF for Ollama
Your fine-tune is trapped. Right now your model exists in exactly one place: a folder on a cloud server you pay for by the hour. Stop paying and the model is gone. This is the companion tutorial to Train Your Own AI, Episode 3: merge your LoRA adapter, quantize the result to GGUF, and run it on your laptop via Ollama. Every command below follows current, verifiable tooling.
What you actually have: the adapter is not a model
When training finished in episode one, Unsloth handed you two things: the base Qwen 7B model, unchanged, and a tiny LoRA adapter holding only your fine-tune's changes. That split is deliberate: training an adapter instead of the full model is what made the run fit on one rented GPU. But the adapter is a diff, not a model. No inference tool can load it alone: not llama.cpp, not Ollama, not anything. Step zero of every export is the merge: bake the adapter's changes back into the base weights and you get one complete, standalone model.
Then comes GGUF, the single-file format from the llama.cpp project. It packs the merged weights, the tokenizer, and the chat-template metadata into one portable file. Copy it, share it, load it anywhere.
The size ladder: why quantization works
A 7B model in 16-bit precision is about 14 GB. That needs a serious GPU just to load. Quantization fixes it with rounding: weights are stored as 16-bit decimals, far more precision than inference needs. Round them down and the model shrinks dramatically, with barely measurable quality loss.
- F16: ~14 GB, full quality, GPU required.
- Q8_0: ~7.2 GB, quality so close to the original you won't find the difference.
- Q4_K_M: ~4.7 GB, the sweet spot: runs on a laptop CPU, benchmark penalty under 2% perplexity.
- Q2_K: ~2.7 GB, phone-sized, but the quality degradation is visible.
For your fine-tune, start at Q4_K_M. It is the default the entire ecosystem converged on: portable enough to carry anywhere, good enough that you'll never notice the rounding.
Path A: the Unsloth one-liner
If you trained with Unsloth, the export is one function call. save_pretrained_gguf merges your adapter into the base model, converts to GGUF, and quantizes in a single shot on the same rented GPU you trained on. It even writes a starter Modelfile for Ollama into the output folder:
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="outputs/lora_adapter",
load_in_4bit=False, # merge in full precision
)
# one call: merge + convert + quantize
model.save_pretrained_gguf(
"qwen-ft-gguf", tokenizer,
quantization_method="q4_k_m",
)
# or several sizes at once:
# quantization_method=["q4_k_m", "q8_0", "f16"]
Five minutes of compute and the folder it produces is everything you need to leave the cloud behind. Copy it to your laptop, and the rental can end.
Path B: manual merge, then llama.cpp
Didn't train with Unsloth, or want your hands on every dial? The manual path is three steps with the raw llama.cpp tools:
# 1. merge the adapter into the base weights
model.save_pretrained_merged(
"qwen-ft-merged", tokenizer,
save_method="merged_16bit",
)
# 2. convert to full-precision GGUF
python convert_hf_to_gguf.py qwen-ft-merged \
--outfile qwen-ft-f16.gguf --outtype f16
# 3. quantize to the shippable file
./llama-quantize qwen-ft-f16.gguf \
qwen-ft-q4_k_m.gguf Q4_K_M
Same endpoint as the one-liner, with full control at every step, and this path unlocks the quality trick below, which the one-liner can't do.
The quality dial: imatrix calibration
Not all weights matter equally. A small fraction are load-bearing: round those aggressively and quality collapses. The importance matrix tells the quantizer which weights to protect. Build it by running your full-precision GGUF over a few hundred megabytes of representative text (Wikipedia is the standard choice) and recording which weights activate hardest:
# calibrate: learn which weights matter most
./llama-imatrix -m qwen-ft-f16.gguf \
-f wiki.txt -o qwen-ft.imatrix
# quantize with the importance matrix
./llama-quantize --imatrix qwen-ft.imatrix \
qwen-ft-f16.gguf qwen-ft-q4_k_m.gguf Q4_K_M
The payoff is real: 10-20% better perplexity at 4 bits, and at 3 bits and below it's the difference between a usable model and garbage. One extra command plus a calibration run: free quality.
Run it with Ollama
Ollama is the simplest local runtime: one background service, one registry of models on your machine. It needs a Modelfile, a tiny recipe naming the file and how to talk to it. The FROM line points at your GGUF. The TEMPLATE line is critical: it must match your base model's chat format exactly, because it turns your raw prompt into the token sequence the model was trained to expect (Qwen's im_start format here, with an im_end stop token):
# Modelfile
FROM ./qwen-ft-q4_k_m.gguf
TEMPLATE """<|im_start|>system
{{ .System }}<|im_end|>
<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
{{ .Response }}<|im_end|>"""
PARAMETER stop "<|im_end|>"
ollama create qwen-ft -f Modelfile
ollama run qwen-ft
Ask it something from your fine-tune's domain first. If the training stuck, you'll hear your dataset talking back, from your own laptop, with no server running anywhere.
Three export pitfalls
- Wrong chat template = gibberish. Get the template wrong and the model babbles, and you'll blame the quantization for a templating mistake. Match it to your base model exactly.
- Shipping the adapter unmerged. Nothing outside the training world can load a bare LoRA adapter. Merge first, always.
- Tiny quants without imatrix. Below Q4_K_M without calibration, quality falls off a cliff. Calibrate, or stay at Q4_K_M and up.
What it costs, and what's next
Merge the adapter, quantize to Q4_K_M, and your fine-tune lives in a five-gigabyte file that runs anywhere. When you're ready to train the next one, check the FlopSource directory for the cheapest 4090-class box today. Prices move daily.
Next in the series: RAG vs. fine-tuning: which one your task actually needs, and the honest test that decides it.
Find the cheapest GPU for your next run
Live pricing, hardware specs, and availability across 30 GPU clouds, neoclouds, and bare-metal providers.
Open the Directory