Setting Parameters like Context Length and Temperature in Ollama Models

10 Aug 2025 - tsp
Last update 10 Aug 2025
Reading time 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.

Viewing and Editing a MODELFILE

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:

You 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:

For full parameter details, see Ollama’s MODELFILE documentation.

Example: Increasing Context and Temperature

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.

Example: Custom System Prompt and LoRA Adapter

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

Considerations

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:


Data protection policy

Dipl.-Ing. Thomas Spielauer, Wien (webcomplains389t48957@tspi.at)

This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/

Valid HTML 4.01 Strict Powered by FreeBSD IPv6 support