पाठ 10 / 30

Modelfile Basics: FROM, SYSTEM and PARAMETER

यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।

Write a Modelfile that bakes a system prompt and parameters into a named custom model.

लेखक: · 15 साल से वेब डेवलपर

A recipe for a derived model

A Modelfile is Ollama's plain-text recipe for building a model, similar in spirit to a Dockerfile. Each line is an instruction. FROM names the base: an existing Ollama model (FROM llama3.2) or a path to a GGUF file. SYSTEM sets the default system message that frames every conversation. PARAMETER sets defaults such as temperature, num_ctx (context window), top_p, stop sequences and seed. TEMPLATE overrides the prompt template, MESSAGE adds example turns for few-shot behaviour, ADAPTER applies a LoRA fine-tune, and LICENSE records terms. Running ollama create <name> -f Modelfile builds a new model entry. Importantly, it reuses the base weights; only the small configuration layers are new, so a custom model costs almost no extra disk. This is the cleanest way to give a team one shared, versioned assistant configuration.

A DSA tutor model

Save as Modelfile, then build and run it.

cat > Modelfile <<'EOF'
FROM llama3.2
PARAMETER temperature 0.3
PARAMETER num_ctx 8192
SYSTEM """You are a patient DSA tutor for college students.
Explain with small examples and always state the time complexity."""
EOF

ollama create dsa-tutor -f Modelfile
ollama run dsa-tutor "How does binary search work?"

Building a custom model

Creating a model layers configuration on top of existing weights. The stages, in order: base model weights -> Modelfile instructions -> ollama create -> named custom model.

4 connected stages, left to right: base model weights, Modelfile instructions, ollama create, named custom model.
Figure 4.1: base model weights -> Modelfile instructions -> ollama create -> named custom model

Inspect before you override

Run ollama show llama3.2 --modelfile first. It prints the base model's own template, stop tokens and parameters. Copy what you need instead of guessing, because a wrong TEMPLATE silently breaks chat formatting.

त्वरित जाँच: What does `ollama create dsa-tutor -f Modelfile` do with the base model's weights?

  • It copies and re-quantizes all the weights
  • It reuses the existing weight layers and adds only the new configuration
  • It fine-tunes the weights on the SYSTEM prompt
  • It uploads them to the Ollama library
Answer

It reuses the existing weight layers and adds only the new configuration — Ollama stores models as layers. A derived model points to the same weight blob and adds small layers for system prompt, parameters and template. No training happens.