10 Aug 2025 - tsp
Last update 10 Aug 2025
2 mins
This guide explains (or rather takes a note for myself) how to modify parameters for Ollama models - such as context length, temperature, and more - using a custom MODELFILE
. Many models available via Ollama come with relatively small context windows (often around 4k tokens) and fixed sampling parameters like a temperature of 0.8. By creating your own model definition, you can override these defaults.
You can view the MODELFILE
of any installed model with:
ollama show --modelfile <model-name>
A MODELFILE
gives you control over various aspects of a model. You can set core parameters such as:
num_ctx
, which determines the context size in tokenstemperature
, which controls output randomness (with 0 producing deterministic responses and higher values making them more creative)seed
, which fixes the random seed to produce reproducible outputYou can also adjust sampler behavior through options like top_p
, min_p
, maximum prediction length, and repetition penalty. In addition, you can define prompts and adapters by specifying:
TEMPLATE
that matches the training formatSYSTEM
prompt to shape the models behaviorADAPTER
to attach LoRA adapters that expand or change the model’s capabilitiesFor full parameter details, see Ollama’s MODELFILE documentation.
Suppose you want to boost creativity and allow much longer context on qwen2.5-coder:32b
:
FROM qwen2.5-coder:32b
PARAMETER num_ctx 128000
PARAMETER temperature 1.2
Save this as MY_MODELFILE
and run:
ollama create qwen2.5-coder:32b_128k --file MY_MODELFILE
This creates a new model variant locally without duplicating the base weights.
You can also set a system prompt and add a LoRA adapter:
FROM llama3.1:70b
PARAMETER num_ctx 32768
SYSTEM "You are a concise assistant specializing in data analysis."
ADAPTER /path/to/finance-lora
num_ctx
increases VRAM/RAM usage massively and increases inference time.TEMPLATE
, ensure it matches the model’s original formatting to avoid degraded performance. Usually you want to use the same model as has been used during training.By customizing a MODELFILE
, you can fine-tune how Ollama models behave for your specific tasks, balancing performance, creativity, and context size to your needs.
This article is tagged:
Dipl.-Ing. Thomas Spielauer, Wien (webcomplains389t48957@tspi.at)
This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/