HOW-TO · INF

How to create a Modelfile to customize model parameters

intermediate10 minBy Eruo Fredoline
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Ollama installed, base model already pulled to local library

What this does

Creates a named model variant with customized inference parameters, system prompts, and template overrides using a declarative Modelfile. After this guide a tailored version of the base model will be available for specialized use cases.

Steps

  1. Create a Modelfile in a working directory. The FROM directive specifies which base model to extend.

    cat > Modelfile << 'EOF'
    FROM llama3.2
    PARAMETER temperature 0.3
    PARAMETER num_ctx 8192
    PARAMETER top_p 0.9
    SYSTEM """You are a coding assistant. Always include code examples."""
    EOF
    

    Low temperature (0.3) produces deterministic output; higher values increase creativity.

  2. Create the custom model variant. Registers the customized model under a new name.

    ollama create coding-llama -f Modelfile
    

    Expected output: transferring model data followed by success.

  3. Run the custom model and verify behavior. Launches the variant with the baked-in parameters.

    ollama run coding-llama "Write a hello world in Python"
    

    Expected output: A response that includes a code example.

  • Record the local run evidence. Save the exact command, runtime or package version, model name if applicable, and observed output so the result can be reproduced later.

Verification

ollama show coding-llama
# Expected: output includes PARAMETER block with temperature 0.3 and num_ctx 8192

Common failures

  • unable to locate model - FROM references a model not in the local library; run ollama pull <name> first.
  • syntax error in Modelfile - Missing newline after a directive or unbalanced quotes; check the file character by character.
  • system prompt ignored - Some model architectures require a TEMPLATE directive before SYSTEM will take effect.
  • duplicate model name - A model with the target name already exists; choose a different name or delete the existing one.

Related guides

RELATED GUIDES