Sub topic 14
Building and running a customized model
This chapter assumes you have Ollama installed, can run ollama pull and ollama run, and have read the previous chapter on writing a Modelfile. Here you build a model from a Modelfile, run it, check it, and remove it.
What a customized model is
A customized model is a new entry in your local model list. It points at the same weights as its base model and adds your parameters and system prompt. Creating one does not copy the multi-gigabyte weight file, so it is fast and uses little extra disk space.
Step 1: Write the Modelfile
Save this as a file named Modelfile in your current directory.
FROM llama3.2
PARAMETER temperature 0.3
PARAMETER num_ctx 4096
SYSTEM You are a concise assistant that answers in at most three sentences.FROM names the base model. If llama3.2 is not yet on your machine, run ollama pull llama3.2 first.
Step 2: Build and run it
ollama create concise-assistant -f Modelfile
ollama run concise-assistantollama create reads the Modelfile and registers a model named concise-assistant. ollama run then starts a chat with it, exactly as with any downloaded model.
Step 3: Check the result
Ask a question that normally gets a long answer, such as "How does a car engine work?" The reply should be short, because the system prompt limits it to three sentences.
Then inspect the model:
ollama list
ollama show concise-assistantollama list now includes concise-assistant. ollama show prints its parameters and system prompt, so you can confirm that your settings were applied.
Using it from the API
A custom model works anywhere a normal model name works. Pass its name in the model field.
curl http://localhost:11434/api/chat -d '{
"model": "concise-assistant",
"messages": [{"role": "user", "content": "What is quantization?"}],
"stream": false
}'The baked-in system prompt and parameters apply automatically. A system message in the request is added on top of them, and options set in the request can override the Modelfile values.
Changing and removing it
To change the model, edit the Modelfile and run ollama create concise-assistant -f Modelfile again. The new settings replace the old ones under the same name. To delete it, run ollama rm concise-assistant. This removes only your custom entry. The base model stays installed.
Common errors
pull model manifest: file does not exist: The model named inFROMis not in the library, or the tag is misspelled. Check the name on the model library.couldn't connector connection refused: The server is not running. Start it and try again.- Behavior does not change: You edited the Modelfile but did not run
ollama createagain. The Modelfile is only read at creation time.
Exercise
You change PARAMETER temperature 0.3 to 0.8 in your Modelfile and run ollama run concise-assistant. The model behaves the same as before. Why, and what do you do?
Show answer
The Modelfile is read only when you run ollama create, so the stored model still has temperature 0.3. Run ollama create concise-assistant -f Modelfile again, then run the model.
Exercise
You run ollama rm concise-assistant. Is llama3.2 also deleted?
Show answer
No. The custom model only references the base model's weights, so removing it deletes only your custom entry. llama3.2 stays installed.