Ollama Modelfile

An Ollama Modelfile is a small text file that describes a custom model: which base model to start from, a built-in system prompt, default parameters and more. It works like a Dockerfile for LLMs.

A Simple Modelfile

Create a file named Modelfile (no extension):

FROM llama3.2

SYSTEM """
You are SupportBot for an online bookshop.
Answer in at most three short sentences and be friendly.
If you do not know, say so and suggest emailing support.
"""

PARAMETER temperature 0.3
PARAMETER num_ctx 8192
(no output - this is a configuration file)

Build and Run It

ollama create supportbot -f Modelfile
ollama run supportbot "Do you ship to Canada?"
gathering model components
using existing layer sha256:...
writing manifest
success

Yes, we ship to Canada! Delivery usually takes 5-10 business days. For exact rates, email our support team.
(Sample response.)

Common Instructions

  • FROM - the base model or a path to a GGUF file (required).
  • SYSTEM - default system prompt.
  • PARAMETER - default options such as temperature, num_ctx, top_p, stop, seed.
  • TEMPLATE - the prompt template (usually inherited; rarely changed).
  • ADAPTER - apply a LoRA adapter on top of the base model.
  • MESSAGE - add example user/assistant turns as built-in few-shot examples.
  • LICENSE - attach licence text.

Key Parameters

  • temperature - randomness. 0-0.3 for factual work, 0.7-1.0 for creative writing.
  • num_ctx - context window in tokens. Larger values use more memory.
  • top_p / top_k - limit which tokens can be sampled.
  • stop - strings that end generation.
  • seed - fixed seed for more reproducible output.

Import a GGUF File

If you downloaded a model in GGUF format (for example from Hugging Face), point FROM at the file:

FROM ./my-model-Q4_K_M.gguf
PARAMETER temperature 0.7
ollama create my-model -f Modelfile
success

You can also run many Hugging Face GGUF repositories directly with ollama run hf.co/<user>/<repo>, without writing a Modelfile.

Frequently asked questions

Does a Modelfile copy the whole model?

No. Ollama stores models as layers, so a custom model reuses the base model weights and only adds the small config layers.

How do I see the Modelfile of an existing model?

Run ollama show <model> --modelfile.

How do I increase the context length in Ollama?

Set PARAMETER num_ctx in a Modelfile, use /set parameter num_ctx in the CLI, or pass options.num_ctx in an API request. More context needs more memory.