RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Ollama — Installation to Mastery
  6. /Ch. 5
Ollama — Installation to Mastery

05. Modelfiles: Customizing Models

Chapter 5 of 20 · 20 min
KEY INSIGHT

Modelfiles let you create reproducible model configurations with baked-in behavior. The base model is not copied-only the instructions are stored, so changes to the Modelfile affect subsequent runs.

A Modelfile is a text file that defines how Ollama creates a model variant. You can set parameters, add system prompts, configure generation behavior, and create reusable model configurations without modifying the base weights.

Modelfile Syntax

The Modelfile format consists of instructions like FROM, PARAMETER, TEMPLATE, and SYSTEM. The FROM instruction is required-it specifies the base model.

Create a file named Modelfile (no extension):

FROM llama3.2:1b

PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 4096

SYSTEM """
You are a helpful assistant that responds in short, clear sentences.
Never use jargon. Always provide concrete examples.
"""

TEMPLATE """
{{ if .System }}
<|start_header_id|>system<|end_header_id|>
{{ .System }}<|eot_id|>
{{ end }}
<|start_header_id|>user<|end_header_id|>
{{ .Prompt }}<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
"""

Creating and Using a Custom Model

ollama create helpful-llama -f ./Modelfile
ollama run helpful-llama

The ollama create command reads the Modelfile, validates the base model exists, and registers the custom variant. The variant stores only the Modelfile configuration-not a copy of the base model. Changing the base model later affects your custom model.

Parameter Instructions

Common parameters you can set in Modelfiles:

Instruction Example Effect
PARAMETER temperature 0.7 Controls randomness. 0 = deterministic, 2 = very random
PARAMETER top_p 0.9 Nucleus sampling threshold
PARAMETER num_ctx 4096 Context window size in tokens
PARAMETER num_gpu 1 Number of GPU layers to load
PARAMETER stop "STOP" Sequence that stops generation

System Prompt via SYSTEM

The SYSTEM instruction sets a persistent system prompt. Unlike passing a system message at runtime, the SYSTEM instruction is baked into the model variant. This means every interaction with your custom model includes the system prompt automatically.

Dynamic Parameters at Runtime

You can override Modelfile parameters at runtime:

ollama run helpful-llama --param temperature 1.2

Or via the API:

curl http://localhost:11434/api/generate -d '{
  "model": "helpful-llama",
  "prompt": "Explain quantum computing",
  "options": {
    "temperature": 1.2
  }
}'

Runtime parameters override the Modelfile defaults but do not change the stored configuration.

EXERCISE

Create a Modelfile for llama3.2:1b that sets temperature to 0.3 and includes a system prompt telling the model to respond like a pirate. Create the model variant and test it with ollama run.

← Chapter 4
Multiple Models
Chapter 6 →
Ollama REST API