Ollama allows you to create customized models by defining a Modelfile.
A Modelfile acts as a blueprint that defines:
FROM)PARAMETER)TEMPLATE, SYSTEM)👉 In practice, this behaves similarly to a Dockerfile for LLMs.
A Modelfile consists of instructions:
INSTRUCTION arguments
Key instructions:
| Instruction | Purpose |
|---|---|
FROM |
Base model (required) |
PARAMETER |
Runtime tuning |
TEMPLATE |
Prompt structure |
SYSTEM |
Default system prompt |
ADAPTER |
LoRA / fine-tuning |
LICENSE |
Metadata |
([docs.ollama.com][1])
ollama show --modelfile qwen3.5:9b > Modelfile-qwen3.5:9b
Example output:
FROM /usr/share/ollama/.ollama/models/blobs/sha256-dec52a44...
TEMPLATE {{ .Prompt }}
RENDERER qwen3.5
PARSER qwen3.5
PARAMETER presence_penalty 1.5
PARAMETER temperature 1
PARAMETER top_k 20
PARAMETER top_p 0.95
Example:
FROM qwen3.5:9b
# large context window
PARAMETER num_ctx 131072
# max output tokens
PARAMETER num_predict 8192
# Qwen tuning
PARAMETER temperature 0.6
PARAMETER top_p 0.8
PARAMETER top_k 20
PARAMETER min_p 0
PARAMETER presence_penalty 0.1
PARAMETER repeat_penalty 1.1
PARAMETER repeat_last_n 64
# deterministic output
PARAMETER seed 42
ollama create qwen3.5-9b-bot -f Modelfile
ollama run qwen3.5-9b-bot
PARAMETER temperature 0.6
PARAMETER top_p 0.8
PARAMETER top_k 20
PARAMETER num_ctx 131072
PARAMETER num_predict 8192
PARAMETER repeat_penalty 1.1
PARAMETER repeat_last_n 64
Defines how prompts are structured:
TEMPLATE {{ .Prompt }}
Advanced templates can include:
TEMPLATE """
{{ if .System }}{{ .System }}{{ end }}
{{ .Prompt }}
"""
Defines model personality:
SYSTEM You are a strict Linux consultant.
👉 This is the most effective way to:
PARAMETER temperature 0
PARAMETER seed 42
Use for:
PARAMETER temperature 1.2
PARAMETER top_p 0.95
Use for:
PARAMETER num_ctx 131072
PARAMETER num_predict 4096
Use for:
PARAMETER temperature 0.5
PARAMETER repeat_penalty 1.2
PARAMETER top_k 20
Use for:
FROM best practicePrefer:
FROM qwen3.5:9b
instead of blob paths:
FROM /usr/share/ollama/.ollama/models/blobs/sha256-...
👉 More portable and stable
Creating models:
ollama create ...
FROM llama3
PARAMETER temperature 0.7
PARAMETER num_ctx 4096
SYSTEM You are a helpful assistant.
ollama show --modelfile <model> > Modelfile
vi Modelfile # adjust parameters
ollama create <new-name> -f ./Modelfile
ollama run <new-name>
ollama create builds a new model layer, not new weights[1]: https://docs.ollama.com/modelfile"Modelfile Reference - Ollama"