Skip to content

Add option for LRU eviction on memory pressure / load #9375

Closed

Description

@Xnyle

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.

Activity

  1. changed the title [-]Add option for LRU eviction on memory pressure[/-] [+]Add option for LRU eviction on memory pressure / load[/+] on Apr 16, 2026
  2. added a commit that references this issue on Apr 26, 2026
    bf9228a
  3. walcz-de commented on Apr 28, 2026

    @walcz-de
    Contributor

    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:

    1. Implement Free() in backend/cpp/llama-cpp/grpc-server.cpp so eviction physically releases the model + KV cache. This is the real fix.
    2. Until (1): in the reclaimer, when Free() returns Unimplemented, 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.
    3. The new feat: Log backend exit code (feat: Log backend exit code #9581, just merged) will help here — combined with surfacing the Unimplemented warning 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.

  4. added a commit that references this issue on May 3, 2026
    6077f91
  5. added a commit that references this issue on Jun 21, 2026
    b50b1fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions