Repository navigation
fix(studio): release the inference subprocess's VRAM when its last model unloads - #8221
Conversation
…del unloads The child's unload frees the model and calls empty_cache, but the caching allocator can only return blocks nothing still references, and the accelerator context is never returned while the process lives. An idle worker therefore kept its high-water mark. gpu_arbiter evicts between owners, and the transformers orchestrator and the llama.cpp GGUF backend are both CHAT, so switching between them is an intra-owner handoff that no evictor covers. The stranded VRAM is also invisible to the GGUF context fit, which probes its own process, so the fit budgets against a card it reads as empty. Shut the worker down once nothing is left to serve. A teardown failure is logged, never surfaced as a failed unload.
|
Reviewed and pushed a small follow-up to this branch. The change itself is correct and I could not find a way to break it:
What I pushed:
Test runs on the branch: Every one of those 78 also fails on clean main here (video backend, RAG with the sqlite extension and pymupdf missing, web, desktop auth, mcp). I diffed the node ids against a main run, so nothing fails because of this PR. Agreed the VRAM probe and |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Fixes #8220.
The transformers inference subprocess stays alive after its last model unloads, holding several GB of VRAM that nothing reclaims. Measured on a 16 GB card: 3.89 GB stranded, card at 16.12 GB against 16.0 GB dedicated.
unload_modelalready callsclear_gpu_cache()in the child and it runs, so this is not a missingempty_cache(). The allocator can only return blocks nothing still references, and the accelerator context outlives every model regardless. The surviving reference is unidentified; this change fixes the layer that holds independent of it.gpu_arbiterevicts between owners, and both the transformers orchestrator and the llama.cpp GGUF backend are ownerCHAT, so switching between them is an intra-owner handoff no evictor covers. Training start and diffusion/video acquisition both already tear the subprocess down; this adds the third case.The stranded VRAM is also invisible to the GGUF context fit, which probes
torch.cuda.mem_get_infoin the parent process, so the fit budgets against a card it reads as empty (GPUs free: [(0, 15939)]with 3.89 GB resident elsewhere). That probe is a separate issue and is not touched here.Change
After a successful unload, if no models remain resident and no load is in flight, shut the worker down. The next load respawns it.
A teardown failure is logged, never surfaced: the unload has already succeeded at that point, and letting the exception reach the outer handler would report a successful unload as failed. (My first draft had exactly that bug; it broke four existing tests in
test_orchestrator_unload_cancel.py, which is how it surfaced.)Guarded on
loading_modelsso a load already reusing the worker isn't killed.Verification
New tests cover the last-model teardown, no teardown while another model is resident, and no teardown while a load is in flight.
test_inference_orchestrator_crash_message.py::test_subprocess_crash_message_includes_signal_and_oom_hintfails on this branch and on a clean tree (verified by stashing), so it is pre-existing and unrelated.test_mcp_server.pyandtest_rag_ocr_fallback.pyfail collection on missing optional deps, also pre-existing.