A deploy script runs lms load your-model on every release; why does lms ps list several copies a week later, and what fixes it?
answer
- load means a new instance
- generated identifiers for each copy
- no idle timer from lms load
- fixed --identifier fails on repeat
- unload first, or --ttl
basics
~20 sEvery lms load creates a new instance even when the model is already loaded, and lms-loaded models have no idle TTL, so copies pile up. Unload first, give the load a fixed --identifier so a repeat errors out, or add --ttl.
solid answer
~40 s`lms load` does not reuse a loaded model: it asks LM Studio for a **new instance** every time, and the server gives each extra copy its own generated identifier. Models loaded with `lms load` also have **no TTL by default**, so nothing ever unloads them on its own; the 60-minute default idle timer and Auto-Evict apply to models the server loads on demand, not to these. The fixes are scriptable: run `lms unload <identifier>` (or `lms unload --all`) before loading; pass `--identifier your-name`, because loading a second instance under an identifier that already exists is an error rather than a silent duplicate; check `lms ps --json` and skip the load when the instance is there; and add `--ttl <seconds>` if it is acceptable for an idle model to unload itself.
go deeper
Remember that each lms load adds an instance and that models loaded this way stay loaded until you unload them, so a script that loads must also unload or check first.
Explain why the JIT idle TTL and Auto-Evict do not touch lms-loaded instances, and show how --identifier, --ttl and lms unload make a provisioning load repeatable.
Design a deploy step that is idempotent: check lms ps --json, unload when settings change, load under a fixed identifier with explicit flags, and alert when memory shows stacked instances.
Decide whether a shared box should run fixed, script-loaded instances with no TTL or rely on on-demand loading, trading predictable latency against memory reclaimed from idle models.
## What `lms load` actually asks for The `lms` CLI is a client of LM Studio's own API, the same one the TypeScript SDK uses. Its `load` command calls the SDK's load operation, which is documented as loading **a new instance of a model, even if one already exists**. That design is deliberate: you might want two instances of the same model with different settings, or the same model twice for throughput. The consequence for automation is that `lms load` is **not idempotent**. Run it on every deploy and each run adds a copy. Each instance needs a name for API calls (the `model` field in a request, or the SDK's model handle). When you do not pass `--identifier`, the server generates one, so the second copy gets a different generated identifier from the first and nothing complains. ## Why nothing cleans the copies up LM Studio has two automatic unloading mechanisms, and neither reaches these instances: - **Idle TTL.** Models loaded **just in time** by the server, because a request named them, get an idle TTL of 60 minutes by default. Models loaded with `lms load` have **no TTL** unless you pass `--ttl`, and stay in memory until you unload them. - **Auto-Evict.** When on (the default), it keeps at most one JIT-loaded model at a time. The documentation says outright that non-JIT-loaded models are not affected. So a week of releases leaves a week of instances, each holding its weights and context memory, until the machine starts refusing loads or swapping. ## Making the script safe | Approach | Command | What it guarantees | |---|---|---| | Clear first | `lms unload --all` then `lms load ...` | exactly one instance, at the cost of a reload every deploy | | Fixed name | `lms load your-model --identifier chat-main` | a second load under the same identifier is an error, not a duplicate | | Check first | `lms ps --json`, load only if `chat-main` is absent | no reload when nothing changed | | Self-expiring | `lms load your-model --ttl 3600` | an idle instance unloads after an hour without requests | A **fixed identifier** is the cheapest guard and has a second benefit: clients can send `chat-main` as the model name and never learn the generated one. Combine it with an explicit unload when the deploy changes the model or its settings, because the old instance will otherwise block the new identifier. ## Flags that belong on a scripted load Interactive defaults are wrong for scripts, so a provisioning load usually spells out: 1. `--identifier <name>` for a stable API name. 2. `--gpu <0-1|max|off>` for GPU offload; omitted, LM Studio picks automatically. 3. `--context-length <n>` (alias `-c`); omitted, the model's default context is used. 4. `--ttl <seconds>` only if idle unloading is acceptable for that service. 5. `--yes` so that several matching models do not trigger an interactive prompt. Settings you leave out fall back to the per-model defaults saved in the app, which is convenient on a laptop and a hidden dependency on a server. ## Why the design is this way Treating every load as a new instance is what makes LM Studio useful for experiments: you can hold the same weights at two context lengths side by side, or compare two GPU offload settings without unloading either. The price is that **idempotence is the caller's job**. A provisioning script is a caller that runs many times, so it has to bring its own guard, and the identifier is the natural one: it is the name every client already depends on. ## Seeing the problem In the current `lms` source, `lms ps` prints each loaded instance with its identifier, status and remaining TTL, so stacked copies show up as several rows for one model with no TTL. `lms ps --json` gives the same data to a script. ## Common wrong explanations - "Auto-Evict should have removed the old one" — it only manages JIT-loaded models. - "The second load just reloads the same instance with new settings" — it creates another instance. - "Models unload after an hour anyway" — that is the JIT default; `lms load` sets no TTL.
- The deploy changes the context length. Why is a fixed --identifier alone not enough?The old instance still holds the identifier, so the new load fails instead of replacing it. The script has to `lms unload chat-main` first and then load with the new `--context-length` under the same identifier, accepting a short gap while the model loads.
- When would you deliberately want two instances of the same model?When two clients need different load settings, such as a short-context instance for autocomplete and a long-context one for document questions, or when you want separate instances for throughput. Each gets its own `--identifier`, and memory is the limit.
It is like a launcher that opens a fresh window every time you click it instead of focusing the one already open: after a week of clicks you have a week of windows, and none of them closes itself.
- lms load reuses the instance that is already loaded
- Auto-Evict unloads models loaded with lms load
- Models loaded with lms load unload after 60 idle minutes
- A duplicate --identifier silently replaces the old instance
- lms ps only shows one row per model key