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.

Kaggle Studio GPU CI: request hardware detection after sign-in (#16728)

Daniel Han7ec4b20bc2f1
diff --git a/tests/kaggle/studio_gpu/run_studio_gpu.py b/tests/kaggle/studio_gpu/run_studio_gpu.py
index 05b05def384..bde4fd6d063 100644
--- a/tests/kaggle/studio_gpu/run_studio_gpu.py
+++ b/tests/kaggle/studio_gpu/run_studio_gpu.py
@@ -37,6 +37,7 @@ from studio_client import ( # noqa: E402
StudioError,
adapter_verdict,
export_verdict,
+ hardware_detected,
health_is_ready,
newest_gguf,
nonfinite_losses,
@@ -641,6 +642,8 @@ class Payload:
f"--password was passed to `unsloth studio` and logging in "
f"with it failed, so the flag did not take effect: {exc}"
)
+ if not failures:
+ failures.extend(self.request_hardware_detection())
return self.record(
"authenticate", not failures, {"source": "--password", "failures": failures}
)
@@ -655,10 +658,28 @@ class Payload:
self.studio.login(password)
except StudioError as exc:
failures.append(str(exc))
+ if not failures:
+ failures.extend(self.request_hardware_detection())
return self.record(
"authenticate", not failures, {"source": "bootstrap", "failures": failures}
)
+ def request_hardware_detection(self) -> list[str]:
+ """Without the startup hardware warmup Unsloth detects on the first authenticated
+ ``/api/health?detect_hardware=true`` (what the UI sends after sign-in); train and export wait on it."""
+ ok, last, reason = wait_for(
+ probe = lambda: self.studio.get("/api/health?detect_hardware=true")[1],
+ accept = hardware_detected,
+ deadline_s = self.args.health_deadline,
+ interval_s = 2.0,
+ alive = self.server_alive,
+ )
+ if ok:
+ return []
+ return [
+ f"hardware detection never finished after sign-in: {reason} (last health: {str(last)[:300]})"
+ ]
+
def server_alive(self) -> bool:
return self.proc is not None and self.proc.poll() is None
@@ -2221,16 +2242,28 @@ class Payload:
if api_key:
client.token = api_key
- code, body = client.post(
- "/v1/chat/completions",
- {
- "model": "default",
- "messages": [{"role": "user", "content": "Say hello in one word."}],
- "max_tokens": 32,
- "temperature": 0.0,
- },
- timeout = self.args.chat_timeout,
- )
+ # The server answers before `unsloth run` finishes loading its model (no startup hardware warmup
+ # gates /api/health any more): retry "No model loaded" while the process lives, up to the deadline.
+ load_deadline = time.time() + self.args.health_deadline
+ while True:
+ code, body = client.post(
+ "/v1/chat/completions",
+ {
+ "model": "default",
+ "messages": [{"role": "user", "content": "Say hello in one word."}],
+ "max_tokens": 32,
+ "temperature": 0.0,
+ },
+ timeout = self.args.chat_timeout,
+ )
+ if not (
+ code == 400
+ and "No model loaded" in str(body)
+ and proc.poll() is None
+ and time.time() < load_deadline
+ ):
+ break
+ time.sleep(3.0)
detail["completion_status"] = code
text = ""
if code == 200 and isinstance(body, dict):
diff --git a/tests/kaggle/studio_gpu/studio_client.py b/tests/kaggle/studio_gpu/studio_client.py
index cf9926e69be..c780c5dae72 100644
--- a/tests/kaggle/studio_gpu/studio_client.py
+++ b/tests/kaggle/studio_gpu/studio_client.py
@@ -139,16 +139,22 @@ class Studio:
def health_is_ready(payload: Any) -> bool:
- """Status healthy is not enough: during hardware detection Unsloth refuses train and export."""
+ """Status healthy is not enough: during hardware detection Unsloth refuses train and export. A deferred
+ detection (no startup hardware warmup) is idle until an authenticated client asks for it, so it counts as up."""
if not isinstance(payload, dict):
return False
if payload.get("status") != "healthy":
return False
- if payload.get("hardware_detecting"):
+ if payload.get("hardware_detecting") and not payload.get("hardware_detection_deferred"):
return False
return True
+def hardware_detected(payload: Any) -> bool:
+ """Healthy with the hardware verdict in: what train and export need."""
+ return health_is_ready(payload) and not payload.get("hardware_detecting")
+
+
def wait_for(
probe: Callable[[], Any],
accept: Callable[[Any], bool],
diff --git a/tests/kaggle/test_studio_gpu_harness.py b/tests/kaggle/test_studio_gpu_harness.py
index b67bf3388a5..b19c6c539f4 100644
--- a/tests/kaggle/test_studio_gpu_harness.py
+++ b/tests/kaggle/test_studio_gpu_harness.py
@@ -257,6 +257,15 @@ def test_health_is_not_ready_until_hardware_detection_settles():
training run or an export in that window."""
assert not studio_client.health_is_ready({"status": "healthy", "hardware_detecting": True})
assert studio_client.health_is_ready({"status": "healthy"})
+ # no startup hardware warmup: detection waits for the authenticated request, so the server is up
+ deferred = {
+ "status": "healthy",
+ "hardware_detecting": True,
+ "hardware_detection_deferred": True,
+ }
+ assert studio_client.health_is_ready(deferred)
+ assert not studio_client.hardware_detected(deferred)
+ assert studio_client.hardware_detected({"status": "healthy"})
assert not studio_client.health_is_ready({"status": "starting"})
assert not studio_client.health_is_ready("connection refused")