Skip to content

Make startup ML warmup opt-in by feature - #16469

Merged
Lyxot merged 17 commits into
unslothai:mainfrom
Imagineer99:fix/opt-in-startup-warmup
Nov 4, 2026
Merged

Lyxot merged 17 commits into
unslothai:mainfrom
Imagineer99:fix/opt-in-startup-warmup

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

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

Startup performance settings with all warmups off

Text models selected: hardware is automatically enabled and locked as a prerequisite. Dataset, media, and advanced quantization prechecks remain independently selectable.

Text-model warmup selected with its required hardware dependency

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.

Startup time and RAM for the main warmup selections

  • All off: 214 MiB settled tree RSS, versus 1,095 MiB all selected (about 80% less). Peak tree RSS was 221 versus 2,383 MiB.
  • Initial HTTP readiness was 1.6–2.4 seconds across the matrix. Warmup plus idle initialization settled in 2.9 seconds all-off versus 20.3 seconds all-on.
  • The actual idle-cadence check completed 87 requests over 60 seconds with 0.38 MiB RSS growth and no ML imports.
  • A cached quantization restart avoided the probe child: settlement fell from 17.8 to 4.3 seconds and peak RSS from 2,110 to 811 MiB.
  • Dependencies overlap: this Datasets version imports PyTorch transitively, and media warmup retains nearly as much RAM as all-on. Opening hardware/media features still loads their libraries on demand.

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

  • Backend suites: 736 startup/settings/health tests; 870 catalog/video tests (2 platform skips); 306 engine tests; 5 fresh-process lifecycle tests. Suite counts overlap.
  • 64 real authenticated idle requests passed without importing the ML stack.
  • 14,624 unique frontend tests passed, with 1 Windows-only skip; production typecheck passed.
  • 43 Playwright scenarios passed, including all 32 saved selections, dependency/persistence behavior, error handling, owner access, mobile layout, and CPU/MLX first-use verdicts.
  • Repository formatter, Ruff and git diff --check passed.

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T19:12:24.178049Z 955a176 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Imagineer99 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member Author

Five approved fixes are staged; source return is held, and this PR is not converged. Source remains c429f4a1e86b; mirror #769 is 024daceea3b6 against base 4f4305ea10c4. The fixes cover restart detection, 24-locale warmup coverage, unused imports, explicit hardware demand in the Mac smoke, and consent-test/formatting corrections.

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:

  • Both frontend jobs fail only the three UI-spacing offsets already reproduced on the pinned base. Strict i18n and typechecks pass. Linux build, bundle and browser steps were skipped after that unit-test failure.
  • All three Zoo matrices fail only two padding-mask cases because the external Zoo CPU MLX shim at fe1bfc2b lacks BatchQuantizedKVCache.
  • Native capability dispatch, Composer browsers and uploads each exhausted one targeted retry without obtaining a macOS arm64 runner. Native capability validation at this head remains incomplete; the prior-head native MLX pass is historical.

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.

@Lyxot Lyxot self-assigned this Nov 3, 2026
…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.
@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

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:

  • Idle Chat ran hardware detection. /api/hub/local checks whether local image/video GGUFs can be built, and for some diffusion families that reached get_device(). On a Mac with such GGUFs that was 5 s and about 500 MiB on Chat's first paint. Listing now skips the device check until hardware is detected (one helper for the 4 call sites in catalog_classification.py), and the load still validates buildability. After the fix, idle Chat stays at about 280 MiB.
  • /v1/models listed GGUF only on a cold start. Servability needs the device, so the scan now detects hardware before rebuilding. API-only clients never triggered detection otherwise.
  • Chat auto-load skipped cached non-GGUF models. It read the deferred chat_only: true as a real verdict. It now treats a deferred verdict as unknown, like the existing pre-health fail-open.
  • Removed the fallback to ml_library_warmup_on_startup, which never existed on main.
  • Fixed tests that assumed Linux: Apple Silicon detection imports mlx_lm/transformers, and the 65-request idle test now has a longer timeout.

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.

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py Resolved
Comment thread studio/backend/main.py Resolved
…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.
@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ 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".

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py Resolved
… 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.
@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/frontend/src/hooks/use-system.ts Resolved
…t and keep cold ROCm status provisional without KFD targets
@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: be748a9f72

ℹ️ 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".

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Review wrap-up on be748a9

Codex: converged on be748a9: #16469 (comment). All review threads are answered and resolved.

CI (staging mirror on the same head and base, since closed): 70 pass, 5 fail, 4 skipped.

Caused by this PR (the follow-up fixes are already in the author's mirror PR):

  • Frontend build + bundle sanity, locale parity: the settings.general.mlWarmup.* keys are missing from the locale overlays.
  • Source lint, import-hoist safety: get_inference_backend is imported but unused in studio/backend/routes/models.py.
  • Mac capability verdict smoke (dispatch): the smoke polls plain /api/health, which now stays deferred, so the verdict never settles. It needs to request detect_hardware=true.

Not caused by this PR:

  • Repo tests (CPU, rest-2): the encoding safety net flags a default-encoding read_text() in tests/test_multi_lora_cold_compile_cpu.py.
  • Repo tests (CPU, studio-install): "Could not resolve a compatible unsloth / unsloth-zoo pair for no-torch mode".

What changed during this review

  • f00bd75: cold startup before hardware detection. Model listing no longer runs detection, and the OpenAI-compatible /models scan detects before deciding servability. Chat auto-load keeps cached non-GGUF models while capabilities are unknown. The legacy warmup settings key is dropped.
  • 546b140: the media capability probe goes through the torch/Dynamo import gate. A deferred authenticated /api/health still reports the host platform, and the frontend keeps re-reading it until the verdict is measured.
  • cb3c6ed, e1d6608: test harness and contract updates for the deferred verdict.
  • 8deaf1f: Settings and the Train entry points are no longer redirected or disabled on a deferred, provisional chat-only guess.
  • 88e7cfe: a desktop backend reconnect requests detection when the current route needs hardware.
  • 039f7b9, be748a9: cold ROCm engine status stays provisional when the kernel's GPU target is overridden (HSA_OVERRIDE_GFX_VERSION) or unreadable. Refreshing the verdict after a cached /api/system snapshot now requests detection, so a replaced backend does not stay deferred.

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Cherry-picked the CI fixes from the author's mirror branch and merged latest main (the branch was 74 commits behind):

  • locale overlays for the settings.general.mlWarmup.* keys (strict i18n parity)
  • dropped the unused get_inference_backend import in routes/models.py (import-hoist lint)
  • the Mac capability verdict smoke now requests detect_hardware=true
  • test fixture and formatting alignment
  • the narrower cached-picker restart fix, which replaces the always-detect variant from be748a9: only a cache hit requests detection

Re-running Codex and CI on 955a176.

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py Resolved
@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

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".

@Lyxot

Lyxot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Review wrap-up on 955a176

Codex: converged on 955a176: #16469 (comment). All review threads are answered and resolved. The one finding on this head (explicit media probes after a load has claimed the import window) was declined with the reasoning in its thread.

CI (staging mirror on the same head and base, since closed): 73 pass, 2 fail, 4 skipped.

  • The three PR-caused failures from the previous head now pass: strict locale parity, the import-hoist lint, and the Mac capability verdict smoke.
  • The encoding net and the studio-install job, both unrelated, also pass after the merge of main.
  • One Windows upload simulation failed on a dropped connection (WinError 10053) and passed on rerun.
  • Remaining failures, not caused by this PR: Core zoo (HF=default + TRL=default) and Core zoo (HF=latest + TRL=latest) each fail the same two Gemma4 float32 full-finetune tests in unsloth_zoo (test_gemma4_forced_float32_full_finetune_matches_vanilla_float32, test_gemma4_boundary_does_not_leak_past_its_scope). This PR changes only studio/ and tests/studio/.

What changed in this round

  • Cherry-picked the author's CI fixes: locale overlays for settings.general.mlWarmup.*, removal of the unused get_inference_backend import, the Mac verdict smoke requesting detect_hardware=true, test fixture and format alignment, and the narrower cached-picker restart fix, which replaces the always-detect variant from be748a9.
  • Merged latest main, which was 74 commits ahead.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Codex converged on 955a176 and CI is green.

@Lyxot
Lyxot merged commit b5c1396 into unslothai:main Nov 4, 2026
danielhanchen added a commit that referenced this pull request Nov 5, 2026
## 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.
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 5, 2026
…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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 5, 2026
…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.

![Before: refusal toast for the cached safetensors repo. After: the
default Gemma 4 E2B GGUF download
starts](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16629/pr16629_ui-9df54cad92ba.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants