Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
don't kill live llama-servers when a new Studio instance starts (#7182)
Nilay1777aae37ee8
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex dadfdfd38d9..3e93a267878 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -8232,6 +8232,11 @@ class LlamaCppBackend:if not is_ours:continue+ # A live parent means a running Studio (or the user's+ # shell) still owns it -- not an orphan.+ if LlamaCppBackend._pid_parent_is_alive(proc.info["pid"]):+ continue+proc.kill()killed += 1logger.info(@@ -8284,6 +8289,9 @@ class LlamaCppBackend:if not owned:continue+ if LlamaCppBackend._pid_parent_is_alive(pid):+ continue+try:os.kill(pid, signal.SIGKILL)killed += 1diff --git a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.pyindex 3c21f417013..d0213f6079f 100644--- a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py+++ b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py@@ -373,6 +373,7 @@ def test_kill_orphaned_servers_returns_count():with (patch.dict(sys.modules, {"psutil": fake_psutil}),patch.dict(os.environ, {"LLAMA_SERVER_PATH": fake_path}),+ patch.object(LlamaCppBackend, "_pid_parent_is_alive", staticmethod(lambda pid: False)),):n = LlamaCppBackend._kill_orphaned_servers()assert n == 1, "only the Studio-owned orphan should be counted"@@ -384,11 +385,53 @@ def test_kill_orphaned_servers_returns_count():with (patch.dict(sys.modules, {"psutil": fake_psutil}),patch.dict(os.environ, {"LLAMA_SERVER_PATH": fake_path}),+ patch.object(LlamaCppBackend, "_pid_parent_is_alive", staticmethod(lambda pid: False)),):assert LlamaCppBackend._kill_orphaned_servers() == 0assert killed == []+def test_kill_orphaned_servers_spares_live_parent():+ """A Studio-owned llama-server whose parent is still running is not an+ orphan (a live Studio or the user's shell owns it) and must never be+ killed; only the true orphan (parent gone) is reaped."""+ import os++ mypid = os.getpid()+ fake_path = "/tmp/unsloth-test-llama/llama-server"+ killed: list[int] = []++ class _FakeProc:+ def __init__(self, pid, name, exe):+ self.info = {"pid": pid, "name": name, "exe": exe}++ def kill(self):+ killed.append(self.info["pid"])++ live_parent = _FakeProc(mypid + 1, "llama-server", fake_path)+ true_orphan = _FakeProc(mypid + 2, "llama-server", fake_path)++ fake_psutil = _types.ModuleType("psutil")+ fake_psutil.NoSuchProcess = type("NoSuchProcess", (Exception,), {})+ fake_psutil.AccessDenied = type("AccessDenied", (Exception,), {})+ fake_psutil.ZombieProcess = type("ZombieProcess", (Exception,), {})+ fake_psutil.process_iter = lambda attrs = None: [live_parent, true_orphan]++ with (+ patch.dict(sys.modules, {"psutil": fake_psutil}),+ patch.dict(os.environ, {"LLAMA_SERVER_PATH": fake_path}),+ patch.object(LlamaCppBackend, "_reap_recorded_pid", staticmethod(lambda: 0)),+ patch.object(+ LlamaCppBackend,+ "_pid_parent_is_alive",+ staticmethod(lambda pid: pid == mypid + 1),+ ),+ ):+ n = LlamaCppBackend._kill_orphaned_servers()+ assert n == 1, "only the true orphan should be reaped"+ assert killed == [mypid + 2], "the live-parent server must be spared"++def test_startup_reaper_arms_settle_timestamp():"""__init__ arms ``_last_kill_monotonic`` when the startup reaper kills anorphan (so the first load_model waits for VRAM to settle), and leaves the