Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a VRAM reserve floor and cap mechanism to prevent auto-fit context spilling to CPU on consumer cards with thin VRAM cushions. It refactors the multi-GPU pooled budget calculation to apply the VRAM reserve floor once across the entire pool rather than per device, and adds comprehensive unit tests to verify the new behavior on consumer, datacenter, and small cards, as well as multi-GPU pools. I have no feedback to provide.
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: 328e5b4665
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a5657304e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return min( | ||
| max((1.0 - frac) * total_mib, _MIN_VRAM_RESERVE_MIB), _MAX_VRAM_RESERVE_FRAC * total_mib |
There was a problem hiding this comment.
Use the floored reserve for pinned selections too
This new floor is only applied through _pool_budget_mib, but the explicit-context and file-size-only branches still call _select_gpus(..., total_by_idx=...), whose usable calculation subtracts only (1 - usable_fraction) * total. On a tight 24 GB card with an explicit --ctx-size or missing KV metadata, _select_gpus can still return use_fit=False based on the old ~1.2 GiB cushion, so Studio emits -ngl -1 instead of --fit on and spends the 3 GiB headroom this patch is trying to protect. Please make _select_gpus use the same floored reserve when totals are known.
Useful? React with 👍 / 👎.
On a 24 GB desktop card, loading a 27B GGUF would pin
-ngl -1, then silently offload layers back to CPU at runtime and run at roughly half speed. Reported in #6682 (Qwen3.6-27B-MTP, ~14 tok/s instead of 30-35).Closes #6682
Problem
The GGUF auto-fit (#6312) reserves a flat 5% of total VRAM before sizing context. On a 24 GB card that is only ~1.2 GB, too thin to absorb what the byte estimate can't capture exactly: the CUDA context and compute buffers, and the gap between nvidia-smi's reported free and the VRAM CUDA actually exposes. So auto-fit sizes the context right up against the card's real usable limit. At that edge part of the load ends up on host RAM and generation roughly halves, even with nothing else on the card.
Clean-card context sweep for
Qwen3.6-27B-MTPUD-Q4_K_XL, q8 KV, on an idle RTX 3090 (24 GB):At the ~113k that 5% advertises, the 27B is already down to ~35 of 60 tok/s with the GPU sitting ~1 GB short of full and host RAM climbing (the load is not staying fully on the device). Backing the context off restores full speed. A desktop or browser sharing the GPU makes it worse: at
-c 112128with a 3.5 GB desktop held, it ran at 14.6 tok/s (reporter: 14.3).Fix
Floor the reserve:
min(max(0.05*total, 3072 MiB), 0.125*total). So the reserve is 5% base, floored at 3 GiB, capped at 12.5%:The floor is a per-pool cushion. The desktop drift and the one-lump layer-split compute buffer it covers are not per-device, so it is applied once across the pool, not per GPU. It lives in one helper (
_pooled_usable_mib) at the single place the auto-context budget is computed. Ranking and the tensor-parallel paths are untouched.Speed (RTX 3090, 24 GB)
Same model and card, measured idle and with a 1 GB desktop sharing the GPU:
The fix holds full speed through a ~1 GB desktop. It is a fixed cushion, not a guarantee. A 27B with a ~3 GB desktop on 24 GB is at the card's edge (the fix gives 21.9 vs 14.6 there), and a steady desktop gets sized down to a smaller full-speed context instead.
Generalizes across architecture and cache type:
gemma-3-27b(SWA): studio: deterministic VRAM auto-fit for GGUF (MTP reserve, compute buffer, total-based budget) #6312 picks 122880 at 23 tok/s; fix picks 78592 at 40 tok/s (full speed).No context regression for models that already fit
Base (#6312) vs fix, same hardware. Only the two 27Bs that were spilling get reduced. Everything else is byte-identical:
Multi-GPU
The per-pool floor matters here. On a constrained 49+24 GB pool (neither card fits the model alone), a naive per-device floor would reserve 3 GiB per card and drop to the 4096 fallback with
--fit. The per-pool floor pins both GPUs at 36352, 74 tok/s, no spill.Verification
Code change is ~50 lines (two helpers and one call-site swap). The rest is tests.