Sub topic 15
Importing your own GGUF weights
This chapter assumes you can write a Modelfile and run ollama create, and that you know what quantization means. You will import a model file that is not in the Ollama library.
What GGUF is
GGUF is a single-file format for model weights. The file holds the tensors, the tokenizer, and metadata such as the architecture. Many community models on Hugging Face are published as GGUF files, usually one file per quantization level, for example Q4_K_M or Q8_0. Ollama can use these files directly.
The file name tells you the quantization. A smaller number of bits means a smaller file and lower quality, as in the quantization chapter.
The import workflow
Step 1: Point FROM at the file
In a Modelfile, FROM accepts a path to a GGUF file as well as a model name. A relative path is resolved against the Modelfile's directory.
FROM ./my-model.Q4_K_M.gguf
PARAMETER temperature 0.3
PARAMETER num_ctx 4096
SYSTEM You are a concise assistant.Step 2: Add the chat template
A GGUF import does not carry Ollama's prompt template. Without a correct TEMPLATE, an instruction-tuned model often gives rambling or repetitive output, because the prompt does not match the format it was trained on. Find the template on the model's Hugging Face page. This example is for a model that uses the ChatML format:
FROM ./my-model.Q4_K_M.gguf
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>"""
PARAMETER stop "<|im_end|>"
SYSTEM You are a concise assistant.The stop parameter makes generation end at the model's end-of-turn token. Use the tokens your model was trained with. Do not copy the ChatML tokens unless the model uses ChatML.
Step 3: Create and run
ollama create my-model -f Modelfile
ollama list
ollama run my-modelollama create copies the weights into the Ollama model store. The original .gguf file is no longer needed afterward, so you can delete it to save disk space. ollama show my-model --modelfile prints the stored Modelfile so you can check the template.
Common errors
| Symptom | Likely cause |
|---|---|
| Output never stops or repeats the prompt | Missing or wrong `stop` parameter or `TEMPLATE` |
| Replies ignore the system prompt | Template has no `.System` section |
| `ollama create` cannot find the file | Wrong relative path in `FROM` |
| Out-of-memory error at run time | Quantization too large for your RAM or GPU memory. Pick a smaller file. |
Exercise
You imported a GGUF chat model. It answers, but it keeps generating fake "user" turns after its reply. Which two Modelfile settings do you check first?
Show answer
Check the TEMPLATE, which must match the model's trained chat format, and the stop PARAMETER, which must name the model's end-of-turn token. Then recreate the model with ollama create.