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: an unverified cached .pt no longer demotes the baseline-format safetensors twin (#17342)
Daniel Hanf6dffef67c12
diff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.pyindex 090ffa75125..34672067a4e 100644--- a/studio/backend/core/inference/diffusion_prequant.py+++ b/studio/backend/core/inference/diffusion_prequant.py@@ -673,13 +673,28 @@ def prefer_cached_pickle_twins(return Truereturn False+ prefer_safetensors = (os.environ.get(PREFER_SAFETENSORS_ENV) or "").strip().lower() in (+ "1",+ "true",+ "yes",+ "on",+ )++ def _reusable(name: str) -> bool:+ if not _ok(name) or not _cached(name):+ return False+ # same pickle trust rule as below+ if name.lower().endswith(_PICKLE_SUFFIXES):+ return not prefer_safetensors and _verified(name)+ return True+# A cached container of an artifact beats an uncached one of the SAME artifact: never download a second copy.for comfy in [n for n in out if is_comfy_prequant_filename(n)]:stem = _artifact_stem(comfy)twins = [n for n in out if n != comfy and _artifact_stem(n) == stem]if not twins:continue- hit = next((t for t in twins if _ok(t) and _cached(t)), None)+ hit = next((t for t in twins if _reusable(t)), None)if _cached(comfy):if hit is None and _ok(comfy) and out.index(comfy) > out.index(twins[0]):out.remove(comfy)@@ -703,12 +718,7 @@ def prefer_cached_pickle_twins(hit,comfy,)- if (os.environ.get(PREFER_SAFETENSORS_ENV) or "").strip().lower() in (- "1",- "true",- "yes",- "on",- ):+ if prefer_safetensors:return outfor st in [diff --git a/studio/backend/tests/test_prequant_prefer_cached_pickle.py b/studio/backend/tests/test_prequant_prefer_cached_pickle.pyindex 6c67bc7e76d..eee5a0fbe97 100644--- a/studio/backend/tests/test_prequant_prefer_cached_pickle.py+++ b/studio/backend/tests/test_prequant_prefer_cached_pickle.py@@ -700,6 +700,24 @@ def test_cached_own_pickle_offline_never_asks_for_the_twin(hub):assert hub.downloads == [("Model-INT8.pt", True)][email protected]("why", ["sha_mismatch", "no_lfs_record", "reuse_off", "prefer_st"])+def test_unverified_cached_pickle_does_not_demote_the_hosted_twin(hub, monkeypatch, why):+ """Only the own safetensors 404s: the hosted twin loads, never the cached pickle the Hub does not vouch for."""+ hub.cache("Model-INT8.pt")+ hub.hosted = {COMFY, "Model-INT8.pt"}+ if why == "sha_mismatch":+ hub.hub_sha["Model-INT8.pt"] = hashlib.sha256(b"other").hexdigest()+ elif why == "no_lfs_record":+ hub.hub_sha["Model-INT8.pt"] = None+ elif why == "reuse_off":+ monkeypatch.setenv(cws.ENV_DISABLE, "0")+ else:+ monkeypatch.setenv(KILL_SWITCH, "1")+ assert pq.prefer_cached_pickle_twins(REPO, _comfy_dit().candidate_filenames)[0] == COMFY+ assert _resolve(_comfy_dit()) == hub.cached[(REPO, COMFY)]+ assert hub.fetched == [COMFY]++def test_cached_comfy_twin_stays_first(hub):hub.cache(COMFY)hub.cache("Model-INT8.pt")