Skip to content

[Bug] Studio: the inference subprocess keeps its VRAM after its last model is unloaded, and the GGUF context fit can't see it #8220

Closed

Description

@LeoBorcherding

Summary

Switching from a transformers chat model to a GGUF one leaves the transformers inference subprocess alive holding several GB of VRAM. Nothing evicts it, and the GGUF context fit cannot see it, so the fit budgets context against a card it reads as empty and the GPU ends up overcommitted.

Measured on a 16 GB card: 3.89 GB stranded, card at 16.12 GB against 16.0 GB dedicated, spilling into shared memory.

Environment

  • Windows 11, AMD Radeon RX 9060 XT 16 GB, ROCm backend (device 'ROCm0')
  • 32 GB DDR5

Reproduction

  1. Train a LoRA (Qwen3.5-2B QLoRA here), then chat with it. Studio spawns a transformers inference subprocess.
  2. Generate a few times. (Compare-to-base does two passes, which raises the allocator high-water mark.)
  3. Load a GGUF chat model.
  4. Check per-process VRAM.

Observed, from the backend log:

23:30:08  Inference subprocess started (pid=8396)
23:30:38  GPU Memory [After loading ...]: 1.90GB/15.92GB (11.9% used, 14.03GB free)
23:36:06  Compare mode: disabling adapters on '...' for base model generation
23:36:50  Compare mode: enabling adapters on '...' for LoRA generation
23:40:12  Model '...Qwen3.5-2B_1786249655' successfully unloaded.
23:47:54  <GGUF load>

pid 8396 was still alive ~1h45m later holding 3.89 GB, having grown from the 1.90 GB it reported at load.

Why nothing reclaims it

unload_model in core/inference/inference.py already calls clear_gpu_cache() (gc.collect() + synchronize() + empty_cache() + ipc_collect()) inside the subprocess, and it runs. It does not reclaim, so a reference to the model's GPU tensors survives del self.models[model_name]. I have not identified which one; torch.compile was enabled on this run, which is a candidate but unconfirmed.

Independently, the accelerator context itself is never returned while the process lives, so even a perfect empty_cache() would leave some behind.

The existing safety systems don't cover this transition:

transition evicts the subprocess?
training start yes, free_chat_models_for_training()
diffusion / video takes the GPU yes, gpu_arbiter._evict_chat()
transformers chat -> GGUF chat no

gpu_arbiter evicts between owners, and both backends are owner CHAT, so this is an intra-owner handoff with no evictor. The arbiter already knows the process matters:

# Kill the subprocess too: its base CUDA context holds VRAM diffusion needs.
orchestrator._shutdown_subprocess(timeout = 5.0)

That line only runs for diffusion and video.

Why it goes unnoticed

The GGUF fit probes free VRAM with torch.cuda.mem_get_info from the parent backend process, which on Windows reports that process's budget rather than device residency. With 3.89 GB held in another process it logged:

GPUs free: [(0, 15939)]

an essentially untouched 16 GB card. _CTX_FIT_VRAM_FRACTION = 0.97 then maximises context into that phantom headroom.

Not the cause

  • Not a RAM spill. The GGUF ran fully on GPU (-ngl -1, 0 CPU layers). Its 7.30 GB of private RAM is WDDM's shadow copy of VRAM, expected on Windows.
  • Not the context estimator. It predicted 8.94 GB against 8.17 GB actual.
  • Not compare mode. It toggles disable_adapter_layers()/enable_adapter_layers() on one model; no second copy. It only raises the allocator high-water mark.

Fix

Shut the worker down once it has nothing left to serve. Separate follow-ups worth filing: make the VRAM probe see other processes, and stop the fit spending 97% of the card on KV cache (it chose 121344 ctx = 6.0 GB of KV for a 6.3 GB model).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions