Skip to content

Studio: on low disk, load the largest GGUF quant that fits and show which one loaded - #11052

Merged
Lyxot merged 10 commits into
unslothai:mainfrom
NilayYadav:fix-gguf-low-disk-fallback
Sep 16, 2026
Merged

Lyxot merged 10 commits into
unslothai:mainfrom
NilayYadav:fix-gguf-low-disk-fallback

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

If the GGUF quant you asked for did not fit on disk, Studio quietly loaded the smallest quant in the repo, often a 1-bit one, even when a much better one would fit. Studio kept showing the quant you asked for, and asking for it again after freeing space did nothing because it thought it was already loaded. This happens with unsloth start and direct load requests.

Now it picks the largest quant that still leaves 5 GB free, the same margin Studio already keeps for downloads. If none leaves that much, it picks the smallest that fits, like before. Studio shows the quant that actually loaded, so asking for the original again after freeing space downloads it. unsloth start prints a warning naming both quants, and Studio shows the same warning when you open it or load a model. Other load warnings, such as a model too big for memory, now show the same way.

With 7.5 GB free and unsloth start hermes --model unsloth/Qwen3-4B-GGUF --gguf-variant BF16, main showed BF16 in the header while a 1-bit quant was running and chat replied with garbage, and running it again after freeing space kept the 1-bit quant. With this change Q4_1 loads, the command and Studio both show the warning, the header shows Q4_1 and chat works. After freeing space BF16 downloads and loads with no warning. Added unit tests that fail on main.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-09-16T08:45:28.168944Z bb7357e 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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 39451dbae2

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 39451dbae2

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 8706292d58

ℹ️ 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 unsloth_cli/commands/start.py Resolved
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 0b2aa4fa92

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 5b09068ada

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 5b09068ada

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions low-disk evidence

Pinned head: 5b09068. Codex ran 8 rounds, and the last two raised only suggestions that were declined. Three findings were real and are fixed on the branch, each with a regression test that fails on the previous head:

  • 39451db: a truncated cached quant counted as needing 0 bytes and could beat a quant that fits.
  • 0b2aa4f: unsloth start --model X could print the load warning of a different active GGUF.
  • 5b09068: in a repo that ships several checkpoints, the fallback could pick another checkpoint's quant. Candidates are now limited to the requested file's gguf_checkpoint_family.

The other four suggestions were declined with reasons on each thread.

Real Studio, real low disk. Both runs use the same workflow and probe. The HF cache is a 16 GB loopback ext4 volume with a ballast file, so free space is exactly 7.45 GiB. The probe requests unsloth/Qwen3-4B-GGUF BF16 (7.50 GiB), then deletes the ballast and requests BF16 again. The only difference between the runs is the PR's files: restored to main on one side, PR head on the other.

main (run) PR (run)
File served at 7.45 GiB free Qwen3-4B-UD-IQ1_S.gguf (1.0 GB) Qwen3-4B-Q4_1.gguf (2.4 GB)
/api/inference/status gguf_variant BF16 Q4_1
Header GGUF · BF16 GGUF · Q4_1
Load notice / toast none "Not enough disk space to download BF16 (7.5 GB needed, 7.4 GB free), so Q4_1 (2.4 GB) was loaded instead."
Chat "capital of France?" no answer; the 2.0k context filled and the probe timed out after 300 s Paris at 6.9 tok/s
BF16 again after freeing space (13–14 GiB free) already_loaded in 0.0 s, still only IQ1_S on disk BF16 (8.05 GB) downloaded and loaded, header GGUF · BF16
Probe checks A1–A4 4 FAIL 4 PASS

Low-disk load: main vs PR

Chat on the served quant: main vs PR

After freeing space: main vs PR

The Actions runs used head 70c7bc7. The later commits cover formatting, the CLI warning, and the checkpoint filter. Qwen3-4B-GGUF is a single checkpoint, so the quant chosen here does not change; the filter's own test covers the multi-checkpoint case.

Tests (CPU).

  • Backend: 1,665 tests across the 16 related files pass.
  • CLI: all 645 tests in unsloth_cli/tests/test_start.py pass as non-root.
  • Frontend: all 12 in load-warning-toast and chat-save-conflict-detail pass.
  • On main, 5 of the PR's 8 low-disk tests fail.

pre-commit.ci failed earlier on this PR, and on #11050, #11046 and #11053, because the kwarg hook reformats about 1,200 files across the repo. The PR's own files pass the hook and ruff check.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: 5b09068ada

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

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits llama_cpp.py where the low-disk fallback takes the smallest quant and the backend keeps reporting the requested one, so the header and status show a variant that is not running. Will get this reviewed.

@Lyxot Lyxot self-assigned this Sep 16, 2026
…ne that did not fit

The fallback records the served quant in `_hf_variant`, so /status, the Studio header and the load dedup all name what is actually running. `_last_load_intent` was left on the requested quant, and that snapshot is what the crash-respawn watchdog replays and what /api/inference/load inherits as `source.hf_variant` when a request omits the variant. Either one re-resolved the quant that did not fit: on a disk since freed that starts a multi-GB download nobody asked for, and on a disk still tight it can land on a quant other than the one that was serving. The snapshot now carries the served variant too.

