Repository navigation
Description
name: Unsloth Studio Bug: When loading a GGUF model with full VRAM offloading (-ngl -1) in Unsloth Studio Desktop on Windows, system RAM allocated during the loading phase is not released. Even when the model and KV cache reside entirely in GPU VRAM, significant system memory remains occupied.
about: Report a problem with the Unsloth Studio desktop app or web UI
title: "[Studio Bug] System RAM not released after VRAM offload due to missing --no-mmap flag"
labels: bug
assignees: ""
Environment
Where are you using Unsloth?
- Studio desktop application
- Studio web UI (
unsloth studio) - Unsloth CLI
- Python package or notebook
- Colab or Kaggle
Operating system and version:
Windows 11
GPU model(s) and accelerator backend:
NVIDIA GeForce RTX 5090 (32GB VRAM), CUDA Backend[cite: 4]
Versions:
Unsloth Studio Desktop (Managed Subprocess Mode)[cite: 4]
What happened?
Steps to reproduce:
- Load a large model (
unsloth/Qwen3.8-27B-GGUFUD-Q4_K_XL +mmproj-F16.gguf) in Unsloth Studio[cite: 4]. - Set configuration for full VRAM offloading (
-ngl -1)[cite: 4]. - Observe that system RAM spikes as the model is read into memory, but is never released back to the OS pool despite the model residing entirely in GPU VRAM.
Expected behavior:
When full GPU offloading is utilized (-ngl -1), system memory should be released after the model and KV cache are loaded into VRAM.
Actual behavior:
The Studio backend orchestrator launches llama-server.exe using default memory mapping (mmap) as logged in "backend-backend-1786854602953-2-s01_2.log"[cite: 4]. Because --no-mmap is absent from the command arguments, the Windows memory manager caches the ~17.6 GB of model and projection files in the system working set indefinitely[cite: 4]. Additionally, PyTorch and the Python runtime retain memory on the heap following the torch warm initialization sequence shown in "server-20260815-213003-pid19064_2.log"[cite: 5].
Model and operation involved:
Inference and loading of unsloth/Qwen3.8-27B-GGUF (variant UD-Q4_K_XL) and mmproj-F16.gguf[cite: 4].
Diagnostics and logs
From "backend-backend-1786854602953-2-s01_2.log":
[1786854616593][stdout] {"timestamp": "2026-08-16T04:30:16.593204Z", "level": "info", "event": "Starting llama-server: C:\Users\shadu\.unsloth\llama.cpp\build\bin\Release\llama-server.exe -m C:\Users\shadu\.cache\huggingface\hub\models--unsloth--Qwen3.8-27B-GGUF\snapshots\f1bfb127c64f7072bdd2cad55f258b9c8b2910fe\Qwen3.8-27B-UD-Q4_K_XL.gguf --port 61036 --parallel 4 --flash-attn on --no-context-shift -c 131072 --alias unsloth/Qwen3.8-27B-GGUF -ngl -1 --fit off --metrics --slot-save-path C:\Users\shadu\.unsloth\studio\cache\llama-slots --kv-unified --threads 2 --jinja --cache-type-k q8_0 --cache-type-v q8_0 --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-kwargs {"enable_thinking": true, "preserve_thinking": false} --mmproj C:\Users\shadu\.cache\huggingface\hub\models--unsloth--Qwen3.8-27B-GGUF\snapshots\f1bfb127c64f7072bdd2cad55f258b9c8b2910fe\mmproj-F16.gguf --cache-ram 0 --ctx-checkpoints 0"}
Model-specific logs, if applicable
N/A
Python package or notebook, if applicable
N/A
Additional context
The primary issue is the omission of the --no-mmap flag when passing arguments to llama-server.exe. Adding this flag programmatically when -ngl -1 is detected on Windows systems would resolve the system RAM retention issue. Furthermore, running an explicit garbage collection (gc.collect()) step after the Python backend completes torch warm could recover the initial warmup overhead.
I loaded additional applications on my computer to see if system ram allocated to the model would release but it doesn't.
See attached screen shots.
Activity
indrajeetapache commentedon Aug 17, 2026
The launch already matches those toggles:
mmap on, no --no-mmap / --mlock, plus the Windows full-offload--cache-ram 0 --ctx-checkpoints 0.“Don’t reserve system RAM” is meant to keep mmap and drop
--no-mmap. Adding--no-mmap on -ngl -1would allocate a full host copy, which is the opposite of that setting.Windows often still shows mmap’d GGUF pages in the working set after VRAM offload. Happy to look at a working-set trim if that’s what you want; I would not add
--no-mmapwithout thattinker-42 commentedon Aug 17, 2026
tinker-42 commentedon Aug 22, 2026
Two things:
Looking at Resource Monitor: Cached is only 3.9GB, In-use is 27.8GB. If this were ordinary reclaimable mmap cache, I’d expect it sitting in Cached, and I’d expect it to drop under memory pressure — I tested that (loaded other apps) and it doesn’t. Is there a chance the CUDA upload path pins the mmap’d region itself (cudaHostRegister or similar) during the VRAM copy, rather than staging through a separate buffer? That would explain non-reclaimable “In use” pages independent of the --no-mmap question entirely.
Second — would --direct-io (-dio) be the more correct fix rather than --no-mmap? Current llama.cpp treats it as a distinct load path (mmap=false, direct_io=true, different buffer type than the mmap-backed one) that reads via unbuffered I/O rather than staging a full private heap copy — so it shouldn’t hit the “allocates a full host copy” problem you flagged for plain --no-mmap. I dug into apply_model_memory_policy/apply_load_mode_policy in your repo, and it looks like --direct-io is already deliberately excluded from what “Don’t reserve system RAM” strips (_RAM_RESERVING_FLAGS only covers --no-mmap and --no-direct-io, not the affirmative -dio). So this isn’t actually a request for new behavior — it looks like it already works today via the Extra Arguments box, just undocumented. I’ll confirm when I’m back at my machine as I am away from my machine for a couple of weeks but if that’s right, it might be worth either (a) surfacing -dio as a first-class option next to the existing toggles rather than something users have to discover by reading the source, or (b) if there’s a reason it’s being kept extras-only, I’d be curious why — since per your own _strip_reserving_load_modes comment, dio “holds no full copy” the same as mmap does.
konst-sh commentedon Aug 28, 2026
same thing - all gpu offloading is on, not reserve system memory is on, yet on almost every request it unloads everything back to system ram. this sucks because the machine become unusable when the ram exausted
Imagineer99 commentedon Sep 9, 2026
Reproduced the Windows resident-RAM behavior on an RTX 5070 Ti with 32 GB RAM using the official
b10830-mix-d5c17a0CUDA13-newer asset and a smaller Qwen3.5-4B-MTP UD-Q4_K_XL GGUF.The process has a 3.314 GiB working set but only 0.459 GiB private working set. Read-only
VirtualQueryEx,GetMappedFileNameandQueryWorkingSetExinspection attributes 2,979,696,640 resident bytes to the 2,990,664,000-byte GGUF itself, alongside CUDA weights. This is measured resident file-backed memory, not a full private resident duplicate.Changing only the loader mode gives:
All runs complete a short generation and release the test process on unload. Private commit is distinct from physical private RAM; the non-mapped runs have higher private commit despite lower resident RAM. Process and GPU accounting can overlap, so these columns should not be added together.
The matching Windows mmap implementation maps the whole file and its
unmap_fragment()is a no-op. The loader cleanup calls it for offloaded ranges. This agrees with the measured retained mapping; it does not establish that those pages are permanently locked or unreclaimable.Reproduction flags, with model and port supplied separately:
The small model offloads 34/34 layers. The MTP-off comparison replaces
draft-mtpwithnone; the loader comparisons add--load-mode dioor--load-mode none. This is a direct llama-server reproduction, not a full Studio UI test. It does not reproduce the surviving-process-after-unload behavior in #9790.Short-term workaround for the confirmed full-offload case: disable both Model Memory toggles, select Mmap/Mlock → None, reload, and verify
--load-mode noneor--no-mmapin the generated command. Required CPU buffers still consume RAM. With “Don't reserve system RAM” enabled, Studio vetoes None/no-mmap, so selecting None alone does not test this workaround.A local candidate fix uses DirectIO for the no-reserve policy on supported Windows builds when full discrete-GPU offload is confirmed, preserving CPU/partial-offload behavior and explicit mmap overrides. It is not pushed or released yet. The reason a separate report's explicit DirectIO selection disappeared from its launch command remains unverified.
Say what the loader actually does on Windows, and tighten the comments