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 diffusion: key learned peaks on the unsloth mirror a fresh install downloads (#13847)
Daniel Hanfc91656ff7b5
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.pyindex bb622cbfd55..10cf6379d5b 100644--- a/studio/backend/core/inference/diffusion.py+++ b/studio/backend/core/inference/diffusion.py@@ -2624,15 +2624,41 @@ def _local_weights_digest(path: Any) -> Optional[str]:def _peak_model_identity(- repo_id: Any, gguf_filename: Optional[str], kind: Optional[str], base: Any+ repo_id: Any,+ gguf_filename: Optional[str],+ kind: Optional[str],+ base: Any,+ fetch_base: Optional[str] = None,) -> str:"""The exact build for the learned-peak key: the denoiser source and its weights' revision / fingerprint, plus thecompanion base and its revision for a GGUF / single-file load. ``unknown`` (no learned peak used or recorded)- when a revision cannot be read."""+ when a revision cannot be read. ``fetch_base``: the repo the load actually read ``base`` from."""from .diffusion_component_sizes import checkpoint_fingerprint-+ from .diffusion_families import mirror_repo++ def _fingerprint(+ repo: Any,+ filename: Optional[str] = None,+ fetched: Optional[str] = None,+ ) -> tuple[Any, Any]:+ if fetched and str(fetched) != str(repo):+ return fetched, checkpoint_fingerprint(fetched, filename)+ revision = checkpoint_fingerprint(repo, filename)+ if revision or filename or fetched:+ return repo, revision+ # No load decision: a fresh install may hold only the unsloth/ mirror.+ mirror = mirror_repo(str(repo)) if repo else None+ if mirror and mirror != str(repo):+ mirrored = checkpoint_fingerprint(mirror)+ if mirrored:+ return mirror, mirrored+ return repo, revision++ pipeline = (kind or "pipeline") == "pipeline"+ repo_id, revision = _fingerprint(+ repo_id, gguf_filename, fetch_base if pipeline and str(base) == str(repo_id) else None+ )source = f"{repo_id}/{gguf_filename}" if gguf_filename else str(repo_id)- revision = checkpoint_fingerprint(repo_id, gguf_filename)if not revision:return "unknown"if str(revision).startswith("local:"):@@ -2641,8 +2667,8 @@ def _peak_model_identity(return "unknown"revision = f"{revision}:{weights}"identity = f"{source}@{revision}"- if (kind or "pipeline") != "pipeline" and base and str(base) != str(repo_id):- base_revision = checkpoint_fingerprint(base)+ if not pipeline and base and str(base) != str(repo_id):+ base, base_revision = _fingerprint(base, None, fetch_base)if not base_revision:return "unknown"if str(base_revision).startswith("local:"):@@ -9507,7 +9533,9 @@ class DiffusionBackend:"; ".join(refined_plan.reasons),)plan = refined_plan- peak_model = _peak_model_identity(repo_id, gguf_filename, kind, base)+ peak_model = _peak_model_identity(+ repo_id, gguf_filename, kind, base, fetch_base+ )if getattr(pipe, "_unsloth_loras", None):peak_model = ("unknown" # adapters baked in at load: a build the key cannot namediff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.pyindex 7d65168f79f..dc707d3ace3 100644--- a/studio/backend/core/inference/video.py+++ b/studio/backend/core/inference/video.py@@ -1431,6 +1431,9 @@ class _VideoLoadState:# resolves a bare device. Mirrors the image backend.placed_ordinal: Optional[int] = Nonegguf_filename: Optional[str] = None+ # The repo the load actually read ``base_repo`` from (the unsloth mirror on a fresh install): the learned-peak key+ # names it. None: no load decision (the key falls back to the mirror when the upstream is not cached).+ fetch_base: Optional[str] = None# Content-detected checkpoint variant identifier (LTX-2.3 "ltx-2.3-22b-distilled" / "-dev"), read before the names.variant_id: Optional[str] = None# Resident MiniMax-H3 denoiser partition, if any.@@ -3653,6 +3656,7 @@ def _calibration_revision(state: Any) -> Optional[str]:getattr(state, "gguf_filename", None),getattr(state, "kind", None),getattr(state, "base_repo", None),+ getattr(state, "fetch_base", None),)try:pipe._unsloth_calibration_revision = revision or ""@@ -9690,6 +9694,7 @@ class VideoBackend:repo_id = repo_id,display_repo_id = display_repo_id,base_repo = base,+ fetch_base = fetch_base,device = device,gpu_ordinal = target.ordinal,placed_ordinal = placed_cuda_ordinal(target),@@ -10937,6 +10942,7 @@ class VideoBackend:repo_id = repo_id,display_repo_id = display_repo_id,base_repo = base,+ fetch_base = fetch_base,device = device,gpu_ordinal = umem_target.ordinal,placed_ordinal = placed_cuda_ordinal(umem_target),diff --git a/studio/backend/tests/test_diffusion_learned_peaks.py b/studio/backend/tests/test_diffusion_learned_peaks.pyindex a8c0308a702..a4016fede98 100644--- a/studio/backend/tests/test_diffusion_learned_peaks.py+++ b/studio/backend/tests/test_diffusion_learned_peaks.py@@ -1209,7 +1209,109 @@ def test_peak_model_identity_names_the_whole_build(monkeypatch):src = (__import__("pathlib").Path(dm.__file__).parent / "diffusion.py").read_text(encoding = "utf-8")- assert "peak_model = _peak_model_identity(repo_id, gguf_filename, kind, base)" in src+ # whitespace-free: the formatter may wrap the call+ assert "peak_model=_peak_model_identity(repo_id,gguf_filename,kind,base,fetch_base)" in "".join(+ src.split()+ )+++def test_peak_model_identity_reads_the_unsloth_mirror_on_a_fresh_install(monkeypatch):+ """Studio fetches a mirrored vendor base from unsloth/: with only the mirror cached, the key must still name a+ revision (the mirror's), or learned peaks are never recorded nor read on a default install."""+ import core.inference.diffusion as diffusion+ import core.inference.diffusion_component_sizes as sizes+ import core.inference.diffusion_families as families++ revisions = {+ ("unsloth/FLUX.2-klein-4B", None): "m1",+ ("unsloth/dit-GGUF", "dit-Q4.gguf"): "g1",+ }+ monkeypatch.setattr(+ sizes, "checkpoint_fingerprint", lambda repo, filename = None: revisions.get((repo, filename))+ )+ monkeypatch.setattr(+ families,+ "mirror_repo",+ lambda repo: {"black-forest-labs/flux.2-klein-4b": "unsloth/FLUX.2-klein-4B"}.get(+ (repo or "").lower()+ ),+ )+ assert (+ diffusion._peak_model_identity("black-forest-labs/FLUX.2-klein-4B", None, "pipeline", None)+ == "unsloth/FLUX.2-klein-4B@m1"+ )+ assert diffusion._peak_model_identity(+ "unsloth/dit-GGUF", "dit-Q4.gguf", "gguf", "black-forest-labs/FLUX.2-klein-4B"+ ) == ("unsloth/dit-GGUF/dit-Q4.gguf@g1+unsloth/FLUX.2-klein-4B@m1")+ # No mirror and no cached revision: still unknown.+ assert diffusion._peak_model_identity("org/unmirrored", None, "pipeline", None) == "unknown"+++def test_peak_model_identity_keys_on_the_repo_the_load_fetched(monkeypatch):+ """An upstream cache holding only model_index.json while the load pulled the weights from the mirror: the key+ names the mirror the load read, not the upstream id whose index happens to be cached (and vice versa)."""+ import core.inference.diffusion as diffusion+ import core.inference.diffusion_component_sizes as sizes+ import core.inference.diffusion_families as families++ revisions = {+ ("black-forest-labs/FLUX.2-klein-4B", None): "u1",+ ("unsloth/FLUX.2-klein-4B", None): "m1",+ ("unsloth/dit-GGUF", "dit-Q4.gguf"): "g1",+ }+ monkeypatch.setattr(+ sizes, "checkpoint_fingerprint", lambda repo, filename = None: revisions.get((repo, filename))+ )+ monkeypatch.setattr(+ families,+ "mirror_repo",+ lambda repo: {"black-forest-labs/flux.2-klein-4b": "unsloth/FLUX.2-klein-4B"}.get(+ (repo or "").lower()+ ),+ )+ up, mirror = "black-forest-labs/FLUX.2-klein-4B", "unsloth/FLUX.2-klein-4B"+ assert diffusion._peak_model_identity(up, None, "pipeline", up, mirror) == f"{mirror}@m1"+ assert diffusion._peak_model_identity(up, None, "pipeline", up, up) == f"{up}@u1"+ assert (+ diffusion._peak_model_identity("unsloth/dit-GGUF", "dit-Q4.gguf", "gguf", up, mirror)+ == f"unsloth/dit-GGUF/dit-Q4.gguf@g1+{mirror}@m1"+ )+ # The load read the upstream bytes but only the mirror's revision is cached: no key, never the mirror's.+ del revisions[(up, None)]+ assert diffusion._peak_model_identity(up, None, "pipeline", up, up) == "unknown"+ assert diffusion._peak_model_identity(up, None, "pipeline", up, mirror) == f"{mirror}@m1"+++def test_video_peak_key_names_the_repo_the_load_fetched(monkeypatch):+ """An upstream video cache holding only model_index.json while the load staged the complete mirror: the video+ calibration key names the mirror the weights came from, not the partial upstream snapshot."""+ import core.inference.diffusion_component_sizes as sizes+ import core.inference.video as video++ up, mirror = "Wan-AI/Wan2.2-TI2V-5B-Diffusers", "unsloth/Wan2.2-TI2V-5B-Diffusers"+ revisions = {(up, None): "u1", (mirror, None): "m1"}+ monkeypatch.setattr(+ sizes, "checkpoint_fingerprint", lambda repo, filename = None: revisions.get((repo, filename))+ )++ def state(fetch_base):+ return types.SimpleNamespace(+ pipe = types.SimpleNamespace(),+ repo_id = up,+ base_repo = up,+ kind = "pipeline",+ gguf_filename = None,+ fetch_base = fetch_base,+ )++ assert video._calibration_revision(state(mirror)) == f"{mirror}@m1"+ assert video._calibration_revision(state(up)) == f"{up}@u1"+ # no load decision: the upstream's own revision, as before+ assert video._calibration_revision(state(None)) == f"{up}@u1"+ src = "".join((__import__("pathlib").Path(video.__file__)).read_text(encoding = "utf-8").split())+ assert "fetch_base" in video._VideoLoadState.__dataclass_fields__+ # both torch loaders (load_pipeline, the H3 modular pipeline) hand their fetch repo to the state+ assert src.count("base_repo=base,fetch_base=fetch_base,") == 2def test_phase_table_seed_needs_its_measured_configuration(klein_pipe):