In the selection itself: when nothing leaves the 5 GB reserve free, variants already complete in the cache tie on new bytes, and the tie went to the smaller one for no saving. The size tie-break now takes the better quant of two that are equally free. Only cached candidates can tie, so nothing else moves.

`_gguf_variant_fallback` becomes `_pending_variant_fallback`; one character from `_variant_fallback_warning` was too close for two fields with different lifetimes.

Tests: the served-variant case now asserts the replayed snapshot, plus new cases for the cached tie-break and for the joined load warning including which notice the teardown keeps. The frontend test drives the real `loadModel`, so the notice wiring is proven rather than matched in source, and the CLI test pins the warning to stderr.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Reviewed the branch and pushed one fix commit (ece000c).

Fixed — the respawn intent kept the quant that did not fit. The fallback already recorded the served quant in _hf_variant, but _last_load_intent still carried the requested one, and that snapshot is replayed by the crash-respawn watchdog and read by /api/inference/load as source.hf_variant when a request omits the variant. On a disk since freed either path would start a multi-GB download of the quant that never fit; on a disk still tight it could land on a quant other than the one serving. load_model now rebinds the intent where it rebinds hf_variant.

Fixed — the tie-break threw away a cached quant. When nothing leaves the 5 GB reserve free, variants already complete in the cache tie on new bytes, and min(key=(needed, total)) took the smaller of them for no saving. The size tie-break is now inverted, so the better quant of two that are equally free wins. Only cached candidates can tie (for an uncached one needed == total), so nothing else moves.

Renamed _gguf_variant_fallback to _pending_variant_fallback — one character from _variant_fallback_warning was too close for two fields with different lifetimes.

Tests. The served-variant case asserts the replayed snapshot; new cases cover the cached tie-break and the joined last_load_warning, including which notice the teardown keeps and which it does not. The frontend test now drives the real loadModel through loadWithStubs instead of matching source text, and the CLI test pins the warning to stderr. Every added assertion was mutation-checked against the production line it covers.

Validation. test_gguf_load_cache_reuse / test_inference_status_loaded_gguf / test_cached_gguf_routes / test_gguf_reload_inheritance / test_llama_cpp_placement 519 passed; unsloth_cli/tests/test_start.py 645 passed; frontend npm test 7717 passed and npm run typecheck clean.

Selection also checked against live Hub metadata rather than fixtures. unsloth/Qwen3-4B-GGUF, requested BF16 (7.5 GB):

free disk this branch main
7.5 GB Q4_1 (2.42 GB) UD-IQ1_S (1.01 GB)
6.0 / 5.4 / 3.0 GB UD-IQ1_S UD-IQ1_S
1.0 GB refuses refuses

And the checkpoint-family filter is a narrowing, so it was checked not to reject legitimate candidates: Qwen3-4B-GGUF (26 files), gpt-oss-20b-GGUF (16), Llama-3.2-3B-Instruct-GGUF (27), DeepSeek-R1-0528-GGUF (235), gemma-3-27b-it-GGUF (27), Qwen3-30B-A3B-GGUF (27), Kimi-K2-Instruct-GGUF (363) each collapse to one family.

Comments and docstrings across the branch were cut by ~60% per the repo's comment guidance, and the new frontend test was folded into load-warning-toast.test.ts rather than kept as a second file.

Not changed, with reasons. I went through the open review threads and agree with the calls already made on them, having checked each against the source:

  • Per-shard cache accounting for fallback candidates — main sized every fallback by its full byte count with no cache credit either, so nothing regressed; crediting partial shards is a follow-up.
  • Warning on an attach without --model — that path deliberately makes no /api/inference/status request, and test_connect_{openclaw,opencode,hermes,pi}_no_launch assert exactly that (assert not any(c[1].endswith("/api/inference/status") for c in fake_studio)). The notice is advisory and Studio still shows it.
  • Reserving space for companion downloads — _download_companion_gguf returns None on a failed fetch, so a full disk leaves the model loaded without the sidecar rather than failing the load.
  • Re-raising the toast for a same-identity external reload — that quant's warning was already shown when it first loaded, and re-raising on warning changes during polling would bring back a toast the user closed.

All four are scope-limiting choices, not defects, so I've left them and resolved the threads.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: ece000c978

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

…s now reads

`FakeLlamaCppBackend` answers only `_InferenceRuntimeFields` from `__getattr__` and raises for anything else, so the new unguarded `llama_backend.last_load_warning` read in `get_status` is an `AttributeError` under every double-driven status test. It does not show on this branch's own CI because the double gained that guard after this branch forked, which is the drift its docstring asks new shared attributes to be added here to prevent.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Merged current main in and pushed one more commit (bb7357e) — this branch was not safe to merge without it, and the earlier green CI could not have shown why.

#11076 landed after this branch forked and gave the shared FakeLlamaCppBackend a __getattr__ that answers _InferenceRuntimeFields and raises for everything else. get_status here adds an unguarded llama_backend.last_load_warning read, which is not a runtime field, so against current main every double-driven status test raises AttributeError: last_load_warning — test_chat_shared_resident.py goes red on all three of its cases. That double's docstring asks for new shared attributes to be added to it rather than worked around at the call site, so last_load_warning = None now sits in its direct-read block alongside spec_fallback_reason and requested_n_ctx. Removing that one line reproduces the three failures.

