Modelfiles and custom models

Ollama · Practical · 12 min

Custom models package a base model with your settings and instructions, so every app gets the same behaviour.

A Modelfile is a small text file describing a model: which base model to use and which settings and instructions to add. It is like a recipe: the ingredients (weights) stay the same, but you fix the seasoning.

FROM qwen3:8b
PARAMETER temperature 0.2
PARAMETER num_ctx 16384
SYSTEM You are a support assistant for Acme. Answer in at most 3 sentences.

Build and use it:

ollama create acme-support -f Modelfile
ollama run acme-support

The new model shares the base model's weights on disk, so it takes almost no extra space.

Instructions (not case-sensitive, any order):

  • FROM (required): the base model, or a path to model files (see the importing lesson).
  • PARAMETER name value: default settings such as temperature, num_ctx, top_p, top_k, repeat_penalty, seed, num_predict and stop. Repeat stop for several stop sequences.
  • SYSTEM: the system prompt. Use """ around multi-line text.
  • MESSAGE role content: example conversation turns (user, assistant), a built-in few-shot example.
  • TEMPLATE: the prompt format the model was trained with. Usually inherited from the base; rarely edit it.
  • LICENSE: license text. REQUIRES: a minimum Ollama version.

Inspect any model's recipe with ollama show qwen3:8b --modelfile.

Settings sent in an API request override the Modelfile's defaults, so the Modelfile sets sensible defaults while apps can still adjust them. Keep Modelfiles in version control next to the code that uses them.

Example

# File: Modelfile
FROM qwen3:8b
PARAMETER temperature 0.2
PARAMETER num_ctx 16384
PARAMETER stop "<END>"
SYSTEM """You are Acme's support assistant.
Answer in at most 3 sentences. If unsure, say you will escalate."""
MESSAGE user Where is my order?
MESSAGE assistant I can check that. Please share your order number (it starts with A-).

# Terminal
ollama create acme-support -f Modelfile
ollama run acme-support "My parcel is late."
# I'm sorry about the delay. Please share your order number (it starts with A-) ...
ollama show acme-support --modelfile      # view the full recipe

Remember

  • FROM + PARAMETER + SYSTEM (+ MESSAGE) define a custom model
  • ollama create NAME -f Modelfile builds it; it reuses the base weights
  • API request options override Modelfile defaults

Watch out for

  • Copying a TEMPLATE from another model family, which breaks the prompt format and produces garbled answers.

Check yourself

  1. You build three custom models from the same 5 GB base model. How much extra disk space do they roughly use?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.ollama.com/modelfile