Skip to content

agent: fall back to the CPU when the GPU has no room for the model - #203

Closed
secinto wants to merge 1 commit into
lightonai:mainfrom
secinto:fix/agent-gpu-oom-fallback
Closed

secinto wants to merge 1 commit into
lightonai:mainfrom
secinto:fix/agent-gpu-oom-fallback

Conversation

@secinto

@secinto secinto commented Oct 14, 2026 •

Copy link
Copy Markdown

Problem

colgrep --install-agent (and colgrep --agent) start llama-server with every layer on the GPU. On a machine whose GPU is almost full (here: an RTX PRO 6000 with 1.4 GB free, used by other services), the load fails with Vulkan ErrorOutOfDeviceMemory and the agent does not start.

Change

When the user has not set --agent-gpu-layers:

  • find_gpu estimates the memory the model needs (weights + 20 % + 512 MiB) and skips a GPU that reports less free memory. The model then runs on the CPU, and the device line names the reason, e.g. CPU, 18 threads; NVIDIA RTX PRO 6000 … has 1422 MiB free, the model needs ~3579 MiB.
  • If the GPU load still fails with an out-of-memory error in the llama-server log, colgrep retries once with 0 GPU layers.

A layer count the user set is kept as before (no fallback).

Testing

  • Agent crate: cargo test (49 pass), cargo clippy clean, cargo fmt applied.
  • New unit tests: skips_a_gpu_without_room_for_the_model, model_size_to_gpu_memory, out_of_device_memory_is_recognised.
  • On the affected machine: 1.8.5 fails with ErrorOutOfDeviceMemory; this build is ready on the CPU in 2.5 s.
  • The CPU retry after an out-of-memory load is covered by unit tests only; I could not reproduce a GPU that reports enough free memory and then fails.

🤖 Generated with Claude Code

llama-server was started with every layer on the first GPU even when that
GPU was nearly full, and failed with ErrorOutOfDeviceMemory. When the user
did not set --agent-gpu-layers, colgrep now skips a GPU whose free memory
is below the model's estimated need, and retries once on the CPU if the
GPU load still runs out of memory. The device line names the reason.
@secinto

secinto commented Oct 14, 2026

Copy link
Copy Markdown
Author

Closing: we keep this fix in our fork for now.

@secinto secinto closed this Oct 14, 2026
@secinto
secinto deleted the fix/agent-gpu-oom-fallback branch October 14, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant