Repository navigation
Studio: arm the VRAM-settle wait after the startup orphan reaper - #6315
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a compute-graph reserve of 2048 MiB for single-GPU pinning on multi-GPU hosts to prevent models from cramming onto a single tight card and hanging, instead deferring to a split. Additionally, _kill_orphaned_servers now returns the count of reaped processes, allowing the backend initialization to arm the VRAM settle clock only when orphans are actually killed. Comprehensive unit tests have been added to verify both the multi-GPU graph reserve logic and the startup orphan-reaper behavior. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efa33fb171
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if len(selected) >= 2 and cumulative >= model_size_mib: | ||
| return sorted(selected), False |
There was a problem hiding this comment.
Preserve graph headroom in the split fallback
When a multi-GPU host has a tight primary GPU plus a busy/tiny secondary GPU, the new 1-GPU check can fail only because of the 2 GiB graph reserve, but this fallback immediately drops that reserve and accepts any second GPU whose free memory makes cumulative >= model_size_mib (for example, ~21.4 GiB on a 22,805 MiB card plus 1 MiB returns [0, 1]). That regresses previously working tight single-GPU loads into a multi-GPU launch that still has no budget for the graph buffer and may touch an unusable device; the auto-ctx loop below has the same reserve-dropping pattern, so the multi-GPU checks should include the reserve or avoid splitting when no real second GPU capacity exists.
Useful? React with 👍 / 👎.
| continue | ||
|
|
||
| proc.kill() | ||
| killed += 1 |
There was a problem hiding this comment.
Wait for reaped servers before arming VRAM settle
On startup with a large orphaned llama-server, proc.kill() only sends the kill signal, so counting it immediately lets __init__ treat the process as reaped while it may still be exiting and holding VRAM. The subsequent _wait_for_vram_settle can then see two stable-but-still-occupied samples and return before reclaim happens, leaving the first load after restart able to rank the wrong GPU exactly as before; wait for the killed process to exit (or keep polling through that transition) before reporting it in the reap count.
Useful? React with 👍 / 👎.
| if (n_gpus == 1 and len(ranked) > 1) | ||
| else 0.0 | ||
| ) | ||
| if total_mib + reserve_mib <= pool_mib * pin_fraction: |
There was a problem hiding this comment.
Refit one-GPU auto context with the graph reserve
In auto context on a multi-GPU host, _fit_context_to_vram has already capped total_mib to the old 90% budget before this new reserve check runs. If the model would fit on the best card after shrinking KV a little further (for example, 20 GiB weights on a 24 GB card leaves about 1.1 GiB KV at the 90% cap, but only about 0.27 GiB after the 2 GiB reserve), this condition fails and the loop immediately tries two GPUs instead of recomputing a reserve-aware one-GPU cap. That violates the existing “prefer fewer GPUs with reduced context” policy and can make Auto unnecessarily launch slower layer-split multi-GPU sessions.
Useful? React with 👍 / 👎.
f74932c to
f08d8e6
Compare
On a restart the constructor reaps the previous run's orphaned llama-server, but the driver does not reclaim that VRAM synchronously. _kill_orphaned_servers now returns the number of processes it killed, and __init__ arms _last_kill_monotonic when that count is positive, so the first load_model waits for VRAM to settle before ranking GPUs by free memory instead of pinning the model onto the smaller card. The compute-graph / auto-fit reserve is handled separately in #6312.
34be0d1 to
3aa42e1
Compare
Problem
On a multi-GPU box (reported with an RTX 5090 32GB plus an RTX PRO 6000 Blackwell 96GB), after a few Studio open/close cycles a GGUF starts loading onto the smaller card and then hangs at the first prompt. GPU selection ranks cards by free VRAM, so a card that momentarily reads low gets ranked below a smaller card.
Root cause: on startup
__init__reaps the previous run's orphanedllama-server, but the driver does not reclaim that VRAM synchronously. Studio already has_wait_for_vram_settleto bridge the kill to reclaim window, but it was never armed for the startup reap:_kill_orphaned_serversreturned nothing and_last_kill_monotonicstayed0.0, so the settle guard (since_kill <= 0.0) short-circuited the wait on the first load. That first load samples VRAM while the previously used (larger) card still looks occupied, ranks it below the smaller card, and pins there.Fix
_kill_orphaned_serversnow returns the number of processes it killed, and__init__arms_last_kill_monotonicwhen that count is positive. The firstload_modelafter a restart then waits for VRAM to settle before ranking GPUs, so the model loads back onto the larger card.This is intentionally narrow. The compute-graph and auto-fit VRAM budget (the other half of the original report) is handled separately and more thoroughly in #6312, so the graph-reserve changes that were in an earlier revision of this PR have been dropped to avoid overlap.
Tests
test_llama_cpp_wait_for_vram_settle.py: the reaper returns an accurate kill count (only Studio-ownedllama-serverprocesses are counted), and__init__arms the settle clock only on a positive count, leaving the0.0cold-start sentinel otherwise. The settle suite stays green.Relates to #5106 and #5680. Complements #6312.