[PR #635] [CLOSED] do not reload model when only prompt template changes #41518

Closed
opened 2026-04-24 21:23:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/635
Author: @BruceMacD
Created: 9/28/2023
Status: Closed

Base: mainHead: brucemacd/no-reload-model


📝 Commits (4)

  • c303f39 do not reload model when only prompt template changes
  • 5961866 remove embeddings
  • bf45332 do not change for model file created from base
  • 26293ca PR feedback

📊 Changes

4 files changed (+123 additions, -57 deletions)

View changed files

📝 llm/llama.go (+1 -1)
📝 server/images.go (+39 -22)
📝 server/images_test.go (+76 -0)
📝 server/routes.go (+7 -34)

📄 Description

Say I have 2 models, both are based on llama2, but they have different prompts.

FROM llama2
TEMPLATE """
you are a dog
"""

and

FROM llama2
TEMPLATE """
you are a cat
"""

If I am building something that swaps requests between these models a lot our current logic will re-load the models every time, even though the only thing changing is the prompt template.

This change adds a runner digest which uses only fields relevant to running the model to determine if a running model should be swapped out.

As a side-effect, this also fixes the /show modelfile to actually show the library model name, rather than the file name when using a base model.

ollama run mistral
>>> /show modelfile
# Modelfile generated by "ollama show"
# To build a new Modelfile based on this one, replace the FROM line with:
# FROM mistral:latest

FROM registry.ollama.ai/library/mistral:latest
TEMPLATE """[INST] {{ .Prompt }} [/INST]
"""
SYSTEM """"""
  • Also remove calculation on system prompt from template that makes sure the first system command is kept via num_keep. This isn't needed with our new prompt templates.

Resolves #337


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/635 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 9/28/2023 **Status:** ❌ Closed **Base:** `main` ← **Head:** `brucemacd/no-reload-model` --- ### 📝 Commits (4) - [`c303f39`](https://github.com/ollama/ollama/commit/c303f39fa79514a1b045bb6c1fb8be1766cd7d0b) do not reload model when only prompt template changes - [`5961866`](https://github.com/ollama/ollama/commit/59618665410343ff75c1e85a03078c975f9061bc) remove embeddings - [`bf45332`](https://github.com/ollama/ollama/commit/bf45332a41ed2850c116ffca47f6143a557ef216) do not change for model file created from base - [`26293ca`](https://github.com/ollama/ollama/commit/26293cadae0462326a6242a6255d707b4c11e550) PR feedback ### 📊 Changes **4 files changed** (+123 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `llm/llama.go` (+1 -1) 📝 `server/images.go` (+39 -22) 📝 `server/images_test.go` (+76 -0) 📝 `server/routes.go` (+7 -34) </details> ### 📄 Description Say I have 2 models, both are based on llama2, but they have different prompts. ``` FROM llama2 TEMPLATE """ you are a dog """ ``` and ``` FROM llama2 TEMPLATE """ you are a cat """ ``` If I am building something that swaps requests between these models a lot our current logic will re-load the models every time, even though the only thing changing is the prompt template. This change adds a `runner digest` which uses only fields relevant to running the model to determine if a running model should be swapped out. As a side-effect, this also fixes the `/show modelfile` to actually show the library model name, rather than the file name when using a base model. ``` ollama run mistral >>> /show modelfile # Modelfile generated by "ollama show" # To build a new Modelfile based on this one, replace the FROM line with: # FROM mistral:latest FROM registry.ollama.ai/library/mistral:latest TEMPLATE """[INST] {{ .Prompt }} [/INST] """ SYSTEM """""" ``` - Also remove calculation on system prompt from template that makes sure the first system command is kept via `num_keep`. This isn't needed with our new prompt templates. Resolves #337 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-24 21:23:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#41518