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
Studio: restart a crashed GGUF model instead of showing it loaded (#15847)
Nilay565b2c1dda8c
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 7d9775677db..4c42641ef45 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -35006,13 +35006,9 @@ class LlamaCppBackend:return Truedef _start_mtp_crash_watchdog(self) -> None:- """Background poll that recovers on an MTP crash even when no request- observes it (direct proxy endpoints, or nothing in flight).-- Armed only for a live MTP launch; the no-MTP reload disarms it, so it- can't loop.- """- if not self._mtp_runtime_fallback_active:+ """Recover a llama-server that dies with no request watching. Never armed by a non-MTP+ recovery reload, so a server that keeps dying can't loop."""+ if not self._mtp_runtime_fallback_active and getattr(_AUTO_RECOVERY_LOAD, "active", False):returnproc = self._processif proc is None:@@ -35028,7 +35024,7 @@ class LlamaCppBackend:while not stop.wait(1.0):if proc.poll() is not None:if not stop.is_set():- self._maybe_recover_from_mtp_crash()+ self._maybe_recover_from_mtp_crash() or self._respawn_if_dead()returnt = threading.Thread(target = _watch, daemon = True, name = "mtp-crash-watchdog")diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.pyindex 2a0ab4d851a..a46bcb7fa59 100644--- a/studio/backend/tests/conftest.py+++ b/studio/backend/tests/conftest.py@@ -18,6 +18,7 @@ for _up in _iso.parents:import contextlibimport errno+import functoolsimport itertoolsimport osimport shutil@@ -393,6 +394,28 @@ def _no_sandbox_mover_outlives_its_test(monkeypatch):_drain_sandbox_movers()[email protected](autouse = True)+def _no_crash_watchdog_outlives_its_test(monkeypatch):+ # Every load arms the crash watchdog, and one left running replays a real load_model in a later test.+ llama = sys.modules.get("core.inference.llama_cpp")+ backend = getattr(llama, "LlamaCppBackend", None)+ if backend is None:+ yield+ return+ armed = []+ start = backend._start_mtp_crash_watchdog++ @functools.wraps(start)+ def _tracked(self):+ armed.append(self)+ return start(self)++ monkeypatch.setattr(backend, "_start_mtp_crash_watchdog", _tracked)+ yield+ for armed_backend in armed:+ armed_backend._stop_mtp_crash_watchdog()++def pytest_configure(config):config.addinivalue_line("markers",diff --git a/studio/backend/tests/test_llama_cpp_idle_crash_respawn.py b/studio/backend/tests/test_llama_cpp_idle_crash_respawn.pynew file mode 100644index 00000000000..c477a8c1c59--- /dev/null+++ b/studio/backend/tests/test_llama_cpp_idle_crash_respawn.py@@ -0,0 +1,83 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++from __future__ import annotations++import subprocess+import sys+import threading+from pathlib import Path++import pytest++_BACKEND_DIR = str(Path(__file__).resolve().parent.parent)+if _BACKEND_DIR not in sys.path:+ sys.path.insert(0, _BACKEND_DIR)++from core.inference.llama_cpp import GgufLoadIntent, LlamaCppBackend+++def _child():+ return subprocess.Popen([sys.executable, "-c", "import time; time.sleep(120)"])+++def loaded():+ children = []+ backend = LlamaCppBackend()+ intent = GgufLoadIntent(model_identifier = "unsloth/test-GGUF")+ loads = []+ reloaded = threading.Event()++ def spawn():+ child = _child()+ children.append(child)+ backend._process = child+ backend._healthy = True+ backend._start_mtp_crash_watchdog()+ return child++ def fake_load_model(load_intent):+ loads.append(load_intent)+ spawn()+ reloaded.set()+ return True++ backend._model_identifier = intent.model_identifier+ backend._last_load_intent = intent+ backend.load_model = fake_load_model+ yield backend, spawn, intent, loads, reloaded+ backend._stop_mtp_crash_watchdog()+ for child in children:+ child.kill()+ child.wait()+++def test_idle_server_death_reloads_without_a_request(loaded):+ backend, spawn, intent, loads, reloaded = loaded+ first = spawn()+ first.kill()+ first.wait()+ assert reloaded.wait(timeout = 10)+ assert loads == [intent]+ assert backend._process is not first+ assert backend._process.poll() is None+ assert backend.is_loaded+++def test_recovered_server_dying_again_is_not_reloaded_in_a_loop(loaded):+ backend, spawn, intent, loads, reloaded = loaded+ spawn().kill()+ assert reloaded.wait(timeout = 10)+ reloaded.clear()+ backend._process.kill()+ assert not reloaded.wait(timeout = 3)+ assert loads == [intent]+++def test_unload_does_not_bring_the_server_back(loaded):+ backend, spawn, intent, loads, reloaded = loaded+ spawn()+ backend.unload_model()+ assert not reloaded.wait(timeout = 3)+ assert loads == []diff --git a/studio/backend/tests/test_tensor_parallel.py b/studio/backend/tests/test_tensor_parallel.pyindex a79a73386f2..f8d9b06e6aa 100644--- a/studio/backend/tests/test_tensor_parallel.py+++ b/studio/backend/tests/test_tensor_parallel.py@@ -24,7 +24,7 @@ def _shared_setup_1(monkeypatch):proc = _ToggleProcess()b._process = procfired = threading.Event()- monkeypatch.setattr(b, "_maybe_recover_from_mtp_crash", lambda *a, **k: fired.set())+ monkeypatch.setattr(b, "_maybe_recover_from_mtp_crash", lambda *a, **k: fired.set() or True)b._start_mtp_crash_watchdog()return b, fired, proc@@ -1019,7 +1019,6 @@ def test_crash_watchdog_ignores_intentional_termination(monkeypatch):@pytest.mark.parametrize("mutate",[- lambda b: setattr(b, "_mtp_runtime_fallback_active", False),lambda b: setattr(b, "_process", None),],)