Skip to main content

Synopsis

ollama create MODEL
ollama create MODEL -f MODELFILE

Description

The create command builds a custom model from a Modelfile. A Modelfile is a blueprint that defines:
  • Base model to build from
  • Custom system prompts
  • Model parameters (temperature, context length, etc.)
  • Additional files (adapters, weights)
This allows you to customize existing models or create entirely new ones.

Arguments

MODEL
string
required
Name for your new modelExamples:
  • mymodel
  • myusername/custom-assistant
  • code-helper:latest

Options

--file
string
default:"Modelfile"
Short: -fPath to the Modelfile. Defaults to Modelfile in the current directory.
ollama create mymodel -f ./custom/Modelfile
--quantize
string
Short: -qQuantization level for the model (reduces size and memory usage)Options: q4_K_M, q4_K_S, q5_K_M, q5_K_S, q8_0
ollama create mymodel -f Modelfile -q q4_K_M
--experimental
boolean
default:"false"
Enable experimental safetensors model creation from local weights
ollama create mymodel --experimental

Modelfile Syntax

A Modelfile contains instructions for building a model:
# Base model
FROM llama3.2

# System prompt
SYSTEM You are a helpful coding assistant specialized in Python.

# Parameters
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER top_k 40

# Template
TEMPLATE """{{ .System }}

User: {{ .Prompt }}
Assistant: """

Available Instructions

FROM
string
required
Base model to build from. Can be:
  • Model name: FROM llama3.2
  • Local model: FROM ./model-weights
  • Model with tag: FROM mistral:7b-instruct
SYSTEM
string
System prompt that sets the behavior and context for the model
SYSTEM You are a helpful assistant that speaks like a pirate.
TEMPLATE
string
Chat template that formats prompts. Uses Go template syntax.
TEMPLATE """{{ .System }}

{{ .Prompt }}"""
PARAMETER
string
Set model parameters:
  • temperature (float): Randomness (0.0-2.0)
  • top_p (float): Nucleus sampling (0.0-1.0)
  • top_k (int): Top-k sampling
  • num_ctx (int): Context window size
  • repeat_penalty (float): Penalty for repetition
PARAMETER temperature 0.8
PARAMETER num_ctx 4096
LICENSE
string
License information for the model
LICENSE """MIT License

Copyright (c) 2024..."""
ADAPTER
path
Path to LoRA adapter files
ADAPTER ./fine-tune-adapter.bin

Examples

Basic Custom Model

Create a Modelfile:
Modelfile
FROM llama3.2

SYSTEM You are a helpful assistant named Bob.

PARAMETER temperature 0.8
Create the model:
ollama create bob
Run it:
ollama run bob

Coding Assistant

Modelfile
FROM codellama:7b

SYSTEM """
You are an expert programmer. Always:
- Write clean, well-commented code
- Follow best practices
- Explain your reasoning
"""

PARAMETER temperature 0.2
PARAMETER top_p 0.9

TEMPLATE """### System:
{{ .System }}

### User:
{{ .Prompt }}

### Assistant:
"""
ollama create code-assistant -f Modelfile

Quantized Model

Create a smaller, faster version:
ollama create small-model -f Modelfile -q q4_K_M

From Local Weights

Create from a directory containing model weights:
Modelfile
FROM ./local-model-weights

SYSTEM You are a helpful assistant.
ollama create custom-model -f Modelfile

With LoRA Adapter

Add fine-tuned adapter weights:
Modelfile
FROM llama3.2

ADAPTER ./my-lora-adapter.bin

SYSTEM This model is fine-tuned for medical advice.
ollama create medical-assistant -f Modelfile

Advanced Examples

Multi-File Model

Modelfile
FROM mistral:7b

# Load multiple adapters
ADAPTER ./adapter1.bin
ADAPTER ./adapter2.bin

SYSTEM You are a multilingual assistant.

PARAMETER temperature 0.7
PARAMETER num_ctx 8192
PARAMETER stop "User:"
PARAMETER stop "Assistant:"

Function Calling Model

Modelfile
FROM mistral:7b-instruct

SYSTEM """
You are a function-calling assistant. When the user needs data:
1. Determine which function to call
2. Format the call as JSON
3. Return the result
"""

PARAMETER temperature 0.1
PARAMETER num_predict 2048

TEMPLATE """[INST] {{ .System }}

{{ .Prompt }} [/INST]
"""

Model Creation Process

When you run ollama create, it:
  1. Parses the Modelfile
  2. Downloads base model (if needed)
  3. Processes any adapter files
  4. Combines configuration and weights
  5. Generates model manifest
  6. Saves to local model library
Output example:
gathering model components
pulling llama3.2:latest
pulling manifest
pulling model.bin: 100%
copying file adapter.bin: 100%
writing manifest
success

Quantization Levels

LevelSizeQualitySpeedDescription
q4_K_M~4 bits/weightGoodFastRecommended for most use cases
q4_K_S~4 bits/weightModerateFastestSmaller, faster, lower quality
q5_K_M~5 bits/weightBetterMediumHigher quality, larger
q5_K_S~5 bits/weightGoodMediumBalanced medium quality
q8_0~8 bits/weightBestSlowHighest quality, largest

Environment Variables

OLLAMA_HOST
string
default:"http://127.0.0.1:11434"
Ollama server address

Exit Codes

  • 0 - Success, model created
  • 1 - Error occurred (invalid Modelfile, missing base model, etc.)

Troubleshooting

Modelfile Not Found

Error: specified Modelfile wasn't found
Solution: Create a Modelfile in the current directory or use -f to specify the path:
ollama create mymodel -f /path/to/Modelfile

Invalid Model Name

Error: invalid model name
Solution: Model names must be lowercase and can contain letters, numbers, hyphens, and underscores.

Base Model Not Found

Error: model 'basemodel' not found
Solution: Pull the base model first:
ollama pull llama3.2
ollama create mymodel -f Modelfile

Server Not Running

Error: could not connect to ollama server
Solution: Start the Ollama server:
ollama serve

Best Practices

Clear System Prompts

Write specific, detailed system prompts that clearly define the model’s role and behavior.

Test Parameters

Experiment with temperature and other parameters to find the right balance for your use case.

Version Your Models

Use tags to version your models: mymodel:v1, mymodel:v2

Document Changes

Keep your Modelfile in version control and document what each version changes.

Build docs developers (and LLMs) love