Repository navigation
fix(studio): avoid resident GGUF mappings for Windows no-reserve loads - #10618
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Confirmed apply_model_memory_policy in studio/backend/core/inference/llama_server_args.py still emits nothing for the no-reserve case, so the setting has no effect on a Windows full-offload load, and the dio branch is the right place for it. You mention end-to-end validation through saved settings and placement detection is still outstanding, so let me know once that is done and I will review. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3ddf6f7af7
ℹ️ 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".
| # argv, or a stale "reserving" spends a full reload | ||
| # the running server already satisfies. | ||
| self._memory_state = resolve_effective_memory_state( | ||
| self._record_memory_state( |
There was a problem hiding this comment.
Drop managed DirectIO for the CPU-projector retry
On Windows with no-reserve enabled, if a fully offloaded vision launch fails and this recovery moves the projector into host RAM via --no-mmproj-offload, the branch strips only the fit-selected load mode and leaves the managed --load-mode dio in _cpu_projector_cmd. The surrounding code already establishes that this retry invalidates the GPU-placement memory proof; retaining DirectIO makes the CPU-resident projector use allocated, non-pageable storage rather than mmap and can substantially increase host-memory pressure or make the recovery fail. Strip the managed DirectIO pair from this copied command (without clearing the base-command record), as the --fit on and CPU-fallback retries do.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and it is the fourth rung of the same invariant: the block right above it already strips the fit's mode with 'it moves the projector into host RAM the fit credited to VRAM', and use_mmap covers mmap / mmap+mlock / auto only, so under dio those bytes are an allocated buffer rather than a mapping. I had covered the --fit on retry, the arch-crash retry and the CPU-fallback replay and missed this one. Now stripped with clear_record = False, matching the note there that the record must stay nameable for the fallbacks below, and the memory record is re-taken from the stripped argv.
There was a problem hiding this comment.
Correcting myself: I agreed with this last round and it is wrong on the same point as the round-5 projector item, so I have reverted the strip I added here.
--load-mode does not reach the projector. mtmd_context_params carries no use_mmap or load_mode field, and clip.cpp reads the mmproj through its own open_ifstream_binary into allocated buffers, so moving the projector to host RAM does not turn a mapping into a buffer: it was a buffer either way. This retry moves the projector and leaves the main model fully offloaded, which is the placement the pair was chosen for, so the pair should stay.
The block directly above it is not the precedent I took it for. It withdraws the FIT's --load-mode none because the fit's VRAM proof credited the projector to the card, which this retry voids. That is an accounting question, not a loader one.
The three rungs that keep the withdrawal all move the WEIGHTS: the --fit on retry hands placement back to llama.cpp, the arch-crash retry runs on a different device set, and the CPU replay appends --device none.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f72d745005
ℹ️ 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".
| _mem_gpu_offload_confirmed = bool( | ||
| not _mem_host_resident | ||
| and self._build_offers_gpu_backend(binary) | ||
| and (_detected_gpus or gpu_indices) | ||
| ) |
There was a problem hiding this comment.
Exclude CPU-resident projectors from the DirectIO proof
On Windows vision loads where the main GGUF fully fits in VRAM but the auto planner has set _mmproj_cpu_pinned (or the user supplied --no-mmproj-offload), this expression still confirms full GPU offload because _mem_host_resident only classifies the main-model weights. The command later appends --no-mmproj-offload, so the projector is loaded into host memory under the managed DirectIO mode; unlike mmap, this makes its CPU-resident data an allocated, non-pageable buffer. The CPU-projector crash retry already strips DirectIO for exactly this placement, but the equivalent initial placement does not, increasing host-memory pressure and undermining the no-reserve policy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. _mem_host_resident is the main-model answer, so a fully offloaded vision launch can still append --no-mmproj-offload and put the projector in host RAM, and use_mmap excludes dio, so those bytes are allocated rather than mapped. The asymmetry you name is exact: I added the withdrawal to the CPU-projector crash retry last round and left the identical initial placement confirming a full offload. _mem_gpu_offload_confirmed now also requires not _mem_projector_in_host_memory, built from launch_mmproj_path with _mmproj_cpu_pinned or _resolved_mmproj_offload(_mem_extra_args, _mem_env) is False, which is the same resolved helper the fit budget reads so the two cannot drift.
There was a problem hiding this comment.
Correcting myself: I agreed with this and it is wrong, and I have reverted the change I made for it.
The stated mechanism does not hold. --load-mode is a main-model loader setting: mtmd_context_params in tools/mtmd/mtmd.h has no use_mmap or load_mode field, and clip.cpp loads the mmproj through its own open_ifstream_binary into buffers it allocates with ggml_dup_tensor, consulting no loader mode. So the projector is an allocated host copy under mmap and under DirectIO alike, and where it lands says nothing about whether the pair is right.
What my change actually did was withhold DirectIO from the multi-GB main-model weights whenever a vision model had a CPU-pinned projector, which is precisely the resident mapping #9033 is about. Reverted in the next commit. I should have checked the loader before agreeing; the analogy I leaned on (the crash retry stripping the fit's mode) is about the fit's VRAM accounting, which the projector move really does void, not about mmap versus DirectIO.
…reading as settled
…e the placement unconditionally
…w dio on residency
… managed DirectIO from policy activity
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
…rch retry agree with its own launch Three fixes to the DirectIO gate, each one a case where a device or a relaunch was credited with an answer nothing had given. AMD is no longer self-evidently discrete. `_SELF_EVIDENTLY_DISCRETE` held rocm and hip on the grounds that `_weights_in_host_memory` classifies them upstream, but that classifier reads the driver through a ROCm torch and `_rocm_unified_memory_gpu_ids` returns the same empty set for "no APU here" and for "there is no ROCm torch to ask". Its own caller only skips a page-lock, so folding the two is right there. A loader choice cannot: there is no Windows ROCm torch wheel, so on the one platform this decision runs on the classifier never answers, and reading that as discrete hands DirectIO to a Strix Halo whose VRAM is system RAM -- the whole model read into allocated host buffers, strictly worse than the mapping it replaces. A new `_rocm_classification_answered` asks whether anything looked at the device, and an AMD id now confirms only when something did. Same rule the Vulkan branch already applies through `type_known`. CUDA is untouched, and where the classifier can run a discrete Radeon confirms exactly as before. The arch-crash retry asks residency the way its launch did. Of the three `probe_vulkan` gates, two were widened to `_mem_should_mlock or _mem_probe_for_dio` precisely because an unprobed Vulkan device answers the conservative "host resident" and `_mem_should_mlock` is always False under no-reserve. The third was left on the mlock flag alone, so on a Windows Vulkan build that rung asked with the probe off and answered True for the same discrete card the launch had just confirmed as a full offload. And it records from the argv. The arm rebuilt the memory record from `_mem_extras + _retry_managed`, which by then does not add up to `cmd` -- it drops the managed DirectIO pair the rung above may have appended. That recorded a mapped load for a streaming child, and the no-reserve comparator reads `dio_applicable` with `direct_io` False as a placement needing a reload, one the relaunch reproduces exactly. The rung 30 lines earlier states this rule in a comment; this arm is now the argv-based form of it.
The setting descriptions promised DirectIO. Windows llama.cpp does not do DirectIO: `llama_file::impl` there takes `use_direct_io` as `[[maybe_unused]]` and reads through buffered `ReadFile`, and the `O_DIRECT` path is `#ifdef __linux__`. There is no `FILE_FLAG_NO_BUFFERING` anywhere in the tree. What `--load-mode dio` buys on Windows is the absence of the mapping, which is the whole point of unslothai#9033, so all twelve locales and the override notice now say that instead. Sentence structure kept identical across the locales so they stay parallel; the `dio: "DirectIO"` label is untouched, since that is the name of the llama.cpp mode rather than a claim about the platform. Also condenses the comments the previous commit added, which had grown longer than the code they explain. Checked: python AST parses, all thirteen TS/TSX files parse via the TypeScript compiler API, the twelve locales still define the three keys non-empty with no interpolation placeholders, run_ruff_format leaves the Python unchanged, and the memory / load-mode / arch-gate / placement suites are 2546 passed 0 failed.
|
Pushed three fixes and a wording correction directly to this branch ( 1. An AMD APU was confirmed as a discrete full offload, and got DirectIO
It matters on the one platform this policy fires on: there is no Windows ROCm wheel, so on Windows the classifier never answers, and the empty set was read as "discrete". Under Reproduced on a real Strix Halo on the AMD CI pool. Windows box
The Linux half of the same pool is the control. There a ROCm torch exists ( The fix adds 2. The arch-crash retry contradicted its own launchOf the three
3. The same rung recorded state from parts rather than the argvIt rebuilt the record from The rung thirty lines earlier already states the rule, so this is now the argv-based form of it:
4. The descriptions promised DirectIO, which Windows does not do
Worth knowing for the description: Verification
One thing I did not change
Still outstanding from your side: the end-to-end check through saved settings, placement detection and the UI on Windows. The numbers above cover policy output and the classification chain, not that whole path. |
Comments only, no code change: 395 added comment lines down to 249. The blocks that stay are the ones naming a mistake the next reader would otherwise make; the rest restated the code.
unslothai#10618 The gate proved a classifier was importable and something enumerated, not that any device was read. _rocm_unified_memory_gpu_ids skips a device it cannot read, and an absent device reads as discrete, so an unreadable APU could still be handed DirectIO over its own system RAM.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Problem
On Windows, "Don't reserve system RAM" removes the per-model
None/--no-mmapchoice and leaves the default mmap path. Windows cannot partially unmap the GGUF after offload, becauseunmap_fragmentis a no-op in llama.cpp, so nearly the entire file stays resident in its mapping even after a full GPU offload. In a native Windows reproduction, a 2.99 GB GGUF stayed resident despite Task Manager showing only a small private working set.Fixes #9033. Reproduction and loader-mode A/B evidence.
Change
Emit
--load-mode diofor this policy when Windows, a confirmed full offload to a discrete GPU, and binary support for--load-modeall apply. Three parts:Confirming the placement. The offload has to be established positively, not inferred from
_weights_in_host_memory. That predicate exists to decide whether a page-lock may be skipped, so it errs towards "host resident" for a device it did not probe and stays False for an-ngla CPU-only build accepts and ignores. Neither direction is safe for choosing a loader.The launch asks the build instead.
llama-server --list-devicesis the loader's own verdict, so a CUDA build with no cudart, a HIP build with noamdhip64, a plugin renamed to disable it, a plugin built for another vendor and a plugin reachable only throughGGML_BACKEND_PATHall come out right without inspecting a filename, and a pinned device the host reports but the child cannot open is caught for the same reason. The one thing ggml does not report is whether a device's VRAM is carved out of system RAM, so a Vulkan target additionally needs the existing probe to answer that every selected device is discrete. Anything unanswered declines, because an iGPU "full offload" is still host-backed. The probe runs only where its answer can reach a flag, which is Windows on a build that understands--load-mode, and once per load.Withdrawing it when the placement changes. Under DirectIO llama.cpp does not map the file (
use_mmapcoversmmap/mmap+mlock/autoonly), so any layer it then leaves on the CPU is an allocated buffer rather than a pageable mapping. The pair is taken back out on the three rungs that hand placement back: the--fit onretry, the arch-crash retry, and the CPU fallback replay. The--fit offretry does the reverse and applies the pair when it proves a full offload the fitted attempt did not.Making the setting visible to the reload check.
mmapanddioare both "no full host copy", so the existing(mlock, reserves_ram)state cannot tell them apart, and toggling the setting on a loaded model would silently do nothing until a manual unload. The launch records what the child runs and what a relaunch under no-reserve would run, both from one call into the real policy chain one toggle apart, and the comparator asks only whether they differ.Explicit choices still win throughout: a per-model
mmap, a hand-typed--load-mode, and an inheritedLLAMA_ARG_MMAP/LLAMA_ARG_LOAD_MODEall take precedence, since no-reserve owns the reservation rather than the loader. Setting descriptions and the override notice are reworded across all twelve locales to describe the policy without promising zero host RAM.Deliberately out of scope
The vision projector is not part of the decision.
mtmd_context_paramscarries nouse_mmaporload_modefield andclip.cppreads the mmproj through its ownifstreaminto allocated buffers, so the pair says nothing about where the projector lands.A speculative drafter pinned to the CPU does inherit
--load-mode, and there is no per-model draft flag, so one setting covers both models. Keeping DirectIO trades the drafter's mapping for the main model's, which is the trade this setting exists to make.Validation
studio/backendsuite diffed against the merge base: no new failures.b10830-mix-d5c17a0CUDA13 server on an RTX 5070 Ti / 32 GB RAM. Stored settings and confirmed placement are fixtures: no-reserve on, keep-resident off, requested modeNone.Both runs offload 34/34 layers of Qwen3.5-4B-MTP UD-Q4_K_XL, retain MTP, generate 16 tokens, and terminate on unload. Background RAM pressure differs between runs, so the reduction is not a fixed guarantee. Non-mapped loading still needs CPU buffers and can raise private commit while lowering resident RAM.
Remaining validation
End-to-end validation through Studio's saved settings, placement detection and UI on Windows is still outstanding; the native test covers policy output and server behaviour, not that whole path. Existing loaded models need an unload/reload. This does not address #9790's surviving process after unload.
UI evidence
Settings -> Resources -> Model Memory, driven against two isolated installs built from this PR's merge base (
8ee07d6ae) and its head, with one Playwright scene run against both. "Keep model in GPU memory" is carried as a control and is byte-identical on both sides.The row, with the one-line description:
The info-icon hint, hovered. The old text promised memory-mapped loading was kept, which is the opposite of what the patched policy does on a confirmed full offload:
--no-mmapand--mlock.--no-mmapand--mlock.The same reword is applied to all twelve locales.