Checked against the merged tree rather than this branch alone: tests/multi_account/ fails the same 55 tests with and without this branch (identical sets, a pre-existing local artifact of running that directory as a whole), so this adds none. test_gguf_load_cache_reuse, test_inference_status_loaded_gguf, test_cached_gguf_routes, test_gguf_reload_inheritance, test_llama_backend_double, the slot-release, tool and usage suites, and unsloth_cli/tests/test_start.py are green; frontend npm test 7717 passed and npm run typecheck clean.

@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Ran the merged state through CI on a throwaway PR in my fork (now closed) so this got a full run against current main rather than the old base: 55 checks green, and none of the red belongs to this change.

  • Core zoo (all 3 HF/TRL legs) — unsloth-zoo's own test_relative_imports_resolve.py on fused_losses/cross_entropy_loss.py (.tiled_mlp needs spelling absolutely). Different repository, not touched here, and identical across all three dependency legs, so not a version interaction either.
  • Repo tests (CPU, studio) — 3 failures. Two reproduce on untouched origin/main locally: test_preset_sheet_reacts_to_a_reasoning_budget_change and test_no_test_file_spawns_powershell_directly, the latter naming tests/python/test_uv_requirements_path_space.py, which main added in Windows installer: stop uv splitting a requirements path, and keep the error position in diagnostics #11064. The third is a timing flake (assert 1375.5 < 50).
  • Frontend unit tests (Windows) — cancelled, not failed.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bb7357ef3a

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

Approving. Re-verified against the current main tip rather than the branch's merge base.

Trial-merging the latest main into this head merges cleanly — llama_cpp.py auto-merges even though #11055 also landed in it, and the hunks do not overlap.

On that merged tree:

  • studio/backend/tests/multi_account/test_chat_shared_resident.py passes, and dropping last_load_warning from the shared backend double reddens exactly its three sharing cases — so the double entry the new /status read needs is load-bearing, not decoration.
  • The backend batch (this PR's tests plus the adjacent llama.cpp suites) is 1024 passed / 1 failed. The one failure is test_llama_cpp_wait_for_health.py::TestWaitForHealthResilience::test_a_started_shutdown_refuses_to_spawn, which fails identically on clean main with this branch absent, so it is pre-existing and unrelated.
  • Frontend unit suite: 7717 passed, 0 failed.
  • Mutation checks still bite: inverting the roomy selection to the smallest fitting quant fails two cases, and dropping the replayed-intent rewrite fails the served-variant case.

The workflow runs on this head are all still queued pending approval, so upstream CI has no verdict yet; the equivalent legs were exercised separately and the only red ones traced to unsloth-zoo and to failures already present on main.

@Lyxot
Lyxot merged commit ce66f60 into unslothai:main Sep 16, 2026
56 of 58 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…hich one loaded (unslothai#11052)

* Studio: fall back to the largest GGUF quant that fits on low disk and report it

* Size-check cached variants before counting them as free in the low-disk fallback

* Studio: show the low-disk fallback warning in unsloth start and in Studio

* Format load warning test for the kwarg hook

* Print the load warning only when it belongs to the resolved model

* Keep the low-disk fallback on the requested checkpoint

* fix(studio): replay the quant the low-disk fallback served, not the one that did not fit

The fallback records the served quant in `_hf_variant`, so /status, the Studio header and the load dedup all name what is actually running. `_last_load_intent` was left on the requested quant, and that snapshot is what the crash-respawn watchdog replays and what /api/inference/load inherits as `source.hf_variant` when a request omits the variant. Either one re-resolved the quant that did not fit: on a disk since freed that starts a multi-GB download nobody asked for, and on a disk still tight it can land on a quant other than the one that was serving. The snapshot now carries the served variant too.

In the selection itself: when nothing leaves the 5 GB reserve free, variants already complete in the cache tie on new bytes, and the tie went to the smaller one for no saving. The size tie-break now takes the better quant of two that are equally free. Only cached candidates can tie, so nothing else moves.

`_gguf_variant_fallback` becomes `_pending_variant_fallback`; one character from `_variant_fallback_warning` was too close for two fields with different lifetimes.

Tests: the served-variant case now asserts the replayed snapshot, plus new cases for the cached tie-break and for the joined load warning including which notice the teardown keeps. The frontend test drives the real `loadModel`, so the notice wiring is proven rather than matched in source, and the CLI test pins the warning to stderr.

* test(studio): teach the shared backend double the load warning /status now reads

`FakeLlamaCppBackend` answers only `_InferenceRuntimeFields` from `__getattr__` and raises for anything else, so the new unguarded `llama_backend.last_load_warning` read in `get_status` is an `AttributeError` under every double-driven status test. It does not show on this branch's own CI because the double gained that guard after this branch forked, which is the drift its docstring asks new shared attributes to be added here to prevent.

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Lyxot <[email protected]>
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