Repository navigation
Make startup ML warmup opt-in by feature - #16469
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Five approved fixes are staged; source return is held, and this PR is not converged. Source remains Current-head CI is terminal: 67 passed, 4 skipped, 5 failed, 3 capacity-cancelled; none pending. Source lint, all backend/CPU shards, all three regular Core matrices, startup checks and the final Chat/API/Update/GGUF retry passed. The earlier stderr-tail and cached-layout shard failures did not recur; their original causes are not being relabeled as fixed. Remaining limitations:
Local follow-up validation passed 251 backend tests, 2 portable Mac smoke cases and the full tracked-Python formatting guard, with negative controls, a clean scoped audit and passing pre-push gate. The fifth commit changes tests only. Codex's current-head review receipt failed because of the code-review usage limit; there is no completed clean review covering these five fixes. No fix commits have been returned to the source branch. Return remains held for current-head review and validation. |
…tion Local inventory listing no longer runs hardware detection while it is deferred: diffusion GGUF buildability checks in catalog classification fail open until the device is known, and the load still validates buildability. Idle Chat's /api/hub/local previously imported torch and the MLX stack on hosts with such GGUFs. /v1/models detects hardware before rebuilding its servability scan, so API clients on a cold start see non-GGUF models instead of a GGUF-only catalog. Chat auto-load treats a deferred hardware verdict as unknown, matching the existing fail-open policy, so cached non-GGUF models are not skipped while detection has not run. Drop the fallback to a never-shipped all-or-nothing warmup setting, and adjust the idle runtime tests for Apple Silicon detection and slower test clients.
|
Pushed f00bd75 on top of this branch to fix cases where the new default (all startup warmups off) still loaded ML libraries or changed behavior before hardware detection:
Measured on an M3 Max (3 runs, all warmups off vs main): idle RSS 326 MiB vs 880 MiB, ready in 3.3 s vs 4.3–4.7 s, and the first hardware request costs about 3.5 s instead of being prepaid. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f00bd753dc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…orm while detection is deferred The picker's /api/system?probe_media=true imports torchao and diffusers; it now waits for the Dynamo import gate like image and video loads, so it cannot race a selected startup warmup. A deferred authenticated health reply now includes device_type, apple_silicon and file_manager, so clients use the server's platform instead of the browser's (for example a Windows browser on a WSL backend). The frontend keeps a deferred reply unfetched, so later reads still settle the hardware verdict.
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…over a deferred verdict
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb3c6eddc5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… hardware verdict A deferred health reply carries a provisional chat_only. The root route guard no longer redirects on it, so /settings direct links and reloads open the dialog. Data settings' Load in Train tab treats it as unknown like the sidebar, so it stays available until detection measures the host.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8deaf1f28f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…nnects on a hardware page
…DE_GFX_VERSION is set
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 039f7b9f52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…t and keep cold ROCm status provisional without KFD targets
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review wrap-up on
|
|
Cherry-picked the CI fixes from the author's mirror branch and merged latest
Re-running Codex and CI on |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 955a176bde
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review wrap-up on
|
## Summary The Kaggle T4 Studio GPU check (`kaggle-studio-gpu`) has failed on every run since #16469 made the startup ML warmup opt-in, on `main` as well as on PRs: `studio_ready: Unsloth never became ready: timed out after 421s`. Cause: without the `hardware` warmup, `/api/health` reports `hardware_detecting: true` together with `hardware_detection_deferred: true`, and detection only starts on an authenticated `GET /api/health?detect_hardware=true` (what the UI sends after sign-in). The harness polled the unauthenticated endpoint and waited for `hardware_detecting` to clear, which never happens, so it timed out while the server sat healthy. Fix (harness only): - `health_is_ready` treats a deferred detection as up (the server is idle, waiting for the request). - New `hardware_detected` keeps the old strict check (healthy and no detection pending). - After a successful sign-in, `authenticate` requests detection with `detect_hardware=true` and waits for the verdict within the existing health deadline, so training and export still run only after detection, as before. A detection that never finishes fails `authenticate` with the last health payload. No Studio code changes. ## Tests - `tests/kaggle/test_studio_gpu_harness.py`: 188 passed, with new assertions for the deferred payload (`health_is_ready` true, `hardware_detected` false). - Real check: `kaggle-t4-studio-gpu-ci` dispatched on this branch; the result is posted as the `kaggle-studio-gpu` status on the head commit.
…cold engine status (unslothai#16670) ## What changes Since unslothai#16469 made startup ML warmup opt-in, torch is no longer imported at startup. On a ROCm host that sets `HSA_OVERRIDE_GFX_VERSION` (for example 11.0.0 on a gfx1102 Radeon), the vLLM / SGLang status endpoint then answered "Checking for a supported AMD GPU." on every poll and never reached a verdict until something else imported torch (the Settings Resources tab does; About and the download manager do not). Before unslothai#16469 it probed torch and answered "supported". The cold path now reads a readable global override the way libhsakmt does (`ROCR-Runtime` `libhsakmt/src/topology.c`, `topology_sysfs_get_node_props`: `sscanf("%u.%u.%u%c")`, so trailing text such as a space is rejected, major at most 63; the name is `gfx<major><minor><stepping in hex>`, so 11.0.0 is gfx1100 and 9.0.10 is gfx90a) and applies it to every GPU the KFD topology lists, as libhsakmt does for every GPU node. That is the target torch reports for each device, so the poll reaches the same verdict as before unslothai#16469 without importing torch. Unchanged and still provisional ("Checking") until torch reports: an unreadable override, any per-device `HSA_OVERRIDE_GFX_VERSION_<n>`, and an unreadable KFD topology. Hosts without an override, CUDA, CPU-only, Windows and macOS take the same code path as before. No UI text changes. The new helper is a pure function of the environment, so repeated polls give the same answer. - `studio/backend/utils/hardware/amd.py`: `hsa_override_gfx_target()`, the same name rule as `install_python_stack._hsa_override_gfx_arch`, but stricter on input: a value libhsakmt rejects (trailing whitespace or text, major above 63) stays unreadable here, so the status never reports supported for an override the runtime refuses. - `studio/backend/core/inference/engine_install.py`: `_rocm_reason` uses it before falling back to "Checking". ## Results Cold status (`support_reason("vllm", wait=False)`, 3 polls) over mocked hosts. "torch" = whether the poll ran hardware detection or the torch probe. | Host | ee3fa40 (before unslothai#16469) | main | this PR | |---|---|---|---| | CUDA Linux | Checking, then supported (torch: yes) | Checking, then supported (no) | Checking, then supported (no) | | ROCm gfx1100 (listed) | supported (yes) | supported (no) | supported (no) | | ROCm gfx1102 (unlisted) | unsupported (yes) | unsupported (no) | unsupported (no) | | ROCm gfx1102, override 11.0.0 | supported (yes) | Checking forever (no) | supported (no) | | same, gpu_id 0 | supported (yes) | Checking forever (no) | supported (no) | | 2 x gfx1102, override 11.0.0, gpu_id 1 | supported (yes) | Checking forever (no) | supported (no) | | ROCm gfx1102, override 10.3.0 | unsupported (yes) | Checking forever (no) | unsupported (no) | | ROCm gfx1032, override 9.0.10 (gfx90a) | supported (yes) | Checking forever (no) | supported (no) | | ROCm gfx1100, override 10.3.0 | unsupported (yes) | Checking forever (no) | unsupported (no) | | ROCm, override "11" (unreadable) | per torch | Checking (no) | Checking (no) | | ROCm, per-device override | per torch | Checking (no) | Checking (no) | | ROCm, override, no KFD | per torch | Checking (no) | Checking (no) | | ROCm, no KFD | per torch | Checking (no) | Checking (no) | | Windows (non-WSL path) | platform message (no) | same | same | | macOS | platform message (no) | same | same | | CPU-only Linux | Checking, then requires NVIDIA (yes) | same (no) | same (no) | ## Tests - New `test_cold_status_judges_an_overridden_gpu_by_the_override_without_torch` (gpu_id None, 0, 1; the torch probe raises if called) and `test_hsa_override_gfx_target`; both fail on main. - `test_hsa_override_gfx_target` also covers `"11.0.0 "` and `"64.0.0"` (both unreadable, as in libhsakmt). - `test_cold_status_does_not_judge_an_overridden_gpu_by_its_kernel_target` now expects the override verdict instead of "Checking". - `test_managed_engines_rocm.py`, `test_engine_status_stays_cold.py`, `test_ml_warmup_idle_runtime.py`, every backend test touching `engine_install` or `HSA_OVERRIDE_GFX_VERSION`, and `tests/studio -k "engine or rocm or amd or hsa"`: same failing IDs on main and this branch. ## Not covered - Checked on a real gfx1151 (Linux, ROCm torch): with overrides 11.0.0, 10.3.0, 11.5.1 and 9.0.10 the base cold poll stays at "Checking", while the head's cold answer equals the answer after torch reports (torch's gcnArchName was gfx1100, gfx1030, gfx1151 and gfx90a), and the poll never imports torch. With "11.0.0 " (trailing space) torch sees no device at all, so treating it as unreadable matches the runtime. - The installer's own `_hsa_override_gfx_arch` still strips trailing whitespace, so it accepts a value libhsakmt rejects; that is a separate, pre-existing difference and is not changed here. - An override naming a target ROCm does not know (for example 11.0.7) is still reported by name; the answer is then "unsupported", never a wrong "supported". - Device masks (`HIP_VISIBLE_DEVICES` ordinal or stacked masks) are not modelled: the override applies to every device, so the per-GPU answer is the override target either way. - Staging (latest head): ubuntu, macos-15 and windows legs all green.
…detection (unslothai#16629) Follow-up to unslothai#16469 (opt-in startup ML warmup). With startup hardware detection now deferred by default, two first-use paths started answering on an unmeasured verdict. This keeps unslothai#16469's cold, torch-free idle start and fixes both. ## What changes 1. **Images listing before hardware detection.** Until detection completes, the listing reported every recognised diffusion family as loadable (`family is not None`). A family whose diffusers pipeline class is missing and that sd.cpp cannot assemble was therefore listed as an image model and only failed on load, which breaks the rule that the picker and the loader agree. Only the engine prediction needs the device. Before detection the listing now calls the same `family_buildable_here` with `provisional=True`, which answers only the device-dependent engine predictions optimistically and keeps every device-free refusal, so the listing and the loader still share one predicate. The load re-checks with the measured verdict. None of these checks imports torch or diffusers or starts detection. 2. **Chat autoload on chat-only hosts.** With the verdict deferred, a CPU-only / Intel Mac / chat-only host read as "unknown", so autoload tried a cached safetensors repo, got the backend's chat-only refusal and stopped with an error toast before the default GGUF download. Autoload now asks for detection first, and only when a non-GGUF candidate exists, so a GGUF-only cache keeps the probe-free idle path. On a busy host detection outlasts the health read's single 5 s wait, so autoload keeps reading health until the verdict is measured (bounded at 60 s; each health read races the remaining deadline and the send's abort signal, so a stalled `/api/health` cannot outlive the deadline or a stopped send; past the deadline it stays fail-open as on main). The post-detection listing contract tests in `test_cached_gguf_routes.py` (krea2, MOSS-Image, and the old-diffusers picker / loader agreement tests that stub the engine prediction) now pin detection complete instead of depending on test order. Run alone or in a fresh process on current main they fail (13 krea2 / MOSS-Image cases, plus the two old-diffusers tests on every staging OS), because nothing in the file marks detection complete. ## Results | Behaviour | main (after unslothai#16469) | this branch | | --- | --- | --- | | `test_cached_gguf_routes.py -k "krea2_gguf_is_an_image or moss_image_gguf_inventory"`, run alone | 13 failed | 13 passed | | Pre-detection listing of a family with no pipeline class and no sd.cpp support | `text-to-image` | `image-diffusion-unsupported` (same as after detection) | | Autoload, chat-only host, only a cached safetensors repo | error toast, no default GGUF | default GGUF downloads and loads | | Autoload, deferred verdict, host turns out to have a GPU backend | loads the cached safetensors repo | same | | Autoload, chat-only host, detection slower than the 5 s health wait | error toast, no default GGUF | waits for the verdict, then the default GGUF | | Autoload, deferred verdict, GGUF-only cache | no detection request | no detection request | | torch / diffusers imported by the listing before detection (18 families x gguf/pipeline) | no | no | ## Tests - New `test_listing_before_detection_keeps_device_free_refusals`: fails on main, passes here; it also fails if the listing calls `family_buildable_here` or `predict_engine` before detection. - Autoload harness (`tests/studio/test_chat_autoload_failure_gate.py`) gains a `fetchDeviceType` stub and a `detectedChatOnly` scenario field; 4 deferred-verdict scenarios, including detection that lands only after several more health reads (3 fail without the change); the whole file passes, 85 tests. - Backend: `test_cached_gguf_routes.py`, `test_cold_model_catalog.py`, `test_selective_ml_warmup.py`, `test_startup_ml_warmup.py`, `test_ml_warmup_idle_runtime.py`: only failures are a local huggingface_hub / diffusers version mismatch in `test_pipeline_class_guard_passes_every_shipped_family` (fails on main too) and subprocess timeouts on a heavily loaded host in the startup subprocess tests. - `tests/studio/test_model_picker_contracts.py` passes. - Per-family matrix before vs after detection: no cell where the pre-detection answer refuses something the post-detection answer allows. ## Not covered - No GPU host run here; on a GPU host some families listed before detection can still become unsupported once detection lands. That is the intended provisional answer, and the load re-checks it. - The autoload change is covered by the frontend harness and code reading, not a browser run on a real chat-only host. - If detection takes longer than 60 s, autoload stays fail-open, as on main. - A real-backend before/after run on a chat-only host showed the race behind the bounded wait: one run matched (BEFORE error toast, AFTER default GGUF download) and two did not, because detection on the loaded host took about 20 s, longer than the single 5 s wait. That is what the second change addresses. ## Before / after (chat-only CPU host, cache holds only a safetensors repo) First send with no model loaded, base `b5c1396` vs head `3514aec`, each Studio on an isolated HF cache seeded with `trl-internal-testing/tiny-Qwen3ForCausalLM`. Before: autoload tries the cached repo, the backend refuses it and the send stops with an error. After: autoload measures the verdict, skips the repo and starts the default GGUF. 
Summary
Keep Unsloth lightweight before a model is loaded by making startup ML warmup opt-in, with separate choices for hardware detection, text models, datasets, image/video models, and quantization prechecks.
The owner can configure these in Settings → General → Startup performance. All choices default off, required hardware dependencies are included automatically, and saved changes apply after restarting Unsloth. The existing global disable override remains respected.
Idle Chat also had three indirect PyTorch imports through model listing, video status, and engine availability. Those reads now use metadata or existing state. First-use hardware/media discovery still runs when requested, refreshes the frontend compatibility verdict, and preserves cold-start watchdog behavior.
Settings UI — Playwright
Actual settings components captured with mocked API responses. These are two states of the new UI, not a merge-base before/after comparison; the captured component, API, and copy match this PR.
Default: all warmups off
Text models selected: hardware is automatically enabled and locked as a prerequisite. Dataset, media, and advanced quantization prechecks remain independently selectable.
Startup and RAM measurements
41 real backend launches covered all 32 selections, four 60-second polling repeats, two cached restarts, the disable override, actual idle polling cadence, and authenticated first use. Each matrix case used a fresh process and probe cache, the same authenticated Chat initialization requests, and no loaded model weights.
Full 32-selection graph · All 32 rows as CSV
Measured on WSL with an RTX 5070 Ti, Python 3.13 and PyTorch 2.11. RSS includes the backend and its children, excludes browser/launcher RAM, and can double-count shared pages; the full graph/CSV also include PSS. Existing local media metadata enabled the full media prewarm path. These are single-host measurements of this implementation's settings; OS file caches were not flushed.
Validation
git diff --checkpassed.The measured backend matches the committed source. The final frontend-only first-use verdict fix was validated separately; it adds no hardware-demand request to idle Chat or General settings. Native Windows/macOS runs and model inference/training are outside this local validation.