Skip to main content
A Modelfile is the blueprint to create and share customized models using Ollama.

Table of Contents

Format

The format of the Modelfile:

Examples

Basic Modelfile

An example of a Modelfile creating a mario blueprint:
To use this:
  1. Save it as a file (e.g. Modelfile)
  2. ollama create choose-a-model-name -f <location of the file e.g. ./Modelfile>
  3. ollama run choose-a-model-name
  4. Start using the model!
To view the Modelfile of a given model, use the ollama show --modelfile command.

Instructions

FROM (Required)

The FROM instruction defines the base model to use when creating a model.

Build from existing model

Base Models

A list of available base models

Base Models

Additional models can be found at

Build from a Safetensors model

The model directory should contain the Safetensors weights for a supported architecture. Currently supported model architectures:
  • Llama (including Llama 2, Llama 3, Llama 3.1, and Llama 3.2)
  • Mistral (including Mistral 1, Mistral 2, and Mixtral)
  • Gemma (including Gemma 1 and Gemma 2)
  • Phi3

Build from a GGUF file

The GGUF file location should be specified as an absolute path or relative to the Modelfile location.

PARAMETER

The PARAMETER instruction defines a parameter that can be set when the model is run.

Valid Parameters and Values

TEMPLATE

TEMPLATE of the full prompt template to be passed into the model. It may include (optionally) a system message, a user’s message and the response from the model. Note: syntax may be model specific. Templates use Go template syntax.

Template Variables

SYSTEM

The SYSTEM instruction specifies the system message to be used in the template, if applicable.

ADAPTER

The ADAPTER instruction specifies a fine tuned LoRA adapter that should apply to the base model. The value of the adapter should be an absolute path or a path relative to the Modelfile. The base model should be specified with a FROM instruction. If the base model is not the same as the base model that the adapter was tuned from the behaviour will be erratic.

Safetensor adapter

Currently supported Safetensor adapters:
  • Llama (including Llama 2, Llama 3, and Llama 3.1)
  • Mistral (including Mistral 1, Mistral 2, and Mixtral)
  • Gemma (including Gemma 1 and Gemma 2)

GGUF adapter

LICENSE

The LICENSE instruction allows you to specify the legal license under which the model used with this Modelfile is shared or distributed.

MESSAGE

The MESSAGE instruction allows you to specify a message history for the model to use when responding. Use multiple iterations of the MESSAGE command to build up a conversation which will guide the model to answer in a similar way.

Valid roles

Example conversation

REQUIRES

The REQUIRES instruction allows you to specify the minimum version of Ollama required by the model.
The version should be a valid Ollama version (e.g. 0.14.0).

Notes

  • the Modelfile is not case sensitive. In the examples, uppercase instructions are used to make it easier to distinguish it from arguments.
  • Instructions can be in any order. In the examples, the FROM instruction is first to keep it easily readable.