Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LM Studio's JIT (Just-In-Time) loading, combined with Auto-Evict and Idle TTL, enables automatic model loading/unloading without manual intervention, perfect for your single-GPU setup with OpenClaw. This ensures only one model runs at a time, preventing VRAM overload as sub-agents request different models. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- ## Enable JIT and Auto-Evict in LM Studio
- Access **Developer tab > Server Settings** to configure these core features. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- - **JIT Loading**: Toggle **ON**. This makes `/v1/models` list *all downloaded models* (even unloaded ones), and any inference request (e.g., `/v1/chat/completions`) auto-loads the specified model if idle. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- - **Auto-Evict**: Toggle **ON** (default). Ensures *at most 1 JIT-loaded model* stays in memory—new model requests unload the previous one first. Non-JIT models (manually loaded) are unaffected. [lmstudio](https://lmstudio.ai/llms.txt)
- - **App-Default Idle TTL**: Set a default unload timer (e.g., 10-30 minutes) for JIT-loaded models. Idle timer resets on each request. [lmstudio](https://lmstudio.ai/llms.txt)
- With these ON, your RTX 3090 Ti will dynamically swap models: GLM loads for research, unloads for coder switch, etc. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- ## How Idle TTL Works
- - **Definition**: Time-To-Live (TTL) unloads JIT-loaded models after inactivity (no requests). Default: 60 minutes. [lmstudio](https://lmstudio.ai/llms.txt)
- - **Per-Request Override**: Include `"ttl": 600` (10 minutes in seconds) in API payloads for specific models. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- - **CLI Override**: `lms load <model> --ttl 1800` for 30-minute TTL on command-loaded models. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- - **Behavior**: Model stays loaded during active use; unloads post-TTL to free VRAM. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- Set shorter TTLs (5-15 min) initially for testing to force swaps. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- ## Seamless Integration with OpenClaw
- OpenClaw acts as an OpenAI-compatible client—it sends `model: "qwen3-coder-..."` to LM Studio's `/v1/chat/completions`, triggering JIT without OpenClaw knowing. Here's the flow: [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- 1. **OpenClaw Config** (no changes needed beyond model allowlist):
- ```
- models.providers.lmstudio.baseUrl: "http://192.168.1.13:9000/v1"
- models.providers.lmstudio.models: [ {id: "glm-4.7..."}, {id: "qwen3-coder..."}, {id: "qwen3-vl..."} ]
- agents.defaults.models: ["lmstudio/glm-4.7...", "lmstudio/qwen3-coder...", "lmstudio/qwen3-vl..."]
- agents.defaults.maxConcurrent: 1 # Prevents parallel overload
- agents.defaults.subagents.maxConcurrent: 1
- ```
- Sub-agents spawn with `--model lmstudio/qwen3-coder...` or defaults. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- 2. **Runtime Flow**:
- | Step | What Happens | LM Studio Action | VRAM Impact |
- |------|-------------|------------------|-------------|
- | Main agent (research task) | Requests GLM model | JIT loads GLM if idle | GLM loads (~20GB) |
- | Coding sub-agent spawns | Requests Qwen3-Coder | Auto-Evict unloads GLM, loads Coder | Coder loads (~8GB), GLM evicted |
- | Idle 10 min | No requests | TTL unloads Coder | VRAM fully free |
- | Vision sub-agent | Requests Qwen3-VL | JIT loads VL | VL loads (~10GB) | [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- 3. **OpenClaw Routing**:
- - **Sub-agent Defaults**: `agents.defaults.subagents.model: "lmstudio/qwen3-coder..."`
- - **Multi-Agent**: Define `coding` agent with its model; route tasks via `/subagents spawn coding "code this"`. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- ## Testing the Full Loop
- 1. **LM Studio Prep**:
- - Download all models.
- - Enable JIT/Auto-Evict, set TTL=300s (5 min).
- - Start server: No manual loads needed. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- 2. **Verify JIT**:
- ```
- curl http://192.168.1.13:9000/v1/models # Lists all downloaded models
- curl -X POST http://192.168.1.13:9000/v1/chat/completions \
- -H "Content-Type: application/json" \
- -d '{"model": "glm-4.7...", "messages": [{"role":"user","content":"Hi"}]}' # Auto-loads GLM
- ```
- Check LM Studio console: "Loading model GLM...", then responds. [github](https://github.com/lmstudio-ai/lms/issues/107)
- 3. **Test Swap**:
- - Repeat curl with Qwen3-Coder model.
- - Console: "Evicting GLM...", "Loading Qwen3-Coder...". [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- - Wait TTL, curl GLM again: Reloads fresh. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- 4. **OpenClaw Test**:
- ```
- openclaw models list --local # Sees all via /v1/models
- # In chat: /model lmstudio/qwen3-coder..., ask to code
- # Then: /subagents spawn main "research X" --model lmstudio/glm-4.7...
- ```
- Monitor LM Studio console for evict/load. Set OpenClaw concurrency=1. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- ## Limitations and Tips
- - **Single Active Model**: Auto-Evict enforces 1 JIT model; ideal for 24GB VRAM but blocks parallel sub-agents (your concurrency=1 fixes this). [lmstudio](https://lmstudio.ai/llms.txt)
- - **Ongoing Generation**: New JIT won't interrupt active inference—queues or waits. [github](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/671)
- - **Bugs to Watch**: Rare double-loads on TTL expiry (update LM Studio). [github](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/634)
- - **Headless/CLI**: Use `lms headless-server` for background; same JIT settings. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
- - **VRAM Optimization**: Use Q4_K_M quants; monitor via LM Studio metrics. Shorten TTL during tests. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
- This setup gives "seamless" switching—OpenClaw routes tasks, LM Studio handles VRAM dance automatically. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
Advertisement
Add Comment
Please, Sign In to add comment