From b91116cacc1c6fe18fb0c2455ef6bbdecaf08ab1 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Fri, 12 Jun 2026 08:16:01 -0700 Subject: [PATCH] studio: declare UNSLOTH_IS_PRESENT at backend startup (#6262) The studio backend lazily imports unsloth_zoo submodules (export's llama_cpp, hardware's vllm_utils, mlx, chat_templates). Each imports the top-level unsloth_zoo, which raises 'Please install Unsloth via pip install unsloth' unless UNSLOTH_IS_PRESENT is set (normally by import unsloth). Only hardware.py set it per-site; the rest crash on a clean install, and it surfaced on Windows. Set it once at backend startup (as unsloth does on import) so every site, and the DiffusionGemma runner, works across platforms. Follow-up to #6259 (which covered only the shim subprocess env). --- studio/backend/main.py | 5 +++++ studio/backend/run.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/studio/backend/main.py b/studio/backend/main.py index 2b34b11fef..064e261753 100644 --- a/studio/backend/main.py +++ b/studio/backend/main.py @@ -193,6 +193,11 @@ if _STUDIO_ROOT_RESOLVED != _LEGACY_STUDIO_ROOT: if not os.environ.get("UNSLOTH_LLAMA_CPP_PATH"): os.environ["UNSLOTH_LLAMA_CPP_PATH"] = str(_STUDIO_ROOT_RESOLVED / "llama.cpp") +# The studio bundles unsloth_zoo; declare unsloth present (as `import unsloth` +# does) so its lazy submodule imports (export, hardware, mlx) and the +# DiffusionGemma runner never trip the install guard on a clean install. +os.environ.setdefault("UNSLOTH_IS_PRESENT", "1") + import hashlib import mimetypes import re as _re diff --git a/studio/backend/run.py b/studio/backend/run.py index a883154c4a..a8e9a46a66 100644 --- a/studio/backend/run.py +++ b/studio/backend/run.py @@ -545,6 +545,11 @@ if _STUDIO_ROOT_RESOLVED != _LEGACY_STUDIO_ROOT: if not os.environ.get("UNSLOTH_LLAMA_CPP_PATH"): os.environ["UNSLOTH_LLAMA_CPP_PATH"] = str(_STUDIO_ROOT_RESOLVED / "llama.cpp") +# The studio bundles unsloth_zoo; declare unsloth present (as `import unsloth` +# does) so its lazy submodule imports (export, hardware, mlx) and the +# DiffusionGemma runner never trip the install guard on a clean install. +os.environ.setdefault("UNSLOTH_IS_PRESENT", "1") + def _write_pid_file(): """Write the current process PID to the studio PID file."""