Module 5 Lesson 4: Runtime Parameters
Fine-tuning the engine. A dictionary of PARAMETER options to control speed, creativity, and memory.
Runtime Parameters: The Control Panel
In Module 4, we learned the theory of why parameters matter. Now, we will look at how to actually apply them in a Modelfile. These PARAMETER commands allow you to control the "statistics" of how the model picks the next word.
1. Temperature (Creativity)
- Range: 0.0 to 2.0 (Default ~0.8)
- Low (0.1): Predictable. Good for code, math, and data extraction.
- High (1.2): Randomized. Good for poetry, creative writing, and ideas.
- Modelfile:
PARAMETER temperature 0.2
2. Top-K and Top-P (The Filters)
These and "Temperature" work together to narrow down the model's choices.
- Top-K: Tells the model to only look at the top
Kmost likely words. (PARAMETER top_k 40) - Top-P: Tells the model to only look at a group of words whose total probability equals
P. (PARAMETER top_p 0.9)
Tip: Usually, you only need to change Temperature. Ollama’s default Top-K/P settings are excellent for most users.
3. Context Window (num_ctx)
As discussed in Module 4, this is the "memory size."
- Small (2048): Saves RAM, very fast.
- Standard (8192): Good for general chat.
- Large (32768+): For analyzing long documents.
- Modelfile:
PARAMETER num_ctx 16384
4. Penalty Parameters
Sometimes models get "stuck" in a loop, repeating the same word ("the the the...").
- Repeat Penalty: How hard to punish the model for repeating itself. (
PARAMETER repeat_penalty 1.1) - Presence Penalty: Encourages the model to talk about new topics.
5. Stop Sequences (stop)
Important for developers! You can tell Ollama to stop generating text as soon as it sees a specific word.
Example: If you want the model to generate a Python function and then stop without explaining it, you might look for the final ``` block.
`PARAMETER stop " ``` "`
6. Seed (For Predictability)
If you want the model to give the exact same answer every time you run the same prompt, set the seed to a specific number.
PARAMETER seed 42
Summary Cheat Sheet
| Parameter | Default | Use Case |
|---|---|---|
temperature | 0.8 | Change "Vibe" vs "Fact" |
num_ctx | 4096 (usually) | Increase working memory |
stop | None | Control API response limits |
num_gpu | Auto | Force model to CPU (0) or GPU (1) |
repeat_last_n | 64 | How far back to check for repetition |
Key Takeaways
- Parameters go inside the Modelfile after the
SYSTEMprompt. - Temperature is the most commonly changed setting.
- num_ctx is the most important setting for hardware stability.
- Use Stop sequences to keep your outputs clean for automation.
- The
PARAMETERkeyword is followed by the name and the value.