diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index c222b43a9f..d1c943ee16 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -58,6 +58,11 @@ class LlamaCppBackend: def is_loaded(self) -> bool: return self._process is not None and self._healthy + @property + def is_active(self) -> bool: + """True if a llama-server process exists (loading or loaded).""" + return self._process is not None + @property def base_url(self) -> str: return f"http://127.0.0.1:{self._port}" diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py index e9ad9a6995..5299d168f5 100644 --- a/studio/backend/routes/inference.py +++ b/studio/backend/routes/inference.py @@ -343,11 +343,11 @@ async def unload_model( Routes to the correct backend (llama-server for GGUF, Unsloth otherwise). """ try: - # Check if the GGUF backend has this model loaded + # Check if the GGUF backend has this model loaded or is loading it llama_backend = get_llama_cpp_backend() - if ( - llama_backend.is_loaded - and llama_backend.model_identifier == request.model_path + if llama_backend.is_active and ( + llama_backend.model_identifier == request.model_path + or not llama_backend.is_loaded ): llama_backend.unload_model() logger.info(f"Unloaded GGUF model: {request.model_path}")