A coding extension on LM Studio's server alternates a chat model, an autocomplete model and an embedding model, and every switch waits for a reload — why, and what do you change?
answer
- a count limit, not a timer
- on unless you switch it off
- only JIT-loaded models count
- unloads before the next one loads
- preload them, or turn it off
basics
~20 sAuto-Evict, on by default, keeps at most one JIT-loaded model, so each request for a different model unloads the previous one first. Turn Auto-Evict off if memory holds all three, or load them explicitly, which Auto-Evict leaves alone.
solid answer
~50 sThe extension relies on **JIT loading**: each model is loaded by the first request that names it. **Auto-Evict**, on by default, unloads previously JIT-loaded models before a new one is loaded, so at most one JIT-loaded model is in memory, and alternating chat, autocomplete and `/v1/embeddings` calls reloads a model on almost every switch. Confirm it with `GET /api/v1/models`, whose `loaded_instances` shows only one of the three, or with `model_load_time_seconds` in native chat responses. Two fixes: switch Auto-Evict off in the Developer tab's Server Settings, so the models stay until their idle TTL expires or you unload them, which needs memory for all three; or load the three explicitly, in the app, with the CLI or through `POST /api/v1/models/load`, because Auto-Evict does not touch models that were not JIT-loaded. Check that all three fit before choosing either.
code
bash · 10 lines# Load the three models explicitly so Auto-Evict leaves them alone
# (add -H "Authorization: Bearer $LM_API_TOKEN" if Require Authentication is on)
for m in your-org/chat-model your-org/autocomplete-model your-org/embedding-model; do
curl -s http://localhost:1234/api/v1/models/load \
-H "Content-Type: application/json" \
-d "{\"model\": \"$m\", \"echo_load_config\": true}"
done
# Each model's loaded_instances should now be non-empty
curl -s http://localhost:1234/api/v1/modelsgo deeper
Recall that LM Studio's server keeps only one JIT-loaded model at a time by default, because of Auto-Evict.
Explain how Auto-Evict differs from the idle TTL, which models it ignores, and why alternating requests reload models.
Diagnose the thrash from loaded_instances or load-time stats, then choose between preloading and disabling Auto-Evict from the memory the three models really need.
Decide whether one workstation should host every model a tool needs, or whether the embedder and the chat model belong on different machines.
## What Auto-Evict does LM Studio's server can load models **just in time (JIT)**: a request naming a model that is not in memory makes the server load it first. **Auto-Evict** is the companion rule that stops those loads from piling up. Before a new model is JIT-loaded, Auto-Evict **unloads the previously JIT-loaded models**. It is **on by default**, and the rules are short: - At most **one** model loaded via JIT stays in memory at a time. - Models that were **not** JIT-loaded are not affected. - It is switched in the **Developer tab > Server Settings**; the settings list describes the same behaviour as **Only Keep Last JIT Loaded Model**. It exists so that a user switching models in a chat client never has to unload the old one by hand. It is exactly wrong for a client that uses several models *at once*. ## Why a three-model client thrashes A coding extension commonly drives three models: a chat model for questions, a small fast model for inline completions, and an **embedding model** for indexing the codebase through `/v1/embeddings`. With the defaults: 1. A chat request JIT-loads the chat model. 2. An autocomplete request names the second model; Auto-Evict unloads the chat model, then the autocomplete model loads. 3. The indexer calls `/v1/embeddings`; the autocomplete model is unloaded and the embedding model loads. The docs make no exception for embedding models. 4. The next chat question reloads the chat model, and the cycle continues. Every switch costs a full load, seconds to tens of seconds depending on model size and disk, and the extension feels broken even though each request succeeds. ## Confirming it - `GET /api/v1/models` lists each model with its `loaded_instances`; under thrashing only one of the three has an instance at any moment. - Native `/api/v1/chat` responses carry `model_load_time_seconds` in `stats` only when the request had to load the model; a value on most calls is the signature. - The latency pattern itself: slow after every model switch, fast for consecutive requests to the same model. The **idle TTL** is not the cause: it is a time rule (60 minutes by default for JIT loads), while this is a count rule firing on every switch. Raising the TTL changes nothing. ## Two fixes and their costs | Fix | What happens | What it costs | |---|---|---| | Switch **Auto-Evict off** | JIT-loaded models stay until their idle TTL expires or you unload them | Memory for all three at once; the docs describe no cap on how many a client can pile up | | **Load the models explicitly** | Auto-Evict ignores them; JIT stays available for anything else | Someone must load them after every restart; a CLI-loaded model has no TTL unless you give it one | | Leave the defaults | Lowest memory use | A reload on almost every switch | Explicit loading can be done from the Developer tab, with the CLI, or over HTTP with `POST /api/v1/models/load`, which takes the `model` key and optional settings such as `context_length`, returns an `instance_id`, and can echo the applied settings with `echo_load_config`. `POST /api/v1/models/unload` with that `instance_id` frees it again. These routes arrived with LM Studio 0.4.0. ## Serving the embedding model alongside chat `/v1/embeddings` takes an `input`, a string or a list of strings, plus the embedding model's identifier, and returns vectors in the OpenAI shape. `GET /api/v1/models` marks embedding models with the type `embedding`, so a client can find the right one programmatically. Two things matter here: the embedding model follows the same JIT and Auto-Evict rules as any chat model, and an indexing run fires many embedding requests in a burst. With Auto-Evict on, an indexer and a chat session running at the same time keep evicting each other, and the editor stalls while indexing. ## Choosing 1. Add up the three models' memory at the context lengths the extension uses. If they do not fit together, no setting fixes it: drop to a smaller autocomplete model or move the embedder elsewhere. 2. If they fit and the machine is dedicated to this work, preload all three; the client's behaviour no longer depends on server switches. 3. If the machine is shared and the models are used in bursts, turn Auto-Evict off and let the idle TTL reclaim memory between sessions. 4. Keep the model identifiers stable: the embedding model that built the index must be the one that embeds queries, whichever loading strategy you choose. Auto-Evict and the idle TTL both arrived in LM Studio 0.3.9; both are about memory on a single machine, not about serving many users.
- With Auto-Evict switched off, what eventually frees the memory those JIT-loaded models hold?Their idle TTL, 60 minutes by default for JIT loads unless a request set another value, or a manual unload, for example `POST /api/v1/models/unload` with the model's `instance_id`. The docs describe no cap on how many models a client can JIT-load meanwhile, so memory has to cover the worst case.
- Does Auto-Evict ever unload a model you loaded yourself in the Developer tab?No. Auto-Evict only unloads models that were loaded just in time by a request; models loaded by hand are not affected. That is why preloading the models a client depends on is the fix that leaves the defaults in place for everything else.
- Auto-Evict is off by default, so JIT models pile up until memory runs out.
- Auto-Evict unloads every model in memory, including ones loaded by hand.
- Raising the idle TTL stops the extension's models evicting each other.
- An embedding model never counts toward Auto-Evict's one-model limit.
- Turning Auto-Evict off costs nothing, because memory use stays the same.
Assumes LM Studio 0.4.0 or newer for the /api/v1 model-list, load and unload routes; Auto-Evict and the idle TTL date from 0.3.9.