diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py index dbb4e835cb..f87a2cc67f 100644 --- a/studio/backend/routes/inference.py +++ b/studio/backend/routes/inference.py @@ -3440,7 +3440,6 @@ async def _wait_for_model_switch_idle(*, current_request_counted: bool) -> None: exclude them to avoid a queue deadlock. """ from core.inference.llama_keepwarm import other_inference_request_count - while True: queued_switches = _switch_waiter_count() if current_request_counted and queued_switches > 0: @@ -3732,6 +3731,7 @@ async def _maybe_auto_switch_model( _auto_switch_process_lock.release() finally: _note_switch_waiter(key, -1) + await _resolve_and_switch() @@ -4531,9 +4531,7 @@ async def _load_model_impl( # Keep the resident model alive until every active generation has # finished. The lifecycle gate held by the caller blocks new starts. - await _wait_for_model_switch_idle( - current_request_counted = current_request_counted - ) + await _wait_for_model_switch_idle(current_request_counted = current_request_counted) # Unload any active Unsloth model only after every hub conflict check. if unsloth_backend.active_model_name: @@ -4745,9 +4743,7 @@ async def _load_model_impl( # Unload any active GGUF model first llama_backend = get_llama_cpp_backend() - await _wait_for_model_switch_idle( - current_request_counted = current_request_counted - ) + await _wait_for_model_switch_idle(current_request_counted = current_request_counted) if llama_backend.is_loaded: logger.info("Unloading GGUF model before loading Unsloth model") llama_backend.unload_model() diff --git a/studio/backend/tests/test_openai_auto_switch.py b/studio/backend/tests/test_openai_auto_switch.py index 813e712c35..d8db447c27 100644 --- a/studio/backend/tests/test_openai_auto_switch.py +++ b/studio/backend/tests/test_openai_auto_switch.py @@ -1229,9 +1229,7 @@ def test_auto_switch_waits_for_another_inference_to_finish(monkeypatch): async def _drive(): task = asyncio.create_task( - inference_route._maybe_auto_switch_model( - "org/B-GGUF:Q8_0", object(), "tester" - ) + inference_route._maybe_auto_switch_model("org/B-GGUF:Q8_0", object(), "tester") ) await asyncio.sleep(0.05) assert rec.calls == [] @@ -1588,15 +1586,11 @@ def test_swap_waits_until_concurrent_request_finishes_resolving(monkeypatch): async def _drive(): task = asyncio.create_task( - inference_route._maybe_auto_switch_model( - "org/B-GGUF:Q8_0", object(), "tester" - ) + inference_route._maybe_auto_switch_model("org/B-GGUF:Q8_0", object(), "tester") ) await asyncio.sleep(0.05) assert rec.calls == [] - inference_route._note_switch_waiter( - inference_route._switch_key("org/B-GGUF", "Q8_0"), 1 - ) + inference_route._note_switch_waiter(inference_route._switch_key("org/B-GGUF", "Q8_0"), 1) await asyncio.wait_for(task, timeout = 1) asyncio.run(_drive()) @@ -1655,9 +1649,7 @@ def test_auto_switch_waits_when_unsloth_stream_active(monkeypatch): async def _drive(): task = asyncio.create_task( - inference_route._maybe_auto_switch_model( - "org/B-GGUF:Q8_0", object(), "tester" - ) + inference_route._maybe_auto_switch_model("org/B-GGUF:Q8_0", object(), "tester") ) await asyncio.sleep(0.05) assert rec.calls == [] diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py index a50556d63f..fc28592960 100644 --- a/unsloth_cli/commands/start.py +++ b/unsloth_cli/commands/start.py @@ -606,11 +606,7 @@ class _ModelDownloadProgress: def _load_model_with_progress( - base: str, - key: str, - model: str, - load: LoadOptions, - payload: dict, + base: str, key: str, model: str, load: LoadOptions, payload: dict ) -> dict: """Run the blocking load request while polling its download progress.""" result: list[tuple[bool, object]] = [] diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.py index 312a81a9aa..619c43a21e 100644 --- a/unsloth_cli/tests/test_start.py +++ b/unsloth_cli/tests/test_start.py @@ -1271,9 +1271,7 @@ def test_connect_model_flag_loads_on_server(fake_studio): ] assert result.output.index( f"Switching the Unsloth server from {MODEL['id']} to unsloth/Qwen3.5-35B-A3B.\n" - ) < result.output.index( - "This unloads the current model for every attached session.\n" - ) + ) < result.output.index("This unloads the current model for every attached session.\n") _assert_env_set(result.output, "ANTHROPIC_MODEL", "unsloth/Qwen3.5-35B-A3B") @@ -1882,25 +1880,24 @@ def test_start_studio_server_polls_progress_from_early_key(monkeypatch): ) assert server.pid == 4321 - assert ( - BASE, - "sk-unsloth-early", - "owner/model-GGUF", - "Q4_K_M", - "created", - ) in created + assert (BASE, "sk-unsloth-early", "owner/model-GGUF", "Q4_K_M", "created") in created assert created.count("poll") == 2 assert created[-2:] == ["complete", "close"] - assert not any( - isinstance(event, tuple) and "server ready" in event[-1] for event in created - ) + assert not any(isinstance(event, tuple) and "server ready" in event[-1] for event in created) def test_load_model_with_progress_uses_selected_gguf_size(monkeypatch, capsys): release = start.threading.Event() calls = [] - def http_json(method, url, token, payload = None, timeout = 30, error = None): + def http_json( + method, + url, + token, + payload = None, + timeout = 30, + error = None, + ): calls.append((method, url, payload)) if url.endswith("/api/inference/load"): assert release.wait(timeout = 2)