Ollama Model Keeps Unloading Itself and Every Question Reloads It? keep_alive, Parallel Requests & Loaded-Model Limit Diagnosis Guide

Key takeaway
When an Ollama model answers quickly, then makes you wait after a few minutes, the server has unloaded it on its five-minute timer — not because the card is broken. This guide explains the keep_alive timer, the loaded-model limit, and parallel limit, and gives six tests that separate an idle unload from an eviction, a queue, or a capacity problem.
What this pattern actually looks like
This guide only applies when one of three shapes is present. If none of them is present, the fault belongs to a different diagnosis path, and following the steps below will lead in the wrong direction.
The first shape is the idle unload. The same model answers quickly just after a question, and then, after a few minutes of silence, the first word of the next answer takes a long time to appear. Once the first word arrives, the rest of the answer comes at normal speed. The waiting time is the time taken to load the model again, not slow generation. The model was fine a moment ago, and it will be fine again once it is loaded; the delay is the reload.
The second shape is the model-swap eviction. Model A is loaded and answering questions. You switch to model B and ask it something. When you switch back to model A, model A has to load all over again. Asking the two models in turn means waiting every time you switch. Each model works well on its own; the waiting appears only when you move between them.
The third shape is the parallel queue. You ask two questions at the same time, and the second question does not start producing words until the first question has finished. Asking one question at a time is fast; asking two together is slow. The second question is not being answered slowly — it is waiting its turn.
These three shapes have to be separated because the tests for each are different. A training or inference run that reports a CUDA out of memory error belongs to the PyTorch caching allocator, not to Ollama. A vLLM server that fails to start or keeps preempting requests belongs to the vLLM engine budget. A model that cannot fit on a card at all, or a question asked before buying a card, belongs to capacity planning. A framework reporting that no CUDA device was found belongs to device detection. A model that loads but runs on the CPU while the GPU sits idle belongs to the offload layer. A game reporting that it is out of video memory belongs to the game allocator.
The boundary that matters most for this guide is the one between a lifecycle event and an out-of-memory error. This guide is about the Ollama server's model lifecycle management: a model is loaded, it is used, and then the server unloads it on its own, with no error message at all. Nothing crashes, nothing reports that memory ran out, and no error is printed. If your Ollama setup reports an out-of-memory error, that is a different problem, covered by a different guide, and the tests below will not help you. Unloading is not an out-of-memory error, and this guide never calls it one.
Why Ollama unloads models: the scheduler and the idle timer
Ollama does not keep a model in graphics memory forever. Its server manages loaded models with a scheduler, and the scheduler follows a small set of rules. Understanding those rules is the whole diagnosis, because every symptom in this guide is one of those rules doing exactly what it was told to do.
The first rule is the idle timer, controlled by `keep_alive`. After a model finishes its last request, the timer starts. The default is five minutes. When the timer runs out, the server unloads the model and frees the graphics memory. The next question to the same model has to load it from the start before any words can be generated. The timer restarts every time a request finishes, so a model that is asked questions often never reaches the end of its timer, while a model left alone for longer than the timer is unloaded.
The second rule is that `keep_alive` has four different kinds of value, and they mean very different things. A duration such as `10m` or `24h` keeps the model loaded for that long after its last request. A number of seconds such as `3600` does the same thing, expressed in seconds. A value of `0` unloads the model immediately after it answers — it does not mean "no setting" and it does not mean "use the default". A negative value such as `-1` keeps the model loaded without applying the timer at all. These four forms must never be confused with each other: `0` is the most aggressive unload of all, and `-1` is not an infinitely long timer but a different instruction, "do not unload on a timer".
The third rule is that `keep_alive` can be set in two places, and the smaller scope wins. It can be written into an individual request, and both the `/api/generate` and `/api/chat` endpoints accept it. It can also be set as the server environment variable `OLLAMA_KEEP_ALIVE`, which becomes the default for all models. A value written into an individual request overrides the server default. This is the most common source of misdiagnosis in this area: a person changes the server default and believes the change has taken effect, while the client or tool they are actually using sends its own `keep_alive` value with every request, overriding the server setting every time. The environment variable is also read once when the server starts, so changing it requires restarting the server before it takes effect.
The fourth rule is the loaded-model limit, controlled by `OLLAMA_MAX_LOADED_MODELS`. It decides how many models can be loaded at the same time. The default is three models per GPU. A setting of `0` does not mean zero models; it means "use the scheduler default", which is three per GPU. When the number of models in use exceeds the limit, loading a new model evicts an older one. This eviction does not follow the timer; it follows the count.
The fifth rule is the parallel limit, controlled by `OLLAMA_NUM_PARALLEL`. It decides how many requests the same loaded model answers at the same time. The default is one, with an exception for MLX on Metal, which chooses its own parallel count automatically. When more than one request arrives, the extra requests wait in a queue rather than running together. Raising the parallel limit is not free: every parallel slot needs its own full context, so the memory cost grows with each additional slot. Requests beyond the parallel limit wait in a queue, and the default queue depth (`OLLAMA_MAX_QUEUE`) is 512.
The sixth rule is that context size changes how much memory a loaded model occupies. The `num_ctx` setting decides the context window, and a larger window means a larger KV cache, which means the model occupies more memory while it stays loaded. This is not loading time; it is the cost of keeping the model resident. A model with a large context window is easier to evict when memory runs short, because it takes up more room than a model with a small window.
Model files themselves come in formats such as GGUF and safetensors. The format decides how the model is stored on disk and loaded into memory; it does not decide how long the model stays loaded. If two models behave differently under the same timer settings, the difference is in their size, their context window, or the requests sent to them — not in the file format alone.
The most direct observation tool is `ollama ps`. It lists the models that are currently loaded, with columns for the name, the identifier, the size, the processor (whether the model is running on the CPU or the GPU), and UNTIL, the time remaining before the model is unloaded. Run it immediately after asking a question, and again a few minutes later, and you can see whether the model is still loaded and how much time is left on its timer. `ollama ls` lists something different: the models that have been downloaded, whether or not they are loaded. The two lists must not be confused. A model that has been unloaded has not been deleted, and it does not need to be downloaded again. `ollama stop` followed by a model name unloads that model immediately.
The key point of this whole mechanism is that unloading is designed behaviour, not a fault. A model that takes a long time to answer after a few idle minutes is not a broken card, not a shortage of graphics memory, and not a damaged model file. It is the server following its default five-minute timer. The work of this guide is not to "fix unloading" but to find out which layer caused it — the timer, an eviction, a queue, or capacity — and then to set the behaviour to match how the model is actually used.
The five suspect layers
An Ollama model that keeps disappearing has five possible layers. Only the first is the main subject of this guide; the other four must be separated out before any conclusion is drawn.
Layer 1: The idle timer — the default five-minute unload
After a model answers, five minutes pass with no further question, and the server unloads it. The evidence is the three tests that compare time intervals, read the server state, and change the timer setting. This is the most common layer, and it is the one to test first, because it is also the easiest to confirm or rule out.
Layer 2: The loaded-model limit — too many models, one is evicted
More models are loaded at once than the limit allows, so asking a new model evicts an older one. Asking the older model again means loading it from the start, which looks exactly like the first layer on the surface — "every question has to wait" — but the trigger is different. The first layer follows time; this layer follows the number of models. The separation is made by the model-swap test.
Layer 3: The parallel queue — one request at a time
The parallel setting defaults to one, so the same model answers only one request at a time, and a second question waits in the queue. The symptom here is not "reload" but "wait for the first question to finish". The separation is made by sending two questions at the same time and watching whether the second one starts immediately or waits.
Layer 4: Capacity — the model and its KV cache are too large for the memory available
The model itself is large, the context window is large, and the KV cache takes up a large amount of memory. Several models together do not fit, so the scheduler evicts the one that has been unused the longest. The separation is made by comparing a smaller model with a larger model under the same timer setting, and by shrinking the context window to see whether the larger model then stays loaded.
Layer 5: The request setting — the request itself carries an unload value
An individual request carries `keep_alive: 0`, which unloads the model as soon as it answers, or a particular client or tool sets `keep_alive` to `0` by default. Changing the server default has no effect in this case, because the request layer overrides the server layer. The separation is made by asking the same model through different tools or requests and seeing whether the result changes.
Six decisive tests
Each of these tests answers a different question, and none of them overlaps with the tests for other out-of-memory shapes.
T1: Time comparison — ask again after 1 minute versus after 6 minutes, with 5 minutes as the dividing line
Ask the same model the same question, then ask it again after 1 minute and note how long the first word takes to appear. Then ask it again after 6 minutes and note the same thing. If the 1-minute repeat is fast and the 6-minute repeat is slow because the model has to load again, the idle timer layer is confirmed, and the default five minutes is the dividing line. If both repeats are fast, the model was never unloaded, and the problem is not in the timer layer. If both repeats are slow, the problem is not the timer either, because every question is slow regardless of the interval, and the diagnosis should move to the other layers or to the offload question of whether the model is running on the CPU.
This test is new because no other guide in this series teaches using a time interval as a model lifecycle comparison. The PyTorch guide's fresh-process comparison tests accumulated state inside one PyTorch process, not a server idle timer. The vLLM guide's preemption indicators belong to the vLLM scheduler, not to the Ollama timer.
T2: Server state comparison — run `ollama ps` immediately after asking, and again a few minutes later
Ask a question, then immediately run `ollama ps` and write down the UNTIL column, which shows how long until the model is unloaded — by default something like "4 minutes from now". Run `ollama ps` again a few minutes later and see whether the model is still listed and how much time is left on UNTIL. If UNTIL counts down with time and the model disappears from the list when the time runs out, the timer layer is confirmed. If the model stays listed but answering is still slow, the problem is not unloading, and the diagnosis should move to the parallel or capacity layers.
This test is new because no other guide in this series uses `ollama ps` as a diagnosis. The device-detection guide's device list comparison reads the compute device lists of desktop applications, not the state of an Ollama server.
T3: Timer setting comparison — change the timer and see whether the slowness goes away
Ask the same model the same question, first with the default setting and a 6-minute gap, and confirm that it is slow. Then ask it again with `keep_alive: -1` in the individual request, or set `OLLAMA_KEEP_ALIVE=30m` as the server default — remembering that the environment variable is read when the server starts, so the server must be restarted before the change takes effect — and ask again after a 6-minute gap. If it is fast again, the timer layer is confirmed, and the comparison also shows which setting location actually took effect. If it is still slow, the problem is not the timer, and the diagnosis should move to the model-swap test and the capacity test.
Remember that `-1` is not a cure-all. Another model that needs memory can still evict a model set to `-1`, because `-1` only means "do not unload on a timer", not "never evict". The timer test should also cover the other forms of the value, so that the four forms are not confused: a duration such as `10m` keeps the model for ten minutes, a number of seconds such as `3600` keeps it for an hour, `0` unloads it immediately after answering, and a negative value such as `-1` keeps it loaded without a timer. Writing only "set it longer" is not enough; the test must say which form was used and what it means.
This test is new because no other guide in this series mentions `keep_alive` or `OLLAMA_KEEP_ALIVE` at all. The PyTorch guide's expandable segments switch belongs to the PyTorch allocator and does not change how long a model stays loaded. The vLLM guide's utilisation setting is an engine budget fraction, not an idle timer.
T4: Model-swap comparison — ask a second model, then check whether the first one is still loaded
Load model A and ask it a question. Then switch to model B and ask it a question. Then ask model A again, while watching `ollama ps`. If model A has to load again and the first word takes a long time, the loaded-model limit or eviction layer is in play. Then run a limit comparison: raise `OLLAMA_MAX_LOADED_MODELS`, for example from the default of 3 to 5, keeping in mind whether there is enough graphics memory for the extra models, and repeat the swap. If model A no longer has to reload, the limit layer is confirmed. If it still has to reload, the problem is not the number of models allowed, and the diagnosis should move to the capacity test.
Remember the counter-intuitive writing of this setting: a value of `0` does not mean zero models. It means "use the scheduler default", which is three models per GPU. Treating `0` as a literal count will lead the diagnosis in the wrong direction.
This test is new because no other guide in this series mentions `OLLAMA_MAX_LOADED_MODELS` or uses a model swap as an eviction comparison. The vLLM guide's preemption evicts a request inside one engine, not a whole model from the server. The planning guide's arithmetic about how many models fit in graphics memory is done before buying a card, not as a running eviction diagnosis.
T5: Parallel comparison — ask two questions at the same time and see whether the second one waits
Send two questions to the same model at the same time, from two terminals or two requests sent together. If the second question only starts producing words after the first one has finished, the parallel queue layer is confirmed, because the parallel setting defaults to one. Then run a parallel comparison: set `OLLAMA_NUM_PARALLEL=2` and send two questions at the same time again. If both questions now produce words together, the parallel layer is confirmed.
This test is a diagnosis, not a long-term fix. Every additional parallel slot needs its own full context, so the KV cache cost grows with each slot. A large context window combined with a high parallel setting can push the model back into eviction, returning the diagnosis to the model-swap and capacity tests. The default of one also has a platform exception: MLX on Metal chooses its own parallel count automatically, so the value of one should not be stated as the default on every platform.
This test is new because no other guide in this series mentions parallel request queueing. The video encoding guide's encoder queue belongs to a video pipeline, not to language model request scheduling.
T6: Model size and context comparison — a smaller model stays loaded while a larger model keeps being evicted
On the same server, with the same timer setting, ask a smaller model a question and a larger model a question, then ask both again after 6 minutes. If the smaller model answers quickly and the larger model is slow because it has to load again, the capacity layer is in play: the larger model and its KV cache take up more room and are easier to evict. Then run a context comparison: shrink the larger model's `num_ctx`, for example from 32k down to 4k, and ask again after 6 minutes. If it is fast again, the context KV cache was the cause. If it is still slow, the problem is not the context window, and the diagnosis should return to the time comparison and the model-swap test.
The exact memory figures for a KV cache vary by model, so this guide does not state fixed sizes. Only the direction of the comparison matters: smaller stays loaded more easily, larger is evicted more easily, and shrinking the context window should move the result in the direction of staying loaded.
This test is new because no other guide in this series mentions `num_ctx` or uses the context window as an eviction comparison. The planning guide treats context length as arithmetic done before buying a card, not as a running eviction diagnosis. The vLLM guide's test of shrinking the maximum model length concerns the sequence length against the KV pool, not the cost of keeping an Ollama model resident.
Seven-step diagnosis flow
- Define the shape. Decide which of the three shapes is present: an idle unload, where only a gap of a few minutes makes the next question slow; a model-swap eviction, where only switching models makes the next question slow; or a parallel queue, where only asking at the same time makes the second question slow. Record the baseline: the model name and size, the `num_ctx` setting, `OLLAMA_KEEP_ALIVE`, `OLLAMA_NUM_PARALLEL`, `OLLAMA_MAX_LOADED_MODELS`, and the Ollama version.
- Time comparison. Ask again after 1 minute versus after 6 minutes, as in T1. Five minutes is the default dividing line.
- State comparison. Run `ollama ps` immediately after asking, and again a few minutes later, to see whether the model is still listed and how much time is left on UNTIL, as in T2.
- Timer comparison. Use `keep_alive: -1` in an individual request, or `OLLAMA_KEEP_ALIVE=30m` as the server default with a server restart, and ask again after 6 minutes, as in T3. Record which setting location actually took effect.
- Model-swap comparison. Ask model B and then ask model A again, to see whether model A has to reload. Raise the loaded-model limit and try again, as in T4.
- Parallel comparison. Ask two questions at the same time and see whether the second one waits. Set `OLLAMA_NUM_PARALLEL=2` and try again, as in T5.
- Capacity comparison. Compare a smaller model with a larger model, and shrink `num_ctx` and try again, as in T6. If the model is still evicted at the smallest context size, return to T1 and T4 to check the timer and the limit, or follow the planning path for splitting, quantisation, or a different card.
What this is not: boundary cases
| Situation | Which path applies instead | Why it is not this guide |
|---|---|---|
| Running AI reports `torch.OutOfMemoryError: CUDA out of memory` | PyTorch caching allocator guide | The PyTorch allocator and its expandable segments switch, not the Ollama lifecycle |
| vLLM fails to start or keeps preempting requests | vLLM engine budget guide | The vLLM engine budget and request preemption, not Ollama model unloading |
| Ollama or llama.cpp itself reports an out-of-memory error | A later framework out-of-memory guide | A framework allocation error, not a lifecycle unload with no error |
| The model cannot fit at all, or the question is asked before buying a card | Local AI memory planning guide | Planning arithmetic, not lifecycle diagnosis |
| The framework reports that no CUDA device was found | CUDA device detection guide | The detection layer, not the lifecycle layer |
| The model loads but runs on the CPU while the GPU sits idle | Offload layer guide | Offload layer count, not unloading |
| A game reports it is out of video memory while memory is not full | Game allocator guide | A game or engine allocator, not the Ollama server |
| The GPU cannot be found inside Docker at all | Docker container GPU guide | The container runtime layer; the server has no device yet |
| The first response is slow and the first word takes a long time | Part of T1 and T5 in this guide | A slow first response can be a model load or a parallel queue, not a separate topic |
| Memory usage is high but the only symptom is slowness or late textures | VRAM exhaustion and performance guides | A performance problem, not a model unload |
Five common misconceptions
- "The model unloading means it is broken or there is not enough graphics memory." Wrong. Unloading is the designed behaviour of the default five-minute timer, not a fault. Run the time comparison and the server state comparison first, and do not start by replacing the card or reinstalling anything.
- "Setting keep_alive longer, for example to -1, is always better." Wrong. A model that stays loaded keeps occupying graphics memory and blocks other models from loading, and another model that needs memory can still evict a model set to `-1`. The timer should match how the model is actually used, not be set as long as possible.
- "Slow answering means the model loads slowly." Wrong. A first load after an idle gap and a parallel queue are two different kinds of slow, with different fixes. Without measuring the interval and the parallel state, saying only that it is "slow" has no diagnostic value.
- "If ollama ps does not show the model, it is not installed." Wrong. `ollama ps` only lists models that are currently loaded. Models that have been downloaded but are not loaded are listed by `ollama ls`. A model that has been unloaded has not been deleted, and it does not need to be downloaded again.
- "A card with more graphics memory will stop the unloading." Wrong. The timer layer has nothing to do with how much graphics memory the card has: under the default five minutes, a model on a larger card is unloaded after five minutes just the same. A larger card only loosens the loaded-model limit and the capacity layer; the timer layer is completely unaffected. Run the time comparison and the timer setting comparison first, and do not start by replacing hardware.
What to do next, and what not to do
If the six tests point to the idle timer layer, the practical step is to record the exact baseline — the model name, the `num_ctx` setting, the current `keep_alive` value and where it was set, the loaded-model limit, the parallel setting, and the Ollama version — and then change one setting at a time. Changing several settings at once destroys the diagnosis, because it becomes impossible to tell which change mattered. Keep the other settings fixed, change one, restart the server if the change is an environment variable, and record the new result before moving on.
Choose the timer to match the rhythm of use. A model asked every few minutes through the working day can stay loaded with a longer timer, while a model asked once an hour does not need to occupy graphics memory all day. Setting `-1` on every model at once is not a plan: the models will compete for the same memory, and the scheduler will evict whichever one another model needs room for. If two models are used in turn, raising the loaded-model limit only helps when there is enough memory for both models and their context windows at the same time; otherwise the swap eviction will return.
Do not keep raising the parallel setting in the hope that more simultaneous answers will fix everything. Each parallel slot needs its own full context, so the memory cost grows with each slot, and a large context window combined with a high parallel setting can push a model back into eviction. Do not treat `keep_alive: 0` as a way of switching the timer off; it is the most aggressive unload of all, and a client that sends it by default will unload the model after every single answer no matter what the server default says. Do not assume that changing the server environment variable has taken effect until the server has been restarted and `ollama ps` shows a longer UNTIL after a fresh question.
The honest limits of this guide should be stated plainly. The Ollama server was not run locally for this article, so the default values, the UNTIL column wording, and the scheduler behaviour come from the published sources listed below, written between October and November 2026 against Ollama versions 0.33.2 to 0.40.17. Wording and defaults change between versions, so a reader should always trust the output of `ollama serve --help` and the official FAQ for the version actually installed. The method for setting an environment variable also differs by installation method, so this guide states the mechanism and how to verify it rather than giving fixed steps for every platform. Multi-GPU scheduling — which card loads which model — is mentioned only as a boundary: splitting a model across cards is scaling, not lifecycle diagnosis, and it is not expanded here.
The sources used for the mechanism in this guide are the Ollama official FAQ on keeping a model loaded in memory, the llmhardware.io guide on `keep_alive`, the ssdnodes.com guides on keeping a model loaded and on Ollama environment variables, the quantacloud.net guide on Ollama environment variables for a GPU server, and the glukhov.org Ollama CLI cheatsheet. The four independent guides agree on the five-minute default across versions 0.33.2 to 0.40.17, and the official FAQ is the authority where the guides differ in wording.
Repair pricing on this site follows the published three-tier fee structure of HK$400–2,800, with the final quote after inspection.
HK GPU Fix is located at Dali Plaza, Room 1209, Shek Mun. The phone number is 2186 8010 and WhatsApp is 6558 6806. There is no Mong Kok shop and no on-site service; inspection and repair are carried out at the workshop.
FAQ
Q1: How long until Ollama unloads an idle model?
Five minutes by default. After a model finishes its last request, the timer starts, and when it runs out the server unloads the model and frees the graphics memory. The timer restarts every time a request finishes, so a model asked often never reaches the end of its timer. The default can be changed with `keep_alive` in a request or with the `OLLAMA_KEEP_ALIVE` server environment variable, but the value should be checked against the version installed, because defaults and wording change between versions.
Q2: What is the difference between keep_alive 0 and -1?
They are opposites. A value of `0` unloads the model immediately after it answers — it does not mean "no setting" and it does not mean "use the default". A negative value such as `-1` keeps the model loaded without applying the timer at all. A duration such as `10m` and a number of seconds such as `3600` are the other two forms: both keep the model loaded for that length of time after its last request. The four forms must never be confused, because `0` is the most aggressive unload of all.
Q3: Why does a model still unload even with -1 set?
Because `-1` only means "do not unload on a timer". It does not mean "never evict". When another model needs memory and the loaded-model limit or the available memory is reached, the scheduler can still evict a model set to `-1`. The other causes to check are a per-request value overriding the server setting, a client or tool sending its own `keep_alive` value with every request, and the environment variable not having taken effect because the server was not restarted after it was changed.
Q4: How can I see which models are currently loaded?
Run `ollama ps`. It lists the models that are currently loaded, with the name, the identifier, the size, the processor, and UNTIL, the time remaining before the model is unloaded. Run it immediately after asking a question, and again a few minutes later, to see whether the model is still listed and how much time is left. Do not use `ollama ls` for this: it lists the models that have been downloaded, whether or not they are loaded, and a model that has been unloaded will still appear there.
Q5: Why does asking a second model make it wait, or evict the first one?
Two different layers can cause this, and they need different fixes. If the second question waits for the first one to finish, that is the parallel queue: the parallel setting defaults to one, so the same model answers only one request at a time. If the first model has to load again when you switch back to it, that is the loaded-model limit: the default is three models per GPU, and loading a new model evicts an older one when the limit is reached. Run the model-swap test to see which one it is before changing any setting.
Q6: Does a bigger model or a larger num_ctx make unloading more frequent?
A larger model or a larger context window does not change the five-minute timer, but it does make eviction more likely. A larger `num_ctx` means a larger KV cache, so the model occupies more memory while it stays loaded, and the scheduler is more likely to evict it when memory runs short. If a smaller model stays loaded and a larger model keeps being evicted under the same timer setting, shrink `num_ctx` — for example from 32k down to 4k — and see whether the larger model then stays loaded. If it still does not, the cause is in the timer or the loaded-model limit, not in the context window.