A Modelfile is a small text file that turns any Ollama model into your own custom model. With a few lines you can give it a permanent system prompt, a bigger context window, a fixed temperature, example conversations, or point it at a GGUF file you downloaded from Hugging Face.
This guide explains every Modelfile instruction in plain English, then walks you through 6 ready-to-copy examples: a custom assistant, a coding helper, a long-context model, a GGUF import, a Safetensors import and a model you can share on ollama.com. All commands and parameters are checked against Ollama’s official docs as of November 2026.
- What: a plain text file (usually named
Modelfile) that describes a custom model: base model, parameters, system prompt and more. - Build it:
ollama create my-model -f Modelfile, thenollama run my-model. - Only FROM is required. Other instructions: PARAMETER, SYSTEM, TEMPLATE, MESSAGE, LICENSE, REQUIRES, CAPABILITY.
- See any model’s Modelfile:
ollama show --modelfile llama3.2. - Import GGUF:
FROM ./model.gguf. Ollama does not quantize GGUF on import, so download the quant you want. - Most useful parameters:
num_ctx,temperature,top_p,repeat_penalty,stop,seed.
What Is an Ollama Modelfile?
Think of a Modelfile as a recipe. It does not contain the model weights. It says “start from this model, then apply these settings”. Ollama reads the recipe and saves the result as a new model name on your computer.
The new model shares the base model’s weights on disk, so a custom model built on llama3.2 takes almost no extra space.
Common reasons to write one:
- You are tired of pasting the same system prompt every time.
- You want a bigger context window by default for long documents.
- You want lower temperature for factual answers, or higher for creative writing.
- You downloaded a GGUF file and want to run it in Ollama.
- You want to share a tuned assistant with your team or on ollama.com.
New to Ollama? Install it first with our Ollama guide.
Quick Start: Your First Custom Model in 2 Minutes
- Pull a base model if you do not have one:
ollama pull llama3.2 - Create a folder for your model, for example
my-assistant. - Create a file named
Modelfile(no extension) in that folder. On Windows, turn on “File name extensions” in Explorer so it is not saved asModelfile.txt. - Paste this into the file:
FROM llama3.2 PARAMETER temperature 0.6 PARAMETER num_ctx 8192 SYSTEM """You are a friendly tech helper. Explain things in simple English, use short paragraphs and numbered steps.""" - Open a terminal in that folder and run:
ollama create my-assistant -f Modelfile - Run it:
ollama run my-assistant - Check it is listed:
ollama list
Your custom model now works everywhere Ollama does: the terminal, the Ollama app, Open WebUI and the Ollama API.
Every Modelfile Instruction Explained
The format is simple: one instruction per line, then its arguments. Lines starting with # are comments. Instructions are not case sensitive and can be in any order, but putting FROM first keeps it readable.
| Instruction | Required? | What it does | Example |
|---|---|---|---|
| FROM | Yes | Base model: a library model, a GGUF file or a Safetensors folder | FROM qwen3 |
| PARAMETER | No | Default run settings such as temperature and context size | PARAMETER num_ctx 8192 |
| SYSTEM | No | The system message (the model’s standing instructions) | SYSTEM """You are...""" |
| TEMPLATE | No | Full prompt template in Go template syntax | See below |
| MESSAGE | No | Example conversation turns to guide replies | MESSAGE user Hi |
| LICENSE | No | Licence text shipped with the model | LICENSE """MIT...""" |
| REQUIRES | No | Minimum Ollama version needed | REQUIRES 0.14.0 |
| CAPABILITY | No | Adds a capability to a GGUF or MLX model | CAPABILITY decision |
FROM
Three forms work:
FROM llama3.2orFROM qwen3:8b: a model from the Ollama library (it is pulled if missing).FROM ./my-model.gguf: a GGUF file, as an absolute path or relative to the Modelfile.FROM /path/to/safetensors/folder: a folder with Safetensors weights for a supported architecture.
For split GGUF files, keep the original shard names and use a wildcard: FROM ./model-*.gguf.
SYSTEM
Use triple quotes for multi-line prompts. This is the instruction most people need: role, tone, format rules and things to avoid.
TEMPLATE
The template wraps your messages in the exact tokens the model was trained on. Library models already include the right one, so do not touch TEMPLATE unless you import a raw GGUF that chats badly. Variables are {{ .System }}, {{ .Prompt }} and {{ .Response }}. A ChatML-style example:
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
"""
MESSAGE
Roles are system, user and assistant. A few examples teach the model your preferred answer style (few-shot prompting) without retraining.
PARAMETER Reference Table
| Parameter | What it controls | Default | Good starting value |
|---|---|---|---|
| num_ctx | Context window (tokens the model can see) | Server default 4096 (set in Ollama’s FAQ; older docs say 2048) | 8192 for documents, if you have the memory |
| temperature | Creativity vs consistency | 0.8 | 0.2 to 0.4 facts and code, 0.7 to 1.0 creative |
| top_k | How many likely tokens are considered | 40 | 20 to 40 |
| top_p | Probability cut-off used with top_k | 0.9 | 0.8 to 0.95 |
| min_p | Alternative to top_p; drops very unlikely tokens | 0.0 | 0.05 |
| repeat_penalty | How hard repetition is punished | 1.0 (off) | 1.1 |
| repeat_last_n | How far back to check for repeats | 64 | 64 to 256 |
| seed | Random seed for repeatable output | 0 | Any fixed number, e.g. 42 |
| stop | Text that ends generation (repeatable) | From the model | stop "User:" |
| num_predict | Max tokens per reply | -1 (no limit) | 512 to 2048 |
| draft_num_predict | Speculative draft tokens per step when a draft model is available | 4 for separate draft models | Leave default; 0 disables drafting |
Bigger num_ctx uses more VRAM or RAM. If a model suddenly runs slowly after you raise it, part of it has spilled to the CPU. Check our VRAM guide before going above 16K on an 8 GB card.
6 Copy-Paste Modelfile Examples
1. Simple-English explainer
FROM llama3.2
PARAMETER temperature 0.5
SYSTEM """Explain any topic to a 15-year-old. Use short sentences, one example, and end with a one-line summary."""
2. Coding helper with low randomness
FROM qwen3:8b
PARAMETER temperature 0.2
PARAMETER num_ctx 16384
PARAMETER num_predict 2048
SYSTEM """You are a senior developer. Answer with working code first, then a short explanation. Point out bugs and security issues."""
3. Long-document summariser
FROM llama3.2
PARAMETER num_ctx 32768
PARAMETER temperature 0.3
SYSTEM """Summarise the pasted text in 5 bullet points, then list any dates, numbers and names."""
4. Strict JSON extractor using MESSAGE examples
FROM llama3.2
PARAMETER temperature 0
SYSTEM """Extract the product name and price from the text. Reply with JSON only."""
MESSAGE user The new Pixel phone costs $799.
MESSAGE assistant {"product": "Pixel phone", "price": 799}
MESSAGE user Get the Kindle for 109 dollars today.
MESSAGE assistant {"product": "Kindle", "price": 109}
5. Reproducible test model
FROM llama3.2
PARAMETER seed 42
PARAMETER temperature 0.7
Same prompt, same seed and same settings give the same answer, which is handy for comparing prompts.
6. A custom GGUF from Hugging Face
FROM ./Qwen3-4B-Instruct-Q4_K_M.gguf
PARAMETER num_ctx 8192
PARAMETER temperature 0.6
SYSTEM """You are a helpful assistant."""
The file name here is an example; use the name of the GGUF you downloaded.
Import a GGUF or Safetensors Model
- Download the file from the model’s Hugging Face page. Pick the quantization you want (Q4_K_M is a good default). Ollama does not quantize GGUF files during import.
- Put the GGUF in the same folder as your Modelfile.
- Write the Modelfile with
FROM ./your-file.gguf. For split files useFROM ./your-file-*.gguf. - Build:
ollama create my-gguf -f Modelfile - Test:
ollama run my-gguf. If the replies are messy or never stop, add the right TEMPLATE andstopparameters from the model card.
For Safetensors weights, point FROM at the folder (or use FROM . if the Modelfile sits in that folder) and run ollama create my-model. The architecture must be one Ollama supports.
Want to make your own quant first? Use llama-quantize from llama.cpp.
Share Your Model on ollama.com
- Sign up at ollama.com. Your username becomes part of the model name.
- Add your Ollama public key on the ollama.com Keys settings page. The page shows where the key file lives on your system.
- Rename the model to include your username:
ollama cp my-assistant yourname/my-assistant - Push it:
ollama push yourname/my-assistant - Others run it with
ollama run yourname/my-assistant.
Respect the base model’s licence before sharing. Add it with the LICENSE instruction if needed.
Make a Model Without a File (/set and /save)
You can also tune a model inside a chat and save it:
ollama run llama3.2
>>> /set system You are a pirate who explains Linux commands.
>>> /set parameter temperature 0.9
>>> /set parameter num_ctx 8192
>>> /save pirate-linux
>>> /bye
ollama run pirate-linux
This is great for quick experiments. For anything you will keep, a Modelfile is better because you can edit it, version it in Git and rebuild it any time.
Update, Copy and Delete Custom Models
| Task | Command |
|---|---|
| See a model’s Modelfile | ollama show --modelfile my-assistant |
| Change settings | Edit the Modelfile, then run ollama create my-assistant -f Modelfile again (it overwrites) |
| Copy under a new name | ollama cp my-assistant my-assistant-v2 |
| List models | ollama list |
| Unload from memory | ollama stop my-assistant |
| Delete | ollama rm my-assistant |
Deleting a custom model does not delete the base model it was built on. To clean up everything, see how to delete Ollama models.
Tip: copy a library model’s Modelfile as a starting point with ollama show --modelfile qwen3 > Modelfile, then replace the long FROM blob path with FROM qwen3 as the generated comment suggests.
Troubleshooting
| Problem | Fix |
|---|---|
| “no FROM line” or similar error | Every Modelfile needs FROM. Check the file is not saved as Modelfile.txt |
| “file does not exist” for a GGUF | Use an absolute path, or a path relative to the Modelfile, not to your terminal |
| Replies never stop or show odd tokens | Wrong template: copy TEMPLATE and stop values from the model card or a similar library model |
| System prompt ignored | Small models follow prompts weakly; keep it short and add MESSAGE examples |
| Model got slow after raising num_ctx | It no longer fits in VRAM; lower num_ctx or use a smaller quant |
| Changes not showing | Re-run ollama create after every edit; restart the chat |
| Push rejected | Model name must start with your ollama.com username, and your public key must be added |
| Open WebUI shows old settings | Open WebUI can override parameters per chat; check its model settings |
My Take
Modelfiles are the easiest upgrade in Ollama. Five lines give you an assistant that always answers the way you like, with the context size your work needs.
Start with FROM, SYSTEM and two PARAMETER lines, keep your Modelfiles in a folder or Git repo, and only touch TEMPLATE when a GGUF import misbehaves. Next, plug your custom model into code with LangChain and Ollama or your editor with Cursor local models.
FAQ
What is a Modelfile in Ollama?
A text file that defines a custom model: its base model, default parameters, system prompt, template and example messages. You build it with ollama create.
Where do I save the Modelfile?
Anywhere. Pass its path with -f, for example ollama create my-model -f ./Modelfile. The name “Modelfile” is a convention, not a rule.
Does a custom model use extra disk space?
Very little when built from a library model, because it reuses the base weights. Importing a new GGUF adds that file’s size.
How do I set the context length in a Modelfile?
Add PARAMETER num_ctx 8192 (or any size your memory allows). You can also set a server-wide default with the OLLAMA_CONTEXT_LENGTH environment variable.
Can I fine-tune a model with a Modelfile?
No. A Modelfile changes settings and prompts, not the weights. To change weights you fine-tune elsewhere, then import the result.
Can Ollama quantize my GGUF?
Not during GGUF import. Download the quant you want, or quantize it first with llama.cpp’s llama-quantize.
How do I see the Modelfile of an existing model?
Run ollama show --modelfile model-name.



