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: require a published digest on upstream llama.cpp prebuilts too (#11402)
Daniel Han0ec1e926e1d7
diff --git a/studio/backend/tests/test_install_resolve_prebuilt.py b/studio/backend/tests/test_install_resolve_prebuilt.pyindex 68c4b806ab5..b087af8ce21 100644--- a/studio/backend/tests/test_install_resolve_prebuilt.py+++ b/studio/backend/tests/test_install_resolve_prebuilt.py@@ -16,6 +16,7 @@ from __future__ import annotationsimport contextlibimport ctypesimport dataclasses+import hashlibimport importlibimport jsonimport ntpath@@ -394,11 +395,21 @@ def test_sm103_host_drops_cuda128_windows_build():assert [a.name for a in kept_b200] == [cuda128.name, cuda129.name]+def _fixture_digest(name: str) -> str:+ """Stand-in for the digest GitHub publishes; a fixture without one selects nothing."""+ return hashlib.sha256(name.encode()).hexdigest()++def _upstream_release(tag, asset_names):return {"tag_name": tag,"assets": [- {"name": n, "browser_download_url": f"https://example/{n}"} for n in asset_names+ {+ "name": n,+ "browser_download_url": f"https://example/{n}",+ "digest": f"sha256:{_fixture_digest(n)}",+ }+ for n in asset_names],}diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex 4ec71458413..e008df6d6ab 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -306,6 +306,21 @@ VALIDATION_MODEL_CACHE_FILENAME = "stories260K.gguf"_RUN_STAGED_PREBUILT_VALIDATION = False+def prebuilt_needs_functional_validation(choice: "AssetChoice") -> bool:+ """True when a staged prebuilt must run the smoke test before activation.++ A release digest proves the bytes are upstream's, not that they load on this host, so+ those archives keep the test they ran while hashless. Only a manifest-approved bundle,+ which Unsloth built and exercised, skips it: that pass costs minutes of cold CUDA JIT+ on Blackwell sm_100, so it stays behind staged_validation_enabled() (#5854).+ """+ if choice.expected_sha256 is None:+ return True+ if choice.unmanifested_digest:+ return True+ return staged_validation_enabled()++def staged_validation_enabled() -> bool:"""True when the expensive llama-server GPU smoke test should run.@@ -439,6 +454,9 @@ class AssetChoice:max_sm: int | None = Noneselection_log: list[str] | None = Noneexpected_sha256: str | None = None+ # expected_sha256 came from GitHub's release digest, not the approved manifest:+ # see prebuilt_needs_functional_validation.+ unmanifested_digest: bool = False# ROCm bundles only (mirrors PublishedLlamaArtifact): umbrella gfx family# and the concrete archs the binaries were built for.gfx_target: str | None = None@@ -1332,11 +1350,23 @@ def direct_upstream_release_plan()if not attempts:raise PrebuiltFallback("no compatible upstream prebuilt asset was found")+ # These archives are extracted, chmod 0o755'd and executed, and download_file_verified+ # treats a None digest as a pass. The release we were handed already states a per-asset+ # digest, so bind every attempt to one and drop the attempts it does not cover.+ verified = _apply_release_digests(attempts, release_asset_digests(release))+ if not verified:+ raise PrebuiltFallback(+ f"{repo}@{release_tag} publishes no asset digest for any compatible prebuilt; "+ "refusing to install one unverified"+ )+ # Digest-verified but not manifest-approved, so the smoke test stays on.+ for attempt in verified:+ attempt.unmanifested_digest = Truereturn InstallReleasePlan(requested_tag = requested_tag,llama_tag = release_tag,release_tag = release_tag,- attempts = attempts,+ attempts = verified,approved_checksums = synthetic_checksums_for_release(repo,release_tag,@@ -9018,15 +9048,7 @@ def validate_prebuilt_choice(walk_back = walk_back,macos_load_probe_passed = macos_load_probe_passed,)- # Hashless external prebuilts are not in the approved-sha256- # manifest and rely on the functional smoke test as their only integrity gate,- # so they are always validated. For an approved bundle the sha256 manifest- # already proves integrity, so its runtime smoke test -- a cold CUDA-JIT pass- # costing minutes on Blackwell sm_100 -- is gated behind- # staged_validation_enabled() (constant or UNSLOTH_LLAMA_STAGED_VALIDATION),- # disabled for now. The check and the source-build fallback it triggers are- # kept intact; flip the flag / env to restore it (#5854).- if choice.expected_sha256 is None or staged_validation_enabled():+ if prebuilt_needs_functional_validation(choice):# Only branch that reads the probe, so this is where a lazy one is fetched.probe_path = resolve_validation_model(probe)validate_quantize(@@ -9120,7 +9142,7 @@ def validate_prebuilt_attempts(# read as a bad bundle and demote a healthy GPU pick to CPU -- and, since the# thunk memoises success but not failure, re-download once per attempt. Plans# that skip validation never call the thunk, so they stay lazy.- if staged_validation_enabled() or any(a.expected_sha256 is None for a in attempt_list):+ if any(prebuilt_needs_functional_validation(a) for a in attempt_list):probe = resolve_validation_model(probe)tried_fallback = initial_fallback_used@@ -10562,9 +10584,8 @@ def install_prebuilt(f"{plan.release_tag} for {host.system} {host.machine}")# Outside the handler, so a transient failure cannot demote to an older release.- if not probe_resolved and (- staged_validation_enabled()- or any(attempt.expected_sha256 is None for attempt in plan.attempts)+ if not probe_resolved and any(+ prebuilt_needs_functional_validation(attempt) for attempt in plan.attempts):probe = resolve_validation_model(probe)probe_resolved = Truediff --git a/tests/studio/install/test_llama_kind_gate_matches_selector.py b/tests/studio/install/test_llama_kind_gate_matches_selector.pyindex 13ae6c2e751..e0ff00f36b2 100644--- a/tests/studio/install/test_llama_kind_gate_matches_selector.py+++ b/tests/studio/install/test_llama_kind_gate_matches_selector.py@@ -28,6 +28,7 @@ import itertoolsimport pathlibimport reimport shutil+import hashlibimport sysimport pytest@@ -58,10 +59,21 @@ ASSET_NAMES = (f"llama-{TAG}-bin-win-vulkan-x64.zip",f"llama-{TAG}-bin-win-hip-radeon-x64.zip",)+++def _fixture_digest(name: str) -> str:+ """Stand-in for the digest GitHub publishes; a fixture without one selects nothing."""+ return hashlib.sha256(name.encode()).hexdigest()++RELEASE = {"tag_name": TAG,"assets": [- {"name": name, "browser_download_url": f"https://example.invalid/{name}"}+ {+ "name": name,+ "browser_download_url": f"https://example.invalid/{name}",+ "digest": f"sha256:{_fixture_digest(name)}",+ }for name in ASSET_NAMES],}diff --git a/tests/studio/install/test_macos_version_compat.py b/tests/studio/install/test_macos_version_compat.pyindex 3963b339fa2..4ae571af83f 100644--- a/tests/studio/install/test_macos_version_compat.py+++ b/tests/studio/install/test_macos_version_compat.py@@ -1,5 +1,6 @@"""Host-macOS-version-aware llama.cpp prebuilt selection; Mach-O samples synthesized in-process, all I/O monkeypatched."""+import hashlibimport importlib.utilimport structimport sys@@ -371,6 +372,11 @@ class TestTheProbeEnvironment:assert "DYLD_INSERT_LIBRARIES" not in seen+def _fixture_digest(name: str) -> str:+ """Stand-in for the digest GitHub publishes; a fixture without one selects nothing."""+ return hashlib.sha256(name.encode()).hexdigest()++def _fake_macos_releases(tags):return [{@@ -379,6 +385,7 @@ def _fake_macos_releases(tags):{"name": f"llama-{tag}-bin-macos-arm64.tar.gz","browser_download_url": f"https://example.com/{tag}.tar.gz",+ "digest": f"sha256:{_fixture_digest(tag)}",}],}diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex 2b848b4b2bb..cd72da7b4bb 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -1,9 +1,11 @@"""Binary selection logic in install_llama_prebuilt.py; all I/O monkeypatched."""+import hashlibimport importlib.utilimport inspectimport jsonimport os+import pathlibimport socketimport subprocessimport sys@@ -34,6 +36,12 @@ PrebuiltFallback = INSTALL_LLAMA_PREBUILT.PrebuiltFallbackLinuxCudaSelection = INSTALL_LLAMA_PREBUILT.LinuxCudaSelectionUPSTREAM_REPO = INSTALL_LLAMA_PREBUILT.UPSTREAM_REPO++def _fixture_digest(name: str) -> str:+ """Stand-in for the digest GitHub publishes; a fixture without one selects nothing."""+ return hashlib.sha256(name.encode()).hexdigest()++pick_windows_cuda_runtime = INSTALL_LLAMA_PREBUILT.pick_windows_cuda_runtimecompatible_windows_runtime_lines = INSTALL_LLAMA_PREBUILT.compatible_windows_runtime_linesapply_approved_hashes = INSTALL_LLAMA_PREBUILT.apply_approved_hashes@@ -2481,7 +2489,12 @@ class TestDirectUpstreamWindowsAmdTakesVulkan:return {"tag_name": self.TAG,"assets": [- {"name": n, "browser_download_url": f"https://example.com/{n}"} for n in names+ {+ "name": n,+ "browser_download_url": f"https://example.com/{n}",+ "digest": f"sha256:{_fixture_digest(n)}",+ }+ for n in names],}@@ -2552,7 +2565,12 @@ class TestDirectUpstreamBlackwellPin:return {"tag_name": self.TAG,"assets": [- {"name": n, "browser_download_url": f"https://example.com/{n}"} for n in names+ {+ "name": n,+ "browser_download_url": f"https://example.com/{n}",+ "digest": f"sha256:{_fixture_digest(n)}",+ }+ for n in names],}@@ -3474,7 +3492,12 @@ class TestWindowsMaskedNvidiaTakesCuda:release = {"tag_name": self.TAG,"assets": [- {"name": n, "browser_download_url": f"https://example.com/{n}"} for n in names+ {+ "name": n,+ "browser_download_url": f"https://example.com/{n}",+ "digest": f"sha256:{_fixture_digest(n)}",+ }+ for n in names],}plan = direct_upstream_release_plan(release, self._host(), UPSTREAM_REPO, "latest")@@ -4116,6 +4139,7 @@ class TestResolveSimpleMacosPin:{"name": name,"browser_download_url": f"https://example.com/{name}",+ "digest": f"sha256:{_fixture_digest(name)}",}],}@@ -4278,10 +4302,12 @@ class TestCpuFallback:{"name": f"llama-{tag}-bin-ubuntu-arm64.tar.gz","browser_download_url": f"https://x/llama-{tag}-bin-ubuntu-arm64.tar.gz",+ "digest": f"sha256:{_fixture_digest('arm64')}",},{"name": f"llama-{tag}-bin-ubuntu-x64.tar.gz","browser_download_url": f"https://x/llama-{tag}-bin-ubuntu-x64.tar.gz",+ "digest": f"sha256:{_fixture_digest('x64')}",},],}@@ -4858,3 +4884,162 @@ class TestExactSourceAssetUrl:checksums, source_repo, source_archive, exact_source, self.INSTALL_TAG)assert url == self._expected("unslothai/llama.cpp", self.INSTALL_TAG)+++# ===========================================================================+class TestDirectUpstreamRequiresAssetDigests:+ """The upstream planner must bind every attempt to a digest.++ It used to leave expected_sha256 None, which download_file_verified treats as a pass,+ so an archive the installer reroutes to by itself (Linux ARM64 Vulkan, any+ --published-repo) was extracted, chmod 0o755'd and executed unverified.+ """++ TAG = "b9365"++ def _host(self, **overrides):+ defaults = dict(+ system = "Windows",+ machine = "AMD64",+ has_physical_nvidia = False,+ has_usable_nvidia = False,+ nvidia_smi = None,+ driver_cuda_version = None,+ compute_caps = [],+ )+ defaults.update(overrides)+ return make_host(**defaults)++ def _release(self, *, with_digests):+ name = f"llama-{self.TAG}-bin-win-cpu-x64.zip"+ asset = {"name": name, "browser_download_url": f"https://example.com/{name}"}+ if with_digests:+ asset["digest"] = f"sha256:{_fixture_digest(name)}"+ return {"tag_name": self.TAG, "assets": [asset]}++ def test_every_attempt_carries_the_published_digest(self):+ plan = direct_upstream_release_plan(+ self._release(with_digests = True), self._host(), UPSTREAM_REPO, "latest"+ )+ assert plan.attempts+ for attempt in plan.attempts:+ assert attempt.expected_sha256, f"{attempt.name} would be installed unverified"++ def test_a_release_with_no_published_digest_is_refused(self):+ """Fail closed, exactly as the fork path does when no checksum covers an asset."""+ with pytest.raises(PrebuiltFallback):+ direct_upstream_release_plan(+ self._release(with_digests = False), self._host(), UPSTREAM_REPO, "latest"+ )++ def test_an_asset_whose_digest_names_another_algorithm_is_not_accepted(self):+ release = self._release(with_digests = False)+ release["assets"][0]["digest"] = "md5:" + "0" * 32+ with pytest.raises(PrebuiltFallback):+ direct_upstream_release_plan(release, self._host(), UPSTREAM_REPO, "latest")+++# ===========================================================================+class TestUpstreamDigestKeepsTheFunctionalSmokeTest:+ """Requiring a digest must not quietly disable the smoke test it replaces.++ validate_prebuilt_choice skips the test for any attempt carrying a sha256. Upstream+ attempts reached it with None and so always ran it; binding them to a release digest+ would have flipped that off for every upstream install.+ """++ TAG = "b9365"++ def _host(self, **overrides):+ defaults = dict(+ system = "Windows",+ machine = "AMD64",+ has_physical_nvidia = False,+ has_usable_nvidia = False,+ nvidia_smi = None,+ driver_cuda_version = None,+ compute_caps = [],+ )+ defaults.update(overrides)+ return make_host(**defaults)++ def _release(self):+ name = f"llama-{self.TAG}-bin-win-cpu-x64.zip"+ return {+ "tag_name": self.TAG,+ "assets": [+ {+ "name": name,+ "browser_download_url": f"https://example.com/{name}",+ "digest": f"sha256:{_fixture_digest(name)}",+ }+ ],+ }++ def test_upstream_attempts_are_marked_as_carrying_an_unmanifested_digest(self):+ plan = direct_upstream_release_plan(self._release(), self._host(), UPSTREAM_REPO, "latest")+ assert plan.attempts+ for attempt in plan.attempts:+ assert attempt.expected_sha256, attempt.name+ assert (+ attempt.unmanifested_digest+ ), f"{attempt.name} would skip the smoke test on the strength of a release digest"++ def test_the_smoke_test_still_runs_for_every_upstream_attempt(self, monkeypatch):+ monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "_RUN_STAGED_PREBUILT_VALIDATION", False)+ monkeypatch.delenv("UNSLOTH_LLAMA_STAGED_VALIDATION", raising = False)+ assert not INSTALL_LLAMA_PREBUILT.staged_validation_enabled()+ plan = direct_upstream_release_plan(self._release(), self._host(), UPSTREAM_REPO, "latest")+ for attempt in plan.attempts:+ assert INSTALL_LLAMA_PREBUILT.prebuilt_needs_functional_validation(+ attempt+ ), f"{attempt.name} lost the functional smoke test it ran while hashless"++ def test_a_manifest_approved_bundle_still_skips_it(self, monkeypatch):+ """The negative control: the expensive-path gate must still be reachable."""+ monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "_RUN_STAGED_PREBUILT_VALIDATION", False)+ monkeypatch.delenv("UNSLOTH_LLAMA_STAGED_VALIDATION", raising = False)+ approved = AssetChoice(+ repo = "unslothai/llama.cpp",+ tag = self.TAG,+ name = "llama-app-bin-win-cuda-x64.zip",+ url = "https://example.com/a.zip",+ source_label = "published",+ expected_sha256 = "a" * 64,+ )+ assert not INSTALL_LLAMA_PREBUILT.prebuilt_needs_functional_validation(approved)+ monkeypatch.setenv("UNSLOTH_LLAMA_STAGED_VALIDATION", "1")+ assert INSTALL_LLAMA_PREBUILT.prebuilt_needs_functional_validation(approved)++ def test_a_hashless_bundle_is_still_always_validated(self):+ hashless = AssetChoice(+ repo = "somebody/llama.cpp",+ tag = self.TAG,+ name = "llama-whatever.zip",+ url = "https://example.com/w.zip",+ source_label = "upstream",+ )+ assert INSTALL_LLAMA_PREBUILT.prebuilt_needs_functional_validation(hashless)++ def test_probe_preresolution_agrees_with_the_validation_decision(self):+ """All three gates must read the same predicate.++ A gate left on `expected_sha256 is None` while validation tests something wider+ would validate upstream attempts with an unresolved probe, which the probe gates'+ own comments say demotes a healthy GPU pick to CPU.+ """+ source = pathlib.Path(INSTALL_LLAMA_PREBUILT.__file__).read_text()+ stale = [+ line.strip()+ for line in source.splitlines()+ if "expected_sha256 is None" in line+ and "prebuilt_needs_functional_validation" not in line+ ]+ # The predicate's own first clause is the single legitimate reader.+ assert stale == ["if choice.expected_sha256 is None:"], stale++ def test_every_upstream_attempt_resolves_the_probe_up_front(self):+ plan = direct_upstream_release_plan(self._release(), self._host(), UPSTREAM_REPO, "latest")+ assert any(+ INSTALL_LLAMA_PREBUILT.prebuilt_needs_functional_validation(a) for a in plan.attempts+ ), "the probe would be resolved lazily inside the per-candidate handler"