C.W.K.
Stream
Lesson 05 of 05 · published

Modelfile Configuration

~24 min · ollama, modelfile

Level 0Downloader
0 XP0/41 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

What a Modelfile is

A Modelfile is to Ollama what a Dockerfile is to Docker: a small text file that derives a customized model from a base. You bake in a system prompt, default parameters, few-shot examples, even a LoRA adapter, then build with ollama create. The result is callable as a regular model: ollama run my-assistant.

Instructions you'll actually use

InstructionRequired?Purpose
FROMYesBase model name, GGUF file path, or safetensors directory
SYSTEMOptionalSystem prompt baked into every chat
PARAMETEROptionaltemperature, num_ctx, top_p, top_k, repeat_penalty, seed, stop, num_predict, min_p
TEMPLATEOptionalGo template for prompt formatting (advanced — usually inherit from FROM)
ADAPTEROptionalApply a LoRA adapter (safetensor or GGUF)
MESSAGEOptionalFew-shot examples (role: user / assistant / system)

When a Modelfile pays off

  • You're building a single product around a model and want one consistent system prompt across all callers.
  • You want a stable num_ctx default (Ollama's defaults often undershoot; 8192 or 16384 is a more practical baseline).
  • You want named variants — my-coder, my-summarizer, my-translator — that share the same base model but differ in system prompt and parameters.

When to skip it

If you're going to send a system prompt with every API call anyway, a Modelfile adds a layer to maintain. The Modelfile pays off when you want to name a configuration so callers don't have to know it.

Code

A real Modelfile·bash
# Save as Modelfile (no extension)
FROM qwen2.5:7b-instruct

PARAMETER temperature 0.6
PARAMETER num_ctx 8192
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.05

SYSTEM """You are a senior Python engineer. Respond with:
1. A clear plan in 3 bullets.
2. Production-grade code with type hints and docstrings.
3. One failure mode worth knowing.
Keep replies under 300 words unless the user asks for more."""

MESSAGE user How do I read a JSON file safely?
MESSAGE assistant Plan: open with explicit encoding, parse, handle decode errors.
Build, run, iterate·bash
# Build the derived model
ollama create py-senior -f ./Modelfile

# Run it
ollama run py-senior "How do I parallelize a loop?"

# Inspect what was baked in
ollama show py-senior --modelfile

# Iterate — edit the Modelfile, rebuild
$EDITOR Modelfile
ollama create py-senior -f ./Modelfile

# Remove when done experimenting
ollama rm py-senior

External links

Exercise

Write a Modelfile that derives a pippa-summarizer from your favorite 7B model. Bake in a system prompt that asks for a 3-bullet summary plus a 1-sentence verdict, set temperature to 0.3, and num_ctx to 16384. Build it, run it on a 2-paragraph essay, and iterate the system prompt twice based on what you don't like.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.