Skip to content

Studio: arm the VRAM-settle wait after the startup orphan reaper - #6315

Merged
danielhanchen merged 1 commit into
mainfrom
studio-gpu-vram-settle-graph-reserve
Jun 15, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-gpu-vram-settle-graph-reserve

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

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 orphaned llama-server, but the driver does not reclaim that VRAM synchronously. Studio already has _wait_for_vram_settle to bridge the kill to reclaim window, but it was never armed for the startup reap: _kill_orphaned_servers returned nothing and _last_kill_monotonic stayed 0.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_servers now returns the number of processes it killed, and __init__ arms _last_kill_monotonic when that count is positive. The first load_model after 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-owned llama-server processes are counted), and __init__ arms the settle clock only on a positive count, leaving the 0.0 cold-start sentinel otherwise. The settle suite stays green.

Relates to #5106 and #5680. Complements #6312.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 1823 to 1824
if len(selected) >= 2 and cumulative >= model_size_mib:
return sorted(selected), False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@danielhanchen
danielhanchen force-pushed the studio-gpu-vram-settle-graph-reserve branch from f74932c to f08d8e6 Compare June 15, 2026 11:14
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.
@danielhanchen
danielhanchen force-pushed the studio-gpu-vram-settle-graph-reserve branch from 34be0d1 to 3aa42e1 Compare June 15, 2026 11:16
@danielhanchen danielhanchen changed the title Studio: fix GGUF load pinning the smaller GPU after a restart and hanging Studio: arm the VRAM-settle wait after the startup orphan reaper Jun 15, 2026
@danielhanchen
danielhanchen merged commit 6c919bb into main Jun 15, 2026
32 checks passed
@danielhanchen
danielhanchen deleted the studio-gpu-vram-settle-graph-reserve branch June 15, 2026 11:22
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