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: keep the app responsive as an MLX or Transformers load finishes (#15842)
Nilay1833dcfd750b
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex f1e390d0dc8..1f23c8e7b83 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -18668,6 +18668,12 @@ async def _load_model_impl(account_access.join_resident("chat")if request._advertised_id:backend._openai_advertised_id = request._advertised_id+ _requires_rc = await asyncio.to_thread(+ _resolve_loaded_trust_remote_code,+ backend.active_model_name,+ _model_info,+ inference_config,+ )return LoadResponse(engine = request.engine,engine_parallelism = request.engine_parallelism,@@ -18708,9 +18714,7 @@ async def _load_model_impl(chat_template_override = _model_info.get("chat_template_override_requested"),chat_template_override_reason = _model_info.get("chat_template_override_reason"),inference = inference_config,- requires_trust_remote_code = _resolve_loaded_trust_remote_code(- backend.active_model_name, _model_info, inference_config- ),+ requires_trust_remote_code = _requires_rc,supports_reasoning = _sf_supports_reasoning,reasoning_style = _sf_reasoning_style,reasoning_effort_levels = _sf_flags.get("reasoning_effort_levels", []),@@ -19503,7 +19507,8 @@ async def _load_model_impl(_sf_flags, _ = _sf_rendered_features(backend, _model_info)# Persist trust_remote_code so a retry/rollback doesn't send false for a custom-code model.- _requires_rc = _resolve_loaded_trust_remote_code(+ _requires_rc = await asyncio.to_thread(+ _resolve_loaded_trust_remote_code,config.identifier,None,inference_config,diff --git a/studio/backend/tests/test_status_trust_remote_code_off_event_loop.py b/studio/backend/tests/test_status_trust_remote_code_off_event_loop.pyindex acc063a42be..84abb985408 100644--- a/studio/backend/tests/test_status_trust_remote_code_off_event_loop.py+++ b/studio/backend/tests/test_status_trust_remote_code_off_event_loop.py@@ -7,10 +7,12 @@ run on the event loop thread (an unreachable Hub parked the loop and /api/livenefrom __future__ import annotationsimport asyncio+import jsonimport threadingfrom types import SimpleNamespaceimport routes.inference as inference_routes+from models.inference import LoadRequestdef _backend(active = "unsloth/Qwen3-8B", info = None):@@ -121,3 +123,85 @@ def test_no_loaded_model_reads_nothing(monkeypatch):assert not calledassert response.requires_trust_remote_code is False+++class _LoadingBackend:+ def __init__(self):+ self.active_model_name = None+ self.models = {}+ self.loading_models = set()++ def load_model(self, *, config, **_kwargs):+ self.active_model_name = config.identifier+ self.models[config.identifier] = {}+ return True++ def set_parallel_slots(self, _n):+ pass+++def test_a_finished_load_resolves_trust_remote_code_off_the_event_loop_thread(+ monkeypatch, tmp_path+):+ model = tmp_path / "tiny"+ model.mkdir()+ (model / "config.json").write_text(json.dumps({"model_type": "llama"}))+ (model / "model.safetensors").write_bytes(b"x")+ backend = _LoadingBackend()+ threads: list[int] = []++ def _auto_map(*_args, **_kwargs):+ threads.append(threading.get_ident())+ return True++ monkeypatch.setattr(inference_routes, "get_inference_backend", lambda: backend)+ monkeypatch.setattr(inference_routes, "_peek_inference_backend", lambda *a, **k: backend)+ monkeypatch.setattr(inference_routes, "_auto_map_trust_remote_code", _auto_map)++ async def _load():+ scope = SimpleNamespace(app = SimpleNamespace(state = SimpleNamespace(llama_parallel_slots = 1)))+ response = await inference_routes._load_model_impl(+ LoadRequest(model_path = str(model)), scope, current_subject = "t"+ )+ return threading.get_ident(), response++ loop_thread, response = _run(_load())++ assert response.status == "loaded"+ assert threads and loop_thread not in threads+ assert response.requires_trust_remote_code is True+ assert backend.models[response.model]["requires_trust_remote_code"] is True+++def test_an_already_loaded_model_resolves_trust_remote_code_off_the_event_loop_thread(+ monkeypatch, tmp_path+):+ model = tmp_path / "tiny"+ model.mkdir()+ (model / "config.json").write_text(json.dumps({"model_type": "llama"}))+ (model / "model.safetensors").write_bytes(b"x")+ backend = _LoadingBackend()+ threads: list[int] = []++ def _auto_map(*_args, **_kwargs):+ threads.append(threading.get_ident())+ return True++ monkeypatch.setattr(inference_routes, "get_inference_backend", lambda: backend)+ monkeypatch.setattr(inference_routes, "_peek_inference_backend", lambda *a, **k: backend)+ monkeypatch.setattr(inference_routes, "_auto_map_trust_remote_code", _auto_map)+ scope = SimpleNamespace(app = SimpleNamespace(state = SimpleNamespace(llama_parallel_slots = 1)))++ async def _load():+ return threading.get_ident(), await inference_routes._load_model_impl(+ LoadRequest(model_path = str(model)), scope, current_subject = "t"+ )++ _run(_load())+ backend.models[backend.active_model_name].pop("requires_trust_remote_code")+ threads.clear()+ loop_thread, response = _run(_load())++ assert response.status == "already_loaded"+ assert threads and loop_thread not in threads+ assert response.requires_trust_remote_code is True