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: stop hiding every model pulled with ollama pull (#10222)
Nilay04bce46a611e
diff --git a/studio/backend/hub/services/models/ollama.py b/studio/backend/hub/services/models/ollama.pyindex 7edccb20fdc..648c549b24f 100644--- a/studio/backend/hub/services/models/ollama.py+++ b/studio/backend/hub/services/models/ollama.py@@ -53,6 +53,36 @@ _OLLAMA_LOADABLE_LAYER_MEDIA_TYPES = frozenset(})+# Modelfile metadata nearly every pulled model carries. llama.cpp uses the GGUF's own template+# and defaults instead, so none of it reaches the load and none of it should hide the row.+# `image.adapter` is deliberately absent: it changes the weights.+_OLLAMA_METADATA_LAYER_MEDIA_TYPES = frozenset(+ {+ "application/vnd.ollama.image.template",+ "application/vnd.ollama.image.params",+ "application/vnd.ollama.image.system",+ "application/vnd.ollama.image.messages",+ "application/vnd.ollama.image.prompt",+ }+)++# Layers the load drops without changing what it returns. `image.draft` only feeds+# speculative decoding, which is output-equivalent by construction, so losing it costs+# speed and nothing else; `image.embed` has been deprecated since ollama 0.1.2 and+# ollama's own load ignores it too.+_OLLAMA_IGNORABLE_LAYER_MEDIA_TYPES = frozenset(+ {+ "application/vnd.ollama.image.draft",+ "application/vnd.ollama.image.embed",+ }+)++_OLLAMA_ADMITTED_LAYER_MEDIA_TYPES = (+ _OLLAMA_LOADABLE_LAYER_MEDIA_TYPES+ | _OLLAMA_METADATA_LAYER_MEDIA_TYPES+ | _OLLAMA_IGNORABLE_LAYER_MEDIA_TYPES+)+_OLLAMA_MATERIALIZE_LOCKS: dict[str, threading.Lock] = {}_OLLAMA_MATERIALIZE_LOCKS_GUARD = threading.Lock()@@ -79,7 +109,7 @@ def is_ollama_manifest_ref(ref: str) -> bool:def _unsupported_ollama_layer_media_types(layers: list[object]) -> tuple[str, ...]:- """Layer types whose behavior the direct llama.cpp load cannot preserve."""+ """Layer types that would make the row describe something the load cannot deliver."""unsupported: set[str] = set()for layer in layers:if not isinstance(layer, dict):@@ -88,7 +118,7 @@ def _unsupported_ollama_layer_media_types(layers: list[object]) -> tuple[str, ..media_type = layer.get("mediaType")if not isinstance(media_type, str) or not media_type:unsupported.add("<missing mediaType>")- elif media_type not in _OLLAMA_LOADABLE_LAYER_MEDIA_TYPES:+ elif media_type not in _OLLAMA_ADMITTED_LAYER_MEDIA_TYPES:unsupported.add(media_type)return tuple(sorted(unsupported))diff --git a/studio/backend/tests/test_ollama_manifest_load_resolution.py b/studio/backend/tests/test_ollama_manifest_load_resolution.pyindex cf87ee724d8..a46e0b030e6 100644--- a/studio/backend/tests/test_ollama_manifest_load_resolution.py+++ b/studio/backend/tests/test_ollama_manifest_load_resolution.py@@ -540,22 +540,34 @@ def test_ollama_intent_loads_the_link_but_keeps_the_manifest_identity(tmp_path,assert active_intent.gguf_path == resolved-_UNSUPPORTED_RUNTIME_LAYERS = (+# Modelfile metadata nearly every pulled model carries.+_METADATA_LAYERS = ("application/vnd.ollama.image.params","application/vnd.ollama.image.template","application/vnd.ollama.image.system","application/vnd.ollama.image.messages",- "application/vnd.ollama.image.adapter","application/vnd.ollama.image.prompt",+)++_UNSUPPORTED_RUNTIME_LAYERS = (+ "application/vnd.ollama.image.adapter","application/vnd.ollama.image.future-runtime",)+# Carried by a real manifest but dropped by the load without changing its output.+_IGNORABLE_LAYERS = (+ "application/vnd.ollama.image.draft",+ "application/vnd.ollama.image.embed",+)+def _rich_manifest_ref(tmp_path: Path, monkeypatch) -> tuple[Path, str]:from hub.services.models import ollamaroot = tmp_path / "ollama-rich"- tag_file = _write_ollama_store(root, extra_layers = _UNSUPPORTED_RUNTIME_LAYERS)+ tag_file = _write_ollama_store(+ root, extra_layers = _METADATA_LAYERS + _UNSUPPORTED_RUNTIME_LAYERS+ )monkeypatch.setattr(ollama, "ollama_model_dirs", lambda: [root])ref = f"ollama-manifest:{quote(str(tag_file), safe = '')}"return root, ref@@ -568,6 +580,65 @@ def test_rich_manifest_is_withheld_from_inventory(tmp_path, monkeypatch):assert ollama.scan_ollama_dir(root) == []+def test_a_normally_pulled_model_is_listed(tmp_path, monkeypatch):+ from hub.services.models import ollama++ root = tmp_path / "ollama-pulled"+ _write_ollama_store(root, extra_layers = _METADATA_LAYERS)+ monkeypatch.setattr(ollama, "ollama_model_dirs", lambda: [root])++ rows = ollama.scan_ollama_dir(root)+ assert len(rows) == 1+ assert ollama.is_ollama_manifest_ref(rows[0].load_id)+++def test_a_normally_pulled_model_resolves_for_a_load(tmp_path, monkeypatch):+ from hub.services.models import ollama+ from models.inference import LoadRequest+ from routes.inference import _resolve_model_identifier_for_request++ root = tmp_path / "ollama-pulled-load"+ tag_file = _write_ollama_store(root, extra_layers = _METADATA_LAYERS)+ monkeypatch.setattr(ollama, "ollama_model_dirs", lambda: [root])+ ref = f"ollama-manifest:{quote(str(tag_file), safe = '')}"++ resolved, _link_name, _is_dir = _resolve_model_identifier_for_request(+ LoadRequest(model_path = ref), operation = "load-model"+ )+ assert resolved.endswith(".gguf")++[email protected]("ignorable", _IGNORABLE_LAYERS)+def test_an_ignorable_layer_does_not_hide_the_primary_model(tmp_path, monkeypatch, ignorable):+ # Neither layer stops llama.cpp loading the model layer beside it, so neither is a+ # reason to withhold the row: a draft model only accelerates speculative decoding,+ # and ollama has ignored the embed layer since 0.1.2.+ from hub.services.models import ollama++ root = tmp_path / f"ollama-{ignorable.rpartition('.')[2]}"+ _write_ollama_store(root, extra_layers = _METADATA_LAYERS + (ignorable,))+ monkeypatch.setattr(ollama, "ollama_model_dirs", lambda: [root])++ rows = ollama.scan_ollama_dir(root)+ assert len(rows) == 1+ assert ollama.is_ollama_manifest_ref(rows[0].load_id)++[email protected]("unsupported", _UNSUPPORTED_RUNTIME_LAYERS)+def test_one_unsupported_layer_still_withholds_beside_the_metadata(+ tmp_path, monkeypatch, unsupported+):+ # Pins each unsupported type on its own. The withholding test above carries both at+ # once, so admitting just one of them back into the loadable set would still pass it.+ from hub.services.models import ollama++ root = tmp_path / f"ollama-{unsupported.rpartition('.')[2]}"+ _write_ollama_store(root, extra_layers = _METADATA_LAYERS + (unsupported,))+ monkeypatch.setattr(ollama, "ollama_model_dirs", lambda: [root])++ assert ollama.scan_ollama_dir(root) == []++def test_rich_manifest_ref_is_rejected_without_creating_links(tmp_path, monkeypatch):from models.inference import LoadRequestfrom routes.inference import _resolve_model_identifier_for_request