Contents

Ollama Modelfile Tutorial: Build Your Own Custom Model

Modelfile is Ollama's model configuration file. The concept is similar to a Dockerfile: start with an existing model, add your own system prompt and parameters, and package it under a new model name.

Your first Modelfile: Traditional Chinese assistant

Create a plain text file named Modelfile:

FROM qwen3:8b

SYSTEM """
You are a professional and friendly assistant.
- Always respond in Traditional Chinese using wording common in Taiwan.
- Keep answers concise. Give the conclusion first, then add an explanation.
- If you are unsure about something, say so directly. Do not make things up.
"""

PARAMETER temperature 0.6
PARAMETER num_ctx 8192

Create and run it:

ollama create tw-assistant -f ./Modelfile
ollama run tw-assistant

tw-assistant will appear in ollama list, and you can use this name directly with the API and other tools. Creating a new model does not copy the original model's weight files, so it takes up almost no additional space.

Instruction reference

InstructionRequiredDescription
FROM✓Base model, which can be a model name or a local GGUF / safetensors file
SYSTEMSystem prompt
PARAMETERInference parameter
MESSAGEPreloaded example conversation
TEMPLATEPrompt template (usually inherited from the base model and does not need to be changed)
LICENSELicense terms

Wrap multiline text in """.

Common parameters

ParameterDescriptionRecommendation
temperatureRandomness. Lower values are more consistent; higher values are more creativeFactual Q&A: 0.2~0.5; creative writing: 0.8~1.0
num_ctxContext length (tokens), which determines how much content the model can "remember"Increase it when summarizing long documents, but this uses more memory
top_pSelect only from tokens whose cumulative probability is within pUsually keep the default
top_kSelect only from the k most likely tokensUsually keep the default
repeat_penaltyReduces the chance of repeated contentIf answers keep repeating, increase it to 1.1
num_predictMaximum number of tokens to generate; -1 means unlimitedSet this when you need to control the length
stopStop generation when this text is encounteredYou can set multiple values
seedRandom seed; with a fixed seed, the same input produces the same outputUse this for testing

The base model may already have some parameters set (such as a recommended temperature). You can check them with ollama show model --parameters. Values you set in the Modelfile override them.

Provide examples with MESSAGE

Example conversations can effectively demonstrate the response format you want:

FROM qwen3:8b

SYSTEM You are an assistant that rewrites conversational sentences as formal business correspondence. Output only the rewritten sentence.

MESSAGE user We can't make it to the meeting tomorrow.
MESSAGE assistant Our organization will be unable to attend the meeting tomorrow due to unforeseen circumstances. We apologize for any inconvenience.
MESSAGE user The items have already been shipped.
MESSAGE assistant The items have been shipped. Please confirm receipt.

Start from an existing model's Modelfile

ollama show qwen3:8b --modelfile > Modelfile

The output file contains the complete TEMPLATE and parameters. Modify only the parts you need. Note that the output's FROM may be a local file path. Changing it back to a model name (for example, FROM qwen3:8b) makes it easier to maintain.

Import a GGUF model from Hugging Face

Hugging Face has many models in GGUF format, including various fine-tuned versions. After downloading the .gguf file:

FROM ./my-finetuned-model.Q4_K_M.gguf
ollama create my-model -f Modelfile

Ollama can also run GGUF repositories on Hugging Face directly:

ollama run hf.co/username/repository-name
ollama run hf.co/username/repository-name:Q4_K_M

Import safetensors

When creating a model from safetensors weights, you can quantize it during creation:

ollama create my-model -f Modelfile --quantize q4_K_M

(See the official documentation for supported architectures.)

Save quickly in interactive mode

You don't need to write a Modelfile. After adjusting the settings in a conversation, save the model directly:

>>> /set system "You are an experienced Python instructor. Respond in Traditional Chinese and include example code."
>>> /set parameter temperature 0.4
>>> /save python-tutor

Manage custom models

ollama list                      # Custom models also appear here
ollama rm tw-assistant           # Delete (does not affect the base model)
ollama show tw-assistant --modelfile

Put the Modelfile under Git version control so team members can build exactly the same model with ollama create.

Updated October 12, 2026