Arno_1

Untitled

Mar 6th, 2026
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. 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)
  2.  
  3. ## Enable JIT and Auto-Evict in LM Studio
  4.  
  5. Access **Developer tab > Server Settings** to configure these core features. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  6.  
  7. - **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)
  8. - **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)
  9. - **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)
  10.  
  11. 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)
  12.  
  13. ## How Idle TTL Works
  14.  
  15. - **Definition**: Time-To-Live (TTL) unloads JIT-loaded models after inactivity (no requests). Default: 60 minutes. [lmstudio](https://lmstudio.ai/llms.txt)
  16. - **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)
  17. - **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)
  18. - **Behavior**: Model stays loaded during active use; unloads post-TTL to free VRAM. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  19.  
  20. Set shorter TTLs (5-15 min) initially for testing to force swaps. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  21.  
  22. ## Seamless Integration with OpenClaw
  23.  
  24. 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)
  25.  
  26. 1. **OpenClaw Config** (no changes needed beyond model allowlist):
  27. ```
  28. models.providers.lmstudio.baseUrl: "http://192.168.1.13:9000/v1"
  29. models.providers.lmstudio.models: [ {id: "glm-4.7..."}, {id: "qwen3-coder..."}, {id: "qwen3-vl..."} ]
  30. agents.defaults.models: ["lmstudio/glm-4.7...", "lmstudio/qwen3-coder...", "lmstudio/qwen3-vl..."]
  31. agents.defaults.maxConcurrent: 1 # Prevents parallel overload
  32. agents.defaults.subagents.maxConcurrent: 1
  33. ```
  34. Sub-agents spawn with `--model lmstudio/qwen3-coder...` or defaults. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
  35.  
  36. 2. **Runtime Flow**:
  37. | Step | What Happens | LM Studio Action | VRAM Impact |
  38. |------|-------------|------------------|-------------|
  39. | Main agent (research task) | Requests GLM model | JIT loads GLM if idle | GLM loads (~20GB) |
  40. | Coding sub-agent spawns | Requests Qwen3-Coder | Auto-Evict unloads GLM, loads Coder | Coder loads (~8GB), GLM evicted |
  41. | Idle 10 min | No requests | TTL unloads Coder | VRAM fully free |
  42. | Vision sub-agent | Requests Qwen3-VL | JIT loads VL | VL loads (~10GB) | [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  43.  
  44. 3. **OpenClaw Routing**:
  45. - **Sub-agent Defaults**: `agents.defaults.subagents.model: "lmstudio/qwen3-coder..."`
  46. - **Multi-Agent**: Define `coding` agent with its model; route tasks via `/subagents spawn coding "code this"`. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
  47.  
  48. ## Testing the Full Loop
  49.  
  50. 1. **LM Studio Prep**:
  51. - Download all models.
  52. - Enable JIT/Auto-Evict, set TTL=300s (5 min).
  53. - Start server: No manual loads needed. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  54.  
  55. 2. **Verify JIT**:
  56. ```
  57. curl http://192.168.1.13:9000/v1/models # Lists all downloaded models
  58. curl -X POST http://192.168.1.13:9000/v1/chat/completions \
  59. -H "Content-Type: application/json" \
  60. -d '{"model": "glm-4.7...", "messages": [{"role":"user","content":"Hi"}]}' # Auto-loads GLM
  61. ```
  62. Check LM Studio console: "Loading model GLM...", then responds. [github](https://github.com/lmstudio-ai/lms/issues/107)
  63.  
  64. 3. **Test Swap**:
  65. - Repeat curl with Qwen3-Coder model.
  66. - Console: "Evicting GLM...", "Loading Qwen3-Coder...". [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  67. - Wait TTL, curl GLM again: Reloads fresh. [lmstudio](https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict)
  68.  
  69. 4. **OpenClaw Test**:
  70. ```
  71. openclaw models list --local # Sees all via /v1/models
  72. # In chat: /model lmstudio/qwen3-coder..., ask to code
  73. # Then: /subagents spawn main "research X" --model lmstudio/glm-4.7...
  74. ```
  75. Monitor LM Studio console for evict/load. Set OpenClaw concurrency=1. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
  76.  
  77. ## Limitations and Tips
  78.  
  79. - **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)
  80. - **Ongoing Generation**: New JIT won't interrupt active inference—queues or waits. [github](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/671)
  81. - **Bugs to Watch**: Rare double-loads on TTL expiry (update LM Studio). [github](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/634)
  82. - **Headless/CLI**: Use `lms headless-server` for background; same JIT settings. [lmstudio](https://lmstudio.ai/docs/developer/core/headless)
  83. - **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)
  84.  
  85. 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