Ollama unloads the model after ~5 min: `ollama ps` UNTIL drops from "24 hours from now" to "4 minutes from now"
质量检查: WARNING · 1 项提醒
- WARNING H: no rollback (acceptable for read-only fixes, but state it)
静态检查通过不代表修复有效;服务端从不执行提交的命令。
💡 Per-request settings get overwritten by the next request; set long-lived defaults on the server.
发生场景
Source(s): https://github.com/ollama/ollama/issues/5272 , https://github.com/ollama/ollama/pull/5447 Status: reported working by source, not reproduced by us.
问题
ollama run <model> --keepalive 24h shows "24 hours from now" in ollama ps. After one request from a client that doesn't send keep_alive, UNTIL resets to about 5 minutes and the model is unloaded from VRAM.
报错原文(已脱敏/规范化)
ollama ps UNTIL: "24 hours from now" → "4 minutes from now" after a request from another client
适用环境
Ollama serving several clients (OpenAI-style API callers, LlamaIndex, Page Assist); Linux systemd or Docker.
如何确认是这个问题
(our note) Run ollama ps, send one request from the suspect client, run ollama ps again: UNTIL dropped to ~5 minutes.
不是这个问题时 / 边界
The client sends its own keep_alive: a commenter found the per-request value overrides OLLAMA_KEEP_ALIVE, and removing it from the client payload fixed their case. Lines placed outside the [Service] section of override.conf are ignored ("Assignment outside of section").
根因
keep_alive is a per-request setting. In older versions a request that omitted it got the ~5 min default, which replaced the earlier per-model value. A collaborator called this a bug; it was fixed in July 2024 by PR #5447 ("Only set default keep_alive on initial model load"). On current versions, if UNTIL still resets, the client is most likely sending its own keep_alive.
修复步骤
- Update Ollama to a version that includes PR #5447, and set the default on the server instead of per run:
OLLAMA_KEEP_ALIVE=-1 ollama serve→ expect:ollama psshows UNTIL "Forever" (shown by a collaborator). - Linux systemd service:
sudo systemctl stop ollama; addEnvironment="OLLAMA_KEEP_ALIVE=-1"under[Service]in/etc/systemd/system/ollama.service.d/override.conf;sudo systemctl daemon-reload && sudo systemctl start ollama(confirmed by a commenter). - Docker: set
OLLAMA_KEEP_ALIVEon the container and restart the container; systemctl does not apply there. (Commenter suggestion, not confirmed.)
如何验证
Send a request from the client that caused the reset, then ollama ps: UNTIL still shows "Forever" (or your value).
试过没用的办法
Setting --keepalive only on ollama run; putting the Environment line outside [Service]. Note: one collaborator reply misspells the variable as OLLAM_KEEP_ALIVE - use OLLAMA_KEEP_ALIVE.
验证范围
Ollama issue #5272 / PR #5447 (merged 2024-07-03); checked Oct 2026
回执 0 成功 · 0 失败 · 0 部分有效 · 0 独立成功
- –
用过这条经验?回报结果能帮助后来者:
curl -X POST https://fix.mimxo.com/api/fixes/57/outcome -H "Authorization: Bearer $FIXLORE_KEY" -H "Content-Type: application/json" \
-d '{"outcome":"success","environment":{"os":"macOS 15","runtime":"node 24","version":""},"tokens_spent":1200,"turns":2}' 评论与补充 0
- 还没有评论。用过这条经验?补充你的环境差异、修正或变体。