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: pair slim whisper bundles on the ggml tree id, not the -mix- tag suffix (#7817)
Daniel Han9b452cb3b377
diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex 72ac8b26ae6..bcbc3d99ced 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -433,6 +433,9 @@ class ApprovedReleaseChecksums:resolved_source_ref: str | None = Nonesource_commit: str | None = Nonesource_commit_short: str | None = None+ # git tree id of ggml/ in the built source: changes exactly when ggml does,+ # so it is the ABI key for slim whisper bundles.+ ggml_tree: str | None = Noneartifacts: dict[str, ApprovedArtifactHash] = field(default_factory = dict)@@ -1430,6 +1433,7 @@ def parse_approved_release_checksums(source_commit = normalize_source_commit(payload.get("source_commit"))source_commit_short = payload.get("source_commit_short")+ ggml_tree = payload.get("ggml_tree")source_repo = payload.get("source_repo")source_repo_url = payload.get("source_repo_url")source_ref_kind = normalize_source_ref_kind(payload.get("source_ref_kind"))@@ -1454,6 +1458,7 @@ def parse_approved_release_checksums(source_commit_short = source_commit_shortif isinstance(source_commit_short, str) and source_commit_shortelse None,+ ggml_tree = ggml_tree if isinstance(ggml_tree, str) and ggml_tree else None,artifacts = artifacts,)@@ -5678,6 +5683,8 @@ def write_prebuilt_metadata("source_ref_kind": approved_checksums.source_ref_kind,"requested_source_ref": approved_checksums.requested_source_ref,"resolved_source_ref": approved_checksums.resolved_source_ref,+ # Read back by install_whisper_prebuilt.py to pair slim bundles.+ "ggml_tree": recorded_ggml_tree(approved_checksums, choice),"bundle_profile": choice.bundle_profile,"runtime_line": choice.runtime_line,"coverage_class": choice.coverage_class,@@ -5798,6 +5805,48 @@ def sync_marker_llama_backend(install_dir: Path, llama_backend: str | None) -> Nlog(f"existing install reused; recorded llama_backend={llama_backend!r} from this run")+def recorded_ggml_tree(+ approved_checksums: ApprovedReleaseChecksums, choice: AssetChoice+) -> str | None:+ """The ggml tree to record, or None when it does not describe this install.++ The tree comes from the fork release's own checkout. A fork plan can install+ an approved ggml-org archive instead (choice.repo differs), built from+ upstream ggml, so the fork tree must not be recorded for it.+ """+ tree = approved_checksums.ggml_tree+ if not isinstance(tree, str) or not tree:+ return None+ return tree if choice.repo == approved_checksums.repo else None+++def sync_marker_ggml_tree(install_dir: Path, ggml_tree: str | None) -> None:+ """Backfill the ggml tree id when the bundle is reused unchanged.++ write_prebuilt_metadata only runs on a real install, so without this an+ already-current install would keep a tree-less marker forever. Unlike+ llama_backend, None means "the release declared none" (upstream ggml-org+ tags), not "clear it".+ """+ if not isinstance(ggml_tree, str) or not ggml_tree:+ return+ marker_path = install_dir / "UNSLOTH_PREBUILT_INFO.json"+ try:+ marker = json.loads(marker_path.read_text(encoding = "utf-8"))+ except (OSError, ValueError):+ return+ if not isinstance(marker, dict) or marker.get("ggml_tree") == ggml_tree:+ return+ marker["ggml_tree"] = ggml_tree+ if not _write_marker(marker_path, marker):+ log(+ f"WARNING: could not record ggml_tree={ggml_tree!r} in {marker_path}; "+ "slim whisper pairing will fall back to the tag suffix"+ )+ return+ log(f"existing install reused; recorded ggml_tree={ggml_tree!r} from this run")++def expected_install_fingerprint(*,llama_tag: str,@@ -5894,6 +5943,17 @@ def installed_llama_runtime(install_dir: Path | None = None) -> tuple[Path, str,return bin_dir, release_tag, profile if isinstance(profile, str) else ""+def installed_llama_ggml_tree(install_dir: Path | None = None) -> str | None:+ """ggml tree id of the managed llama.cpp install; None for installs predating+ it. Kept out of installed_llama_runtime() to keep that tuple's shape."""+ root = install_dir if install_dir is not None else default_managed_llama_dir()+ metadata = load_prebuilt_metadata(root)+ if metadata is None:+ return None+ tree = metadata.get("ggml_tree")+ return tree if isinstance(tree, str) and tree else None++def runtime_payload_health_groups(choice: AssetChoice) -> list[list[str]]:if choice.install_kind in {"linux-cpu", "linux-arm64"}:return [@@ -6880,6 +6940,10 @@ def install_prebuilt(install_dir,persisted_llama_backend(persist_llama_backend, current.attempts[0]),)+ sync_marker_ggml_tree(+ install_dir,+ recorded_ggml_tree(current.approved_checksums, current.attempts[0]),+ )returnwith scratch_dir("unsloth-llama-prebuilt-") as work_dir:probe_path = work_dir / "stories260K.gguf"@@ -6904,6 +6968,10 @@ def install_prebuilt(install_dir,persisted_llama_backend(persist_llama_backend, choice),)+ sync_marker_ggml_tree(+ install_dir,+ recorded_ggml_tree(plan.approved_checksums, choice),+ )returnlog("selected "@@ -6928,7 +6996,13 @@ def install_prebuilt(force_cpu = persist_force_cpu,llama_backend = persist_llama_backend,)- except ExistingInstallSatisfied:+ except ExistingInstallSatisfied as satisfied:+ # Third reuse path: the reinstall was skipped, so+ # write_prebuilt_metadata does not run here either.+ sync_marker_ggml_tree(+ install_dir,+ recorded_ggml_tree(plan.approved_checksums, satisfied.choice),+ )returnexcept PrebuiltFallback as exc:if _environment_fatal_reason(exc):diff --git a/studio/install_whisper_prebuilt.py b/studio/install_whisper_prebuilt.pyindex f1a7fce5e04..3c2215e31f5 100644--- a/studio/install_whisper_prebuilt.py+++ b/studio/install_whisper_prebuilt.py@@ -95,6 +95,7 @@ InstallSelection = core.InstallSelectionReleaseBundle = core.ReleaseBundlellama_detect_host = llama.detect_hostinstalled_llama_runtime = llama.installed_llama_runtime+installed_llama_ggml_tree = llama.installed_llama_ggml_tree# Late-binding seam for prebuilt_core: name lookups hit this module's globals# first (so monkeypatches apply), then the core defaults.@@ -336,26 +337,44 @@ def artifacts_for_host(# ── Slim selection (paired with the installed llama.cpp ggml runtime) ──def _llama_ggml_commit(tag: str) -> str | None:- """The ggml commit a llama.cpp fork tag was built against. Fork tags are- "b<upstream_build>-mix-<ggml_commit>"; the ggml commit after "-mix-" fixes- the ggml ABI the slim whisper bundle links against, while the build number- only tracks upstream llama / fork PRs outside ggml. None when the tag has no- "-mix-" marker (then only an exact tag pairs)."""+ """The "-mix-" suffix of a fork tag "b<upstream_build>-mix-<suffix>".++ Despite the name this is NOT a ggml commit: it hashes the pinned PR set and+ stays constant while the base tag, and ggml with it, moves (one value covered+ b9909..b10001, whose ggml trees differ). Fallback for releases predating+ ggml_tree."""marker = "-mix-"idx = tag.rfind(marker)end = idx + len(marker)return tag[end:] if idx >= 0 and end < len(tag) else None-def llama_runtime_pairs(installed_tag: str, required_tag: Any) -> bool:+def llama_runtime_pairs(+ installed_tag: str,+ required_tag: Any,+ *,+ installed_ggml_tree: Any = None,+ required_ggml_tree: Any = None,+) -> bool:"""Whether an installed llama tag can back a slim bundle needing required_tag.- An exact tag always pairs; so does a shared ggml commit, since a newer llama- build with the same ggml ships an ABI-identical runtime. requires_ggml_sonames- stays the real per-file ABI gate."""+ An exact tag always pairs; otherwise the ggml tree ids decide, since they+ change exactly when ggml does. The "-mix-" suffix does not track ggml at all+ (see _llama_ggml_commit) and is only used when either tree is missing.+ requires_ggml_sonames stays the per-file ABI gate."""if not isinstance(required_tag, str):return Falseif installed_tag == required_tag:return True+ # Only decidable with both trees. Refusing when the install predates+ # ggml_tree would strand it: nothing can backfill a tree-less marker+ # without a llama release to install.+ if (+ isinstance(installed_ggml_tree, str)+ and installed_ggml_tree+ and isinstance(required_ggml_tree, str)+ and required_ggml_tree+ ):+ return installed_ggml_tree == required_ggml_treecommit = _llama_ggml_commit(installed_tag)return commit is not None and commit == _llama_ggml_commit(required_tag)@@ -373,7 +392,12 @@ def slim_pairing_for_artifact(return Nonellama_bin_dir, llama_tag, _profile = runtimerequires_tag = artifact.get("requires_llama_tag")- if not llama_runtime_pairs(llama_tag, requires_tag):+ if not llama_runtime_pairs(+ llama_tag,+ requires_tag,+ installed_ggml_tree = installed_llama_ggml_tree(),+ required_ggml_tree = artifact.get("requires_ggml_tree"),+ ):log(f"slim_selection: {asset} skipped: installed llama tag {llama_tag!r} "f"does not pair with required {requires_tag!r}"@@ -486,12 +510,26 @@ def _slim_release_incompatibility(manifest: dict[str, Any], host: HostInfo) -> sif runtime is None:return Noneinstalled_tag = runtime[1]- required_tags = {- artifact.get("requires_llama_tag")+ installed_tree = installed_llama_ggml_tree()+ # Normalise the tree: llama_runtime_pairs treats a non-string as absent, but+ # an unhashable one (list/dict) would blow up the set first.+ required_pairs = {+ (+ artifact.get("requires_llama_tag"),+ artifact["requires_ggml_tree"]+ if isinstance(artifact.get("requires_ggml_tree"), str)+ else None,+ )for artifact in os_compatibleif isinstance(artifact.get("requires_llama_tag"), str)}- if required_tags and not any(llama_runtime_pairs(installed_tag, tag) for tag in required_tags):+ required_tags = {tag for tag, _tree in required_pairs}+ if required_tags and not any(+ llama_runtime_pairs(+ installed_tag, tag, installed_ggml_tree = installed_tree, required_ggml_tree = tree+ )+ for tag, tree in required_pairs+ ):required_tag = sorted(required_tags)[0]return (f"slim bundle requires llama.cpp {required_tag}; installed llama.cpp is {installed_tag}"@@ -844,7 +882,12 @@ def selection_from_artifact(# A slim selection carries its pairing so the install wiring and marker know# which llama runtime provides the ggml libraries.runtime = installed_llama_runtime()- if runtime is None or not llama_runtime_pairs(runtime[1], artifact.get("requires_llama_tag")):+ if runtime is None or not llama_runtime_pairs(+ runtime[1],+ artifact.get("requires_llama_tag"),+ installed_ggml_tree = installed_llama_ggml_tree(),+ required_ggml_tree = artifact.get("requires_ggml_tree"),+ ):raise PrebuiltFallback("the paired llama.cpp runtime changed underneath the slim whisper selection")diff --git a/tests/studio/install/test_install_llama_prebuilt_logic.py b/tests/studio/install/test_install_llama_prebuilt_logic.pyindex 2b2c34e0c6b..e27a1d16b32 100644--- a/tests/studio/install/test_install_llama_prebuilt_logic.py+++ b/tests/studio/install/test_install_llama_prebuilt_logic.py@@ -3906,6 +3906,82 @@ def test_marker_sync_strands_no_temp_file_when_the_first_write_fails(tmp_path, massert [q.name for q in install_dir.iterdir() if ".tmp-" in q.name] == []+TREE_A = "8f3c6e197debb027f500df9f76e710e137f9fe68"+++def _checksums(tree, repo = "unslothai/llama.cpp"):+ return INSTALL_LLAMA_PREBUILT.ApprovedReleaseChecksums(+ repo = repo,+ release_tag = "b10173-mix-2c8b9c1",+ upstream_tag = "b10173",+ ggml_tree = tree,+ )+++def test_recorded_ggml_tree_only_for_binaries_from_that_release():+ """The fork's tree describes the fork's own bundles, not a ggml-org archive.++ A fork plan can install an approved upstream archive instead; recording the+ fork tree there would pair a slim whisper bundle against upstream ggml.+ """++ def choice(repo):+ return AssetChoice(+ repo = repo,+ tag = "b10173",+ name = "bundle.tar.gz",+ url = "https://x/bundle",+ source_label = "fork" if repo == "unslothai/llama.cpp" else "upstream",+ is_ready_bundle = True,+ install_kind = "linux-cpu",+ bundle_profile = "cpu",+ runtime_line = "cpu",+ expected_sha256 = "0" * 64,+ )++ fork = choice("unslothai/llama.cpp")+ upstream = choice("ggml-org/llama.cpp")+ assert INSTALL_LLAMA_PREBUILT.recorded_ggml_tree(_checksums(TREE_A), fork) == TREE_A+ assert INSTALL_LLAMA_PREBUILT.recorded_ggml_tree(_checksums(TREE_A), upstream) is None+ assert INSTALL_LLAMA_PREBUILT.recorded_ggml_tree(_checksums(None), fork) is None+++def test_reused_install_backfills_the_ggml_tree(tmp_path):+ """An install made before ggml_tree existed must gain it on reuse.++ write_prebuilt_metadata only runs on a real install, so without this the+ marker stays tree-less forever and slim whisper pairing silently falls back+ to the "-mix-" suffix.+ """+ install_dir = tmp_path / "llama.cpp"+ (install_dir / "build" / "bin").mkdir(parents = True)+ marker = install_dir / "UNSLOTH_PREBUILT_INFO.json"+ marker.write_text(json.dumps({"release_tag": "b10173-mix-2c8b9c1"}) + "\n", encoding = "utf-8")++ INSTALL_LLAMA_PREBUILT.sync_marker_ggml_tree(install_dir, TREE_A)++ payload = json.loads(marker.read_text(encoding = "utf-8"))+ assert payload["ggml_tree"] == TREE_A+ assert payload["release_tag"] == "b10173-mix-2c8b9c1" # nothing else lost+ assert INSTALL_LLAMA_PREBUILT.installed_llama_ggml_tree(install_dir) == TREE_A++[email protected]("declared", [None, ""])+def test_reused_install_keeps_the_ggml_tree_when_the_release_declares_none(tmp_path, declared):+ """A release with no ggml_tree (upstream ggml-org tags) must not erase one."""+ install_dir = tmp_path / "llama.cpp"+ install_dir.mkdir()+ marker = install_dir / "UNSLOTH_PREBUILT_INFO.json"+ marker.write_text(+ json.dumps({"release_tag": "b10173-mix-2c8b9c1", "ggml_tree": TREE_A}) + "\n",+ encoding = "utf-8",+ )++ INSTALL_LLAMA_PREBUILT.sync_marker_ggml_tree(install_dir, declared)++ assert json.loads(marker.read_text(encoding = "utf-8"))["ggml_tree"] == TREE_A++@pytest.mark.skipif(os.name == "nt", reason = "Windows st_mode carries no POSIX mode bits")@pytest.mark.parametrize("mode", [0o444, 0o644, 0o664])def test_marker_sync_preserves_the_marker_mode(tmp_path, mode):diff --git a/tests/studio/install/test_install_whisper_prebuilt_logic.py b/tests/studio/install/test_install_whisper_prebuilt_logic.pyindex 0a5541b27cc..9d8989c24bf 100644--- a/tests/studio/install/test_install_whisper_prebuilt_logic.py+++ b/tests/studio/install/test_install_whisper_prebuilt_logic.py@@ -823,10 +823,75 @@ NEWER_LLAMA_TAG = "b10079-mix-fb3d4ca"("b10070", "b10069", False), # tag without -mix-, no shared key],)-def test_llama_runtime_pairs_keys_on_ggml_commit(installed, required, pairs):+def test_llama_runtime_pairs_falls_back_to_mix_suffix(installed, required, pairs):+ # No tree ids either side, so the legacy suffix comparison applies.assert M.llama_runtime_pairs(installed, required) is pairs+# Real releases: same -mix-2c8b9c1 suffix, but genuinely different ggml trees.+SUFFIX_SHARED_A = "b10173-mix-2c8b9c1"+SUFFIX_SHARED_B = "b10181-mix-2c8b9c1"+TREE_A = "8f3c6e197debb027f500df9f76e710e137f9fe68"+TREE_B = "e96ffb0e063f66952b0c54796a74755b6041c867"+++ "installed,required,installed_tree,required_tree,pairs",+ [+ # The bug this fixes: a shared suffix is not a shared ggml.+ (SUFFIX_SHARED_A, SUFFIX_SHARED_B, TREE_A, TREE_B, False),+ # Different suffixes, same ggml: ABI-identical.+ ("b10241-mix-89aa77b", "b10225-mix-345e1e3", TREE_A, TREE_A, True),+ # A missing tree either side falls back to the suffix, so installs+ # predating ggml_tree are not stranded.+ (SUFFIX_SHARED_A, SUFFIX_SHARED_B, None, TREE_B, True),+ (SUFFIX_SHARED_A, SUFFIX_SHARED_B, TREE_A, None, True),+ (SUFFIX_SHARED_A, SUFFIX_SHARED_B, "", "", True),+ # An exact tag pairs before trees are consulted.+ (SUFFIX_SHARED_A, SUFFIX_SHARED_A, TREE_A, TREE_B, True),+ ],+)+def test_llama_runtime_pairs_prefers_ggml_tree(+ installed, required, installed_tree, required_tree, pairs+):+ assert (+ M.llama_runtime_pairs(+ installed,+ required,+ installed_ggml_tree = installed_tree,+ required_ggml_tree = required_tree,+ )+ is pairs+ )+++def test_installed_llama_ggml_tree_reads_marker(tmp_path):+ root = tmp_path / "llama.cpp"+ root.mkdir()+ (root / "UNSLOTH_PREBUILT_INFO.json").write_text(+ json.dumps({"release_tag": SLIM_LLAMA_TAG, "ggml_tree": TREE_A})+ )+ assert M.llama.installed_llama_ggml_tree(root) == TREE_A+++ "prepare",+ [+ lambda root: None, # no marker: installs predating ggml_tree+ lambda root: (root / "UNSLOTH_PREBUILT_INFO.json").write_text("{}"),+ lambda root: (root / "UNSLOTH_PREBUILT_INFO.json").write_text(+ json.dumps({"ggml_tree": ""})+ ),+ lambda root: (root / "UNSLOTH_PREBUILT_INFO.json").write_text("not json"),+ ],+)+def test_installed_llama_ggml_tree_absent_is_none(tmp_path, prepare):+ root = tmp_path / "llama.cpp"+ root.mkdir()+ prepare(root)+ assert M.llama.installed_llama_ggml_tree(root) is None++def test_slim_pairs_across_llama_build_bump_with_same_ggml(tmp_path, monkeypatch):# The live failure: the llama installer advances to a newer build that keeps# the same ggml commit, so the slim bundle's paired runtime is ABI-identical