Skip to content

[Bug] Models keep going in and out of VRAM #7164

Closed

Description

@jimster480

Unsloth
Unsloth Version
v0.1.49-beta
Package Version
2026.7.3
llama.cpp Version
b10019-mix-bd6aa58

GPUs
W7900
W7500

Just like the titles say; according to HWINFO, the models keep leaving VRAM when they are idle. Causing additional time (and extra RAM usage) for the model to respond as it transfers from RAM back into VRAM. There should be options to not even load it into RAM and just keep it in VRAM unless it is unloaded.
This is what I do with LM Studio to save ram (even though I have 128GB, I am often using alot of it).

Also there should be an option to use each GPU or not, as right now there is no option to select the GPUs where unsloth will run on, so sometimes it uses both it seems.

Activity

  1. InfoSage05 commented on Jul 16, 2026

    @InfoSage05
    Contributor

    Hi, I've implemented backend support for both GPU selection and memory placement mode on GGUF models. Here's what was done:

    Changes

    GPU Selection (gpu_ids)

    • Removed the 400 error that previously rejected gpu_ids for GGUF models.
    • gpu_ids are now validated via resolve_requested_gpu_ids and passed through to LlamaCppBackend.load_model.
    • The visible GPU list is filtered to the requested IDs before auto-selection / tensor split planning.
    • Explicit GPU pinning is preserved even when --fit fallback kicks in.
    • For Vulkan builds, physical gpu_ids are translated to compact Vulkan ordinals (Vulkan0..N).

    Memory Placement (gguf_memory_mode)

    • Added a new first-class field gguf_memory_mode with three modes:
      • auto (default) — normal memory-mapped loading.
      • pinned — locks pages in RAM via --mlock.
      • resident — loads fully into RAM via --no-mmap --mlock.
    • None, "", and "auto" are canonicalized as equivalent to avoid spurious reloads.
    • Inherited --mlock / --no-mmap from llama_extra_args are shadowed when gguf_memory_mode is set, so the first-class field always wins.
    • Both _already_in_target_state and _request_matches_loaded_settings now compare memory_mode, so changing it triggers a proper reload.

    Tests

    • New test file: test_llama_cpp_memory_mode.py (19 tests covering memory mode flags, GPU filtering, fit fallback, Vulkan translation, and auto/None equivalence).
    • Updated: test_llama_server_args.py, test_chat_load_during_training.py, test_gpu_selection.py.
    • 491 targeted tests pass, ruff check is clean.

    This should close #7164.

  2. jimster480 commented on Jul 26, 2026

    @jimster480
    Author

    I'm confused by what has changed here because the same thing is still happening and I don't see any options to change it. Is it just not in the newest version?

  3. jimster480 commented on Jul 30, 2026

    @jimster480
    Author

    The model totally unloads from VRAM + even some from Ram (depending on how high my system ram usage is) and this means that new requests take a long time to process because literally the model has to be loaded back into VRAM (even partially from disk) which makes no sense.
    There should be an option for this where the model is not put into RAM at all and just kept in VRAM unless it is unloaded.

    Image Image
  4. danielhanchen commented on Aug 28, 2026

    @danielhanchen
    Member

    On a discrete card with the model fully offloaded, Keep model in GPU memory emits no launch flag and only vetoes an idle unload, so neither toggle changes residency on your setup.

  5. LeoBorcherding commented on Sep 22, 2026

    @LeoBorcherding
    Collaborator

    Closing this, with an honest split on the two asks.

    The GPU selection half landed: each model's settings has a GPU picker now, so a load can be pinned to one card or both instead of Studio deciding. That arrived just after the 2026.7.3 you filed from.

    The residency half is answered rather than fixed. As above: on a discrete card with the model fully offloaded, "Keep model in GPU memory" emits no launch flag and only vetoes Studio's own idle unload, so neither toggle changes whether the weights stay in VRAM. If a hard "never leave VRAM" control is worth having, that is a feature request rather than this bug and is better filed as one. Nothing needed from you here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions