Add option for LRU eviction on memory pressure / load
Is your feature request related to a problem? Please describe. Usecase is that i have limited memory but want to test multiple models while still need to maintain certain smaller models always in memory.
Describe the solution you'd like New Setting: LRU eviction on model load:
LRU eviction that fires whenever a new model /backend is about to be loaded, Triggers if the to be loaded model would not fit in memory (same calculation as on the model gallery). eviction target(s) are biggest models first, keep smaller ones in memory.
Note for anyone hitting this: the feature is actually already implemented as the memory_reclaimer (added in #7583, Dec-16-2025). You can enable it via LOCALAI_MEMORY_RECLAIMER=true and LOCALAI_MEMORY_RECLAIMER_THRESHOLD=0.95 (or via the runtime-settings JSON / Settings UI). When GPU usage exceeds the threshold, the watchdog evicts LRU models.
However, there's a sharp corner that makes it unusable on llama-cpp setups today. Surfaced cleanly on a single-GPU AMD Strix Halo (gfx1151, 96 GB unified VRAM, ROCm 7.x, current master @ f53577… llama-cpp pin) with 4 preloaded models pushing usage to ~92 %:
WARN [WatchDog] Memory usage exceeds threshold, evicting LRU backend type=GPU usage_percent=92.0 threshold_percent=90
INFO [WatchDog] Memory reclaimer evicting LRU model model="Qwen2.5-72B-Instruct-GGUF"
INFO [WatchDog] Memory reclaimer eviction complete model="Qwen2.5-72B-Instruct-GGUF"
WARN Error freeing GPU resources error=rpc error: code = Unimplemented desc = model="Qwen2.5-72B-Instruct-GGUF"
The reclaimer logs eviction complete but the llama-cpp gRPC backend's Free() returns Unimplemented, so VRAM is never actually released. Every 5 s tick the watchdog sees usage still >90 %, picks the next LRU victim, repeats. After all four preloaded models have been "evicted in name only", the next chat-completion that needs a freshly-loaded model crashes the backend on load:
WARN Backend process exited unexpectedly id="qwen3.6-35b-a3b-apex" exitCode="-1"
A few things that would make the feature actually safe to enable:
- Implement
Free()inbackend/cpp/llama-cpp/grpc-server.cppso eviction physically releases the model + KV cache. This is the real fix. - Until (1): in the reclaimer, when
Free()returnsUnimplemented, don't mark eviction as complete — fall back to the next-largest victim and add an exponential backoff before re-firing, otherwise the watchdog spins for nothing while load operations queue up behind it. - The new
feat: Log backend exit code(#9581, just merged) will help here — combined with surfacing theUnimplementedwarning to the UI/logs as an error rather than warn would let users immediately see the misconfiguration.
Workaround for anyone hitting this on llama-cpp today: set memory_reclaimer_enabled: false in runtime_settings.json, restart, pin the models you need via LOCALAI_LOAD_TO_MEMORY. Tracked separately in our memory as a regression to watch on every upstream sync.