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: verify the Diffusers main zip against a pinned SHA-256 (#11908)
Daniel Han4af7e844de42
diff --git a/studio/backend/requirements/diffusers-main.txt b/studio/backend/requirements/diffusers-main.txtindex 773355a4655..f666b555ee3 100644--- a/studio/backend/requirements/diffusers-main.txt+++ b/studio/backend/requirements/diffusers-main.txt@@ -31,6 +31,11 @@# one place. That fallback is why the commit below must stay a full 40-character SHA: an archive# records no ref, so only a SHA in the URL makes the resident build identifiable afterwards.#+# Unlike a clone, an archive's bytes are not checked against the commit, so pip and uv verify this+# SHA-256 before building; no digest line means no zip route. Bump it with the commit:+# curl -sL https://github.com/huggingface/diffusers/archive/<commit>.zip | sha256sum+# archive-sha256: 7b0d00b5b44f5ca1745d477ae4a0c2da125d58b89cff8470c422d3181a797a09+## Retiring this file: once 0.41.0 ships, bump diffusers-pin.txt to it and delete this. The family# entry already records 0.41.0 as QwenImage21Pipeline's minimum, so nothing else has to move.diffusers @ git+https://github.com/huggingface/diffusers.git@80c7ed262aeffbeb43ef13ae04baeb9b84515a69diff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex e2c5b9e8cd2..169fc1800ba 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -10658,10 +10658,34 @@ def _diffusers_main_supersedes_release() -> bool:return _diffusers_main_requested() and _diffusers_main_resident()+_ARCHIVE_SHA256_RE = re.compile(r"#\s*archive-sha256:\s*([0-9a-fA-F]{64})")+++def _archive_sha256_in_requirements(req: Path) -> "str | None":+ """The ``# archive-sha256:`` digest *req* pins for its zip, or None unless exactly one."""+ try:+ text = req.read_text(encoding = "utf-8-sig")+ except (OSError, ValueError):+ return None+ found = [+ m.group(1).lower()+ for m in (_ARCHIVE_SHA256_RE.fullmatch(line.strip()) for line in text.splitlines())+ if m+ ]+ return found[0] if len(found) == 1 else None++def _diffusers_main_archive(req: Path) -> "str | None":- """The zip route 11c takes on a host with no working git, or None when it has none."""+ """The hash-pinned zip route 11c takes with no working git, or None when it has none.++ pip and uv record the URL without the ``#sha256=`` fragment, so residency still matches it.+ """wanted = _direct_reference_in_requirements(req)- return _github_archive_url(*wanted) if wanted is not None else None+ archive = _github_archive_url(*wanted) if wanted is not None else None+ digest = _archive_sha256_in_requirements(req)+ if archive is None or digest is None:+ return None+ return f"{archive}#sha256={digest}"def _diffusers_main_needs_dependency_pass() -> bool:diff --git a/tests/studio/install/test_diffusers_pin.py b/tests/studio/install/test_diffusers_pin.pyindex c0605b8735e..86e6f17a7c9 100644--- a/tests/studio/install/test_diffusers_pin.py+++ b/tests/studio/install/test_diffusers_pin.py@@ -218,11 +218,45 @@ def test_the_main_build_falls_back_to_the_zip_when_there_is_no_git(monkeypatch):spec = [arg for arg in args if arg.startswith("diffusers @ ")]assert len(spec) == 1, argsrevision = _requirements(MAIN_FILE)[0].rpartition("@")[2].strip().lower()+ digest = module._archive_sha256_in_requirements(MAIN_FILE)+ assert digest is not None and re.fullmatch(r"[0-9a-f]{64}", digest), digest+ # The fragment is what pip and uv verify; the commit in the URL checks no bytes.assert spec[0] == (- "diffusers @ https://github.com/huggingface/diffusers/archive/" f"{revision}.zip"+ "diffusers @ https://github.com/huggingface/diffusers/archive/"+ f"{revision}.zip#sha256={digest}"), spec+def test_the_zip_route_is_skipped_without_exactly_one_pinned_digest(tmp_path, monkeypatch):+ """No single valid digest, no zip route: the host keeps the release."""+ module = _probe_module("install_python_stack_probe2e")+ spec = _requirements(MAIN_FILE)[0]+ digest = module._archive_sha256_in_requirements(MAIN_FILE)+ pin = tmp_path / "diffusers-main.txt"++ pin.write_text(f"{spec}\n", encoding = "utf-8")+ assert module._diffusers_main_archive(pin) is None+ pin.write_text(+ f"# archive-sha256: {digest}\n# archive-sha256: {'0' * 64}\n{spec}\n", encoding = "utf-8"+ )+ assert module._diffusers_main_archive(pin) is None+ pin.write_text(f"# archive-sha256: {digest[:63]}\n{spec}\n", encoding = "utf-8")+ assert module._diffusers_main_archive(pin) is None+ pin.write_text(f"# archive-sha256: {digest.upper()}\n{spec}\n", encoding = "utf-8")+ assert module._diffusers_main_archive(pin).endswith(f".zip#sha256={digest}")++ monkeypatch.delenv("UNSLOTH_DIFFUSERS_MAIN", raising = False)+ monkeypatch.setattr(module, "REQ_ROOT", tmp_path)+ monkeypatch.setattr(module, "_has_working_git", lambda: False)+ monkeypatch.setattr(module, "_progress", lambda *a, **k: None)+ monkeypatch.setattr(module, "_note", lambda *a, **k: None)+ monkeypatch.setattr(+ module, "pip_install_try", lambda *a, **k: pytest.fail("an unverified archive install")+ )+ pin.write_text(f"{spec}\n", encoding = "utf-8")+ module._diffusers_main_step()++def test_the_main_build_keeps_the_release_when_there_is_no_git_and_no_zip(monkeypatch):"""Diffusers is mandatory, unlike triton_kernels, so a host that can reach neither route mustbe left with the release the previous step installed rather than nothing at all.