skip to content

When an Ollama Modelfile builds FROM a library model, which settings does `ollama create` inherit, replace or merge from the base?

level: middleimportance: should knowfreq 9%

answer

  1. new manifest over shared blobs
  2. singletons replaced, lists differ
  3. parameters merged key by key
  4. one stop line replaces the whole list
  5. read the base with ollama show first

basics

~20 s

ollama create keeps the base's weights and every layer you omit. A new TEMPLATE, SYSTEM or MESSAGE set replaces the base's; PARAMETER merges key by key, so one stop line replaces the whole stop list; LICENSE appends.

solid answer

~40 s

`ollama create` starts from the base model's manifest — weight blob, template, system prompt, parameters, messages, licence — and overlays only what your Modelfile states. `TEMPLATE` and `SYSTEM` are singletons: give one and it replaces the base's, omit it and the base's is inherited. `MESSAGE` lines replace the base's seeded turns as a set. `PARAMETER` values are merged key by key: your `temperature` overrides the base's while its other keys survive — but a key replaces the old value wholesale, so a single `PARAMETER stop` line throws away every stop string the base carried. `LICENSE` texts are appended. The weights are shared by digest, not copied. So run `ollama show --modelfile` on the base first and copy its `stop` lines when you add your own.

code

dockerfile · 9 lines
dockerfile
FROM llama3.2
SYSTEM """You are the support assistant. Finish every answer with: Ticket closed."""
# stop is replaced as a whole list, so restate the base's stops first
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
PARAMETER stop "<|reserved_special_token"
# then add your own
PARAMETER stop "Ticket closed."

go deeper

for a junior

Recall that anything your Modelfile leaves out is inherited from the FROM model, and that the base's weights are reused rather than copied.

for a middle

Explain the overlay rule: TEMPLATE and SYSTEM replace, MESSAGE replaces as a set, PARAMETER merges by key, LICENSE appends, and why one stop line drops the base's stops.

for a senior

Treat ollama show --modelfile on the base and on the result as part of the build, so a replaced stop list or a missing template is caught before users see runaway answers.

for a principal

Decide how far team models should inherit from library bases: thin overlays track upstream fixes on re-pull, while restating template and stops pins behaviour at the cost of maintaining them.

## What `ollama create` actually builds An Ollama model is a **manifest**: a list of content-addressed **layers** (blobs named by their `sha256` digest) plus a config. One layer is the weights; others hold the prompt template, the system prompt, the parameters as JSON, the seeded messages and licence texts. A Modelfile that says `FROM llama3.2` does not edit `llama3.2`. `ollama create` reads the base's manifest, keeps its layers, overlays what the Modelfile states, and writes a **new manifest** under the new name. The weight layer is reused by digest, so the create output shows `using already created layer sha256:...` for it. The overlay rule in the 0.35 source is short: **singleton values are replaced, parameters are merged, and licences are appended**. The details are where people get caught. ## The rule, instruction by instruction | Instruction in your Modelfile | Effect on the base's setting | If you omit it | |---|---|---| | `TEMPLATE` | replaces the base's template (checked as a valid Go template first) | base template inherited | | `SYSTEM` | replaces the base's system prompt | base system prompt inherited | | `MESSAGE` (any number) | your turns replace the base's seeded turns as a whole | base turns inherited | | `PARAMETER key value` | merged by key: your keys override, the base's other keys stay | base parameters inherited untouched | | `LICENSE` | appended after the base's licence texts | base licences inherited | | `REQUIRES` | your minimum version replaces the base's | base value inherited | Two consequences follow directly: - **Replacement is per setting, not per file.** A Modelfile with only `SYSTEM` keeps the base's template, stop strings and options; you do not restate them. - **Merging is per key, not per value.** `stop` is a list-valued key. Several `PARAMETER stop` lines in *your* file build one list, and that list replaces the base's list entirely. ## The stop-list trap A library chat model usually ships stop strings that end a turn at its end-of-turn markers; `ollama show --modelfile llama3.2` prints several `PARAMETER stop` lines. Suppose you add one line, `PARAMETER stop "Ticket closed."`, to end answers at a phrase. Merging by key replaces the inherited `stop` list with your single string. The model has lost the stop strings the base relied on, and any turn boundary they were catching is no longer cut off: generations can run past the end of the assistant's turn, with the model writing the next user turn itself. Whether it shows depends on the model and the engine, and nothing errors either way — the output just looks broken. The fix is mechanical: 1. Run `ollama show --modelfile` (or `ollama show --parameters`) on the base. 2. Copy every inherited `PARAMETER stop` line into your Modelfile. 3. Add your own `stop` line after them and run `ollama create` again. Why a model needs those particular markers is a chat-template subject; what matters here is that create will not keep them for you once you touch `stop`. ## Other edges worth knowing - **An empty SYSTEM does not clear the base's.** Create replaces the system layer only when the new value is non-empty; to neutralise an inherited system prompt, write a replacement one. - **MESSAGE is all or nothing.** Adding one example turn discards the base's seeded turns; restate any you want to keep. - **A bad TEMPLATE fails the build.** The template is parsed as a Go template before the manifest is written, so a syntax error is reported by create instead of surfacing at chat time. - **Rebuilding under the same name** writes a fresh manifest; by default the old one's layers that no other model uses are pruned. Clients calling the name see the new settings on their next request. ## How to check what you built - `ollama show --modelfile your-model` shows the merged result: the inherited template, the combined parameters and the system prompt that will actually apply. - `ollama show --parameters your-model` is the quick check that the stop strings you expected are still there. Reading the result rather than the source file is the habit that catches the stop-list trap before a user does. In an interview, the strong answer is the rule — inherit what you omit, replace singletons, merge parameters by key, append licences — followed by the one place where merging by key bites.

  • Your Modelfile sets only `PARAMETER temperature 0.2` — what happens to the base's stop strings?
    They survive. Parameters merge key by key, so setting `temperature` overrides only that key and the inherited `stop` list stays as the base defined it. The list is lost only when your Modelfile sets `stop` itself, because then your list replaces the base's for that key.
  • How do you confirm after `ollama create` which template and stop strings the new model really carries?
    Run `ollama show --modelfile your-model` or `ollama show --parameters your-model`. Both print the merged result stored in the new manifest — inherited template, combined parameters, system prompt — rather than your source file, so a stop list that was silently replaced shows up immediately.

Like a container image built on a base image: the new image reuses the base's big layers untouched and adds a thin layer of its own settings, and a setting you redeclare wins over the base's.

  • A Modelfile with only SYSTEM loses the base model's template
  • Adding one PARAMETER stop appends it to the base's stop list
  • FROM llama3.2 copies the weights into a new blob
  • An empty SYSTEM line clears the inherited system prompt
  • ollama create edits the base model's manifest in place

Assumes Ollama 0.35.0: the overlay rule (singletons replaced, parameters merged by key, licences appended) is read from that release's create code.