AI Hints
Home›Fine-Tuning LLMs Tutorial›Sharing and Serving Your Model
Fine-Tuning LLMs · Lesson 99 of 120

GGUF and Ollama

Run it on a laptop.

⏱ 2 min read▶ Video at 2:32:09🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

What if you want your model to run on a normal laptop, with no GPU, and no Python at all? That's what GGUF, and Ollama, are for.

  • A normal laptop
  • No GPU, no Python
  • GGUF and Ollama

What is GGUF?

GGUF is a single file format for language models. It holds the weights, the tokenizer, and the settings, all in one file. It's used by llama dot c p p, a fast engine written in C plus plus. And the weights are usually quantized, to four or five bits, to make them small.

keyvalue
GGUFone file: weights + tokenizer
Enginellama.cpp, in C++
Usuallyquantized, 4–5 bits
Runs onCPUs, Macs, laptops

From merged model to Ollama

Here are the steps. First, a script from the llama dot c p p project converts our merged model to GGUF. Then llama quantize shrinks it to four bits. Then a model file tells Ollama which file to use, with our system message, and temperature zero. Finally, ollama create builds the model, and ollama run chats with it.

commands.shbash
# 1. convert the merged model to GGUF (script from the llama.cpp project)
python convert_hf_to_gguf.py upload/merged --outfile tickets-f16.gguf

# 2. quantize it to 4 bits
llama-quantize tickets-f16.gguf tickets-q4.gguf Q4_K_M

# 3. describe it for Ollama, then create and run it
cat > Modelfile <<'END'
FROM ./tickets-q4.gguf
SYSTEM "Read the customer's message. Reply with JSON: the intent and the book."
PARAMETER temperature 0
END
ollama create tickets -f Modelfile
ollama run tickets 'Is Dune in stock?'

Important

Two things to remember. Merge the adapter first, because GGUF conversion needs a full model. And always use the same system message, and chat template, that you trained with. Then test the quantized model with your scorer, because four bits can lose some accuracy.

keyvalue
Firstmerge the adapter
Keepsame system message
Templatesame chat template
Testscore the 4-bit model

Summary

Let's recap. GGUF is one file, for llama dot c p p. Merge, convert, and quantize. Ollama runs it with a simple model file. And re-test after quantizing. Next, making inference faster.

Key takeaways
  • Merge → GGUF → quantize
  • Ollama Modelfile
  • Re-test after quantizing
Next up: Fast Inference — quicker answers