Troubleshooting
Should you keep an Ollama model loaded between requests?
By llamaperf · · 5 min read
Quick answer
Keep a model loaded when you return to it often and other work still has enough memory. Start with a finite timeout and compare the wait after your usual idle gap. Test switching models before choosing indefinite retention.
Start with the gap between requests
Write down when you come back
Use a normal work session to decide how long you want a model to stay loaded. Note when you finish a reply and when you send the next prompt. Include the pause while you read an answer or edit a file. A test that sends requests back to back won't answer whether the model should stay resident through lunch.
The Ollama FAQ states:
By default models are kept in memory for 5 minutes before being unloaded. (Ollama FAQ)
Try the default first. If your next request arrives after the model has left memory, compare a finite timeout that covers your usual pause. Check whether the longer timeout reduces the wait before reserving memory for an all-day session.
Define what would make you unload it
Choose a competing task you use on the same machine. Open the project or application you normally return to after chat. Record whether that work remains comfortable while the model stays loaded. Keep the result beside your latency notes. Our first-token timing article covers the separate job of measuring the wait for text.
Change the request before the server default
Try a finite timeout
The FAQ's retention controls accept duration strings such as "10m", negative values for indefinite retention, and 0 to unload after a response. A request's keep_alive overrides the server's OLLAMA_KEEP_ALIVE default. Use the request field while testing so you can see the policy beside the prompt.
Replace YOUR_INSTALLED_MODEL with your installed model's exact name. This example uses the documented finite duration:
curl http://localhost:11434/api/generate \
-H 'Content-Type: application/json' \
-d '{"model":"YOUR_INSTALLED_MODEL","prompt":"Reply with a greeting.","stream":false,"keep_alive":"10m"}'
Save the request body with the response. If you later change the server default, check what your chat application sends too. Otherwise you'll compare the setting you intended with a different setting on the wire.
Check residency after the pause
Use ollama ps to inspect loaded models, as the FAQ documents. Check immediately after the reply and again before your next request. Keep those observations with the timestamps. Don't assume that a configured timeout proves which model is resident when your application asks for it.
Compare the return visit with the whole task
Keep the loading field
The generate API reference defines load_duration as time spent loading the model in nanoseconds. Save it with total_duration and the prompt evaluation fields. Use the Ollama measurement walkthrough if you need help reading the response. A faster return visit is useful evidence only when you can see which part of the request changed.
Repeat your usual prompt after the same idle gap under each policy. Keep the prompt and context settings fixed. Then try a fresh prompt from the same task, because repeating identical text can change the prompt work. Preserve each response rather than copying only a headline time into a spreadsheet.
Include the application you left open
Return to the competing task while the model waits in memory. Write down any delay you would find annoying in daily work, and rerun the sequence after unloading. Judge the delay against what you can tolerate in daily work.
Add the chosen policy and idle interval to your performance log. If keeping the model resident barely changes the return visit, leave the simpler policy in place while you investigate the rest of the request.
Test a model change before keeping one loaded all day
Replay the handoff your tools make
Include the case where another application asks for a different model. Pause background clients during an initial test, then repeat with your normal applications open. Save the order of requests if the handoff stalls. A successful request to the resident model doesn't tell you whether another request can get its turn.
The conversation in Ollama issue 19182 describes a pending model swap with a single model slot that stalls when another request renews the resident model's keep_alive. That's a reported failure case to include in your test, rather than a prediction for every installation. Record your installed version if you hit it.
Leave an explicit release path
The documented unload request uses the same endpoint with keep_alive set to 0 and no prompt:
curl http://localhost:11434/api/generate \
-H 'Content-Type: application/json' \
-d '{"model":"YOUR_INSTALLED_MODEL","keep_alive":0}'
Wait until your intended work finishes before testing that request. Check residency afterward, then try the competing task again. Keep the finite timeout if it covers your pauses and the model handoff works. Choose indefinite retention only after that handoff and your other applications pass the same test. Put the unload command beside the saved request body so you can release the reservation when your work changes.
Frequently asked questions
How do I free VRAM after using Ollama?
Finish active work, send an empty generate request with keep_alive set to 0, then check ollama ps. Compare memory use before and after.
How do I keep the model running between prompts?
Set a finite keep_alive on the native API request and check whether the model is still resident after your usual pause. Test indefinite retention only if other work remains comfortable.
Why does another model wait while the current one still answers?
Save the request order and server logs. The linked GitHub issue describes this symptom during a pending model swap, so include background clients that renew retention in your reproduction.
Should I set keep_alive on every request or on the server?
Use explicit request settings for a controlled comparison. Before choosing a server default, inspect your clients because their request field takes precedence.
Why does keep_alive stop working when another client connects?
Inspect what each client sends. A request can override the server default, so check the request body and the residency expiry before changing the server setting again.