Skip to content

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.

Studio: fix Windows desktop updates failing integrity checks (#8185)

Etherl968d2e50ffae
diff --git a/pyproject.toml b/pyproject.toml
index e5f58c5a59f..066e7943587 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -78,7 +78,14 @@ studio = [
[tool.setuptools.packages.find]
include = ["unsloth*", "unsloth_cli*", "studio", "studio.backend*"]
-exclude = ["images*", "tests*", "*.node_modules", "*.node_modules.*"]
+exclude = [
+ "images*",
+ "tests*",
+ "unsloth_compiled_cache*",
+ "*.unsloth_compiled_cache*",
+ "*.node_modules",
+ "*.node_modules.*",
+]
[project.optional-dependencies]
# Studio's server stack, mirroring studio/backend/requirements/studio.txt.
diff --git a/studio/backend/requirements/extras.txt b/studio/backend/requirements/extras.txt
index 1601ccbfae3..d62c529924b 100644
--- a/studio/backend/requirements/extras.txt
+++ b/studio/backend/requirements/extras.txt
@@ -7,7 +7,8 @@ scikit-learn==1.7.1
# Additional extras
jiwer # WER/CER metrics for vision OCR save-merge benchmarks
omegaconf
-einx
+einx<0.4.3; sys_platform == "win32"
+einx; sys_platform != "win32"
pyloudnorm
openai-whisper
av # PyAV: decode dictation audio (webm/opus/mp3/…) for the Whisper STT sidecar
diff --git a/studio/backend/tests/test_torchao_select.py b/studio/backend/tests/test_torchao_select.py
index e4775a10a68..fa7355fd941 100644
--- a/studio/backend/tests/test_torchao_select.py
+++ b/studio/backend/tests/test_torchao_select.py
@@ -18,6 +18,7 @@ import pytest
# install_python_stack.py lives at repo_root/studio/install_python_stack.py
_INSTALL_SCRIPT = Path(__file__).resolve().parents[2] / "install_python_stack.py"
+_EXTRAS_REQUIREMENTS = Path(__file__).resolve().parent.parent / "requirements" / "extras.txt"
def _load_module(monkeypatch):
@@ -79,6 +80,19 @@ def test_default_spec_matches_table(monkeypatch):
assert mod._select_torchao_spec("2.9.0") == mod._TORCHAO_DEFAULT_SPEC
+def test_matching_torchao_pin_does_not_need_force_reinstall(monkeypatch):
+ mod = _load_module(monkeypatch)
+ monkeypatch.setattr(mod, "_installed_distribution_version", lambda _name: "0.17.0")
+ assert mod._exact_distribution_spec_is_installed("torchao==0.17.0")
+ assert not mod._exact_distribution_spec_is_installed("torchao==0.16.0")
+
+
+def test_windows_first_hop_uses_einx_wheel_without_shared_test_tree():
+ requirements = _EXTRAS_REQUIREMENTS.read_text(encoding = "utf-8")
+ assert 'einx<0.4.3; sys_platform == "win32"' in requirements
+ assert 'einx; sys_platform != "win32"' in requirements
+
+
@pytest.mark.parametrize(
("rocm_windows_torch_installed", "installed_torch_is_windows_rocm"),
[
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 903ef224ab7..0cf11a258e5 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -328,6 +328,24 @@ def _probe_installed_torch_version() -> str | None:
return lines[-1] if lines else None
+def _installed_distribution_version(name: str) -> str | None:
+ """Return installed distribution metadata without importing the package."""
+ try:
+ from importlib.metadata import PackageNotFoundError, version
+ return version(name)
+ except (PackageNotFoundError, ValueError):
+ return None
+
+
+def _exact_distribution_spec_is_installed(spec: str) -> bool:
+ """Whether a simple ``name==version`` pin already matches this venv."""
+ match = re.fullmatch(r"([A-Za-z0-9][A-Za-z0-9._-]*)==([^\s]+)", spec)
+ if match is None:
+ return False
+ installed = _installed_distribution_version(match.group(1))
+ return installed is not None and installed == match.group(2)
+
+
def _installed_torch_is_windows_rocm() -> bool:
"""Return True when the target venv currently has a Windows ROCm torch build.
@@ -4052,10 +4070,9 @@ def install_python_stack() -> int:
req = REQ_ROOT / "extras-no-deps.txt",
)
- # 4. Overrides (torchao) -- force-reinstall to a version matching the venv's
- # torch so its C++ extensions load (see _select_torchao_spec). Skipped when
- # torch is unavailable (Intel Mac GGUF-only) and on Windows ROCm (no working
- # build; see below).
+ # 4. Install the torch-matched torchao override. Reinstall only when the pin
+ # changes, since Windows can remove shared files during replacement.
+ # Skip when torch is unavailable or Windows ROCm has no working build.
if NO_TORCH:
_progress("dependency overrides (skipped, no torch)")
elif _rocm_windows_torch_installed or _installed_torch_is_windows_rocm():
@@ -4069,10 +4086,12 @@ def install_python_stack() -> int:
_torch_ver = _probe_installed_torch_version()
_torchao_spec = _select_torchao_spec(_torch_ver)
_note(f"torch {_torch_ver or 'unknown'} detected -- installing {_torchao_spec}")
+ _torchao_args = ["--no-cache-dir"]
+ if not _exact_distribution_spec_is_installed(_torchao_spec):
+ _torchao_args.insert(0, "--force-reinstall")
pip_install(
"Installing dependency overrides",
- "--force-reinstall",
- "--no-cache-dir",
+ *_torchao_args,
_torchao_spec,
)
diff --git a/tests/studio/install/test_package_discovery.py b/tests/studio/install/test_package_discovery.py
new file mode 100644
index 00000000000..ac565b3dac3
--- /dev/null
+++ b/tests/studio/install/test_package_discovery.py
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+import re
+from fnmatch import fnmatchcase
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[3]
+
+
+def test_generated_compiled_caches_are_excluded():
+ text = (REPO_ROOT / "pyproject.toml").read_text(encoding = "utf-8")
+ finder = text.split("[tool.setuptools.packages.find]", 1)[1].split("\n[", 1)[0]
+ exclude = re.search(
+ r"^exclude\s*=\s*\[(.*?)\]",
+ finder,
+ re.MULTILINE | re.DOTALL,
+ )
+ assert exclude, "no packages.find exclude list in pyproject.toml"
+ patterns = re.findall(r'["\']([^"\']+)["\']', exclude.group(1))
+
+ for package in ("unsloth_compiled_cache", "studio.backend.unsloth_compiled_cache"):
+ assert any(fnmatchcase(package, pattern) for pattern in patterns)