Skip to content

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.

Studio: let unsloth start attach to a loaded Ollama model (#16944)

Nilay66dfa6d5e6d1
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py
index d6b4718c194..2b9571956ff 100644
--- a/unsloth_cli/commands/start.py
+++ b/unsloth_cli/commands/start.py
@@ -5029,9 +5029,11 @@ def _connect(
requested = model
explicit_connection = bool(model) and model.startswith(_CONNECTION_MODEL_PREFIX)
# `--model org/name:QUANT` is shorthand for `--model org/name --gguf-variant QUANT`. Split it before we match or serve so the attach path resolves against the already-loaded `org/name` (listed without the suffix) instead of reloading a `:`-suffixed repo id, which Unsloth rejects and which would evict a model another session is using.
+ unsplit = None
if model and not explicit_connection:
repo, variant = _split_repo_variant(model)
if variant:
+ unsplit = (model, load)
model = repo
if not load.gguf_variant:
load = load._replace(gguf_variant = variant)
@@ -5054,6 +5056,19 @@ def _connect(
model = os.path.abspath(os.path.expanduser(model))
try:
key = _agent_api_key(base, api_key, auto_started = server is not None)
+ # Studio's own ids can carry a tag (ollama/qwen3:8b), so a loaded model of that exact id wins over the split.
+ if (
+ unsplit
+ and server is None
+ and any(
+ entry.get("loaded") is not False
+ and _model_id_matches(
+ entry.get("id"), requested, allow_casefold = is_loopback_url(base)
+ )
+ for entry in _loaded_models(base, key)
+ )
+ ):
+ model, load = unsplit
connection = None if server is not None else _connection_entry(base, key, requested)
if connection is not None:
if not connections:
diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.py
index 2e2eeff1d53..fdbe8686d2a 100644
--- a/unsloth_cli/tests/test_start.py
+++ b/unsloth_cli/tests/test_start.py
@@ -4651,6 +4651,18 @@ def test_connect_model_bare_id_matches_loaded_without_reload(fake_studio):
_assert_env_set(result.output, "ANTHROPIC_MODEL", MODEL["id"])
+def test_connect_loaded_ollama_model_keeps_its_tag(fake_studio):
+ fake_studio.state["models"] = [{"id": "ollama/qwen3:8b", "context_length": 40960}]
+ result = CliRunner().invoke(
+ start.start_app, ["claude", "--no-launch", "--model", "ollama/qwen3:8b"]
+ )
+ assert result.exit_code == 0, result.output
+ loads = [c for c in fake_studio if c[1].endswith("/api/inference/load")]
+ assert loads == []
+ assert "Reusing loaded model: ollama/qwen3:8b\n" in result.output
+ _assert_env_set(result.output, "ANTHROPIC_MODEL", "ollama/qwen3:8b")
+
+
def test_connect_model_variant_suffix_defers_to_server_dedup(fake_studio):
result = CliRunner().invoke(
start.start_app, ["claude", "--no-launch", "--model", MODEL["id"] + ":UD-Q4_K_XL"]