Skip to content

Stop unsloth chat and unsloth inference reloading a 16-bit model in 4-bit - #11477

Merged
Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:cli-chat-keep-server-precision
Sep 22, 2026
Merged

Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:cli-chat-keep-server-precision

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

If Studio already has a model loaded in 16-bit, running unsloth chat or unsloth inference on the same model unloads it and loads it again in 4-bit. The chosen quality is lost and the model reloads for no reason.

The CLI always sent 4-bit because that was its default. It now only sends it when --load-in-4bit or --no-load-in-4bit is typed, the same way #10257 fixed this for context length. Tested on a real Studio with Qwen2.5-0.5B: main reloaded the model in 4-bit, this branch kept the 16-bit model.

@NilayYadav

NilayYadav commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions evidence

Reviewed head: e1eeaf17c5. Codex is clean on both 6aaa525b41 and e1eeaf17c5 ("Didn't find any major issues").

Setup. Real Studio on macos-15 using MLX. unsloth/Qwen2.5-0.5B-Instruct is loaded in 16-bit through /api/inference/load (load_in_4bit:false), then unsloth inference runs without --load-in-4bit. Values below come from /api/inference/status and the server log.

P2, found and fixed in e1eeaf17c5. On the original head, omitting load_in_4bit only prevented the reload when nothing else differed. If another setting forced a reload, the omitted field fell back to the server default True, so the 16-bit model was still requantized. For example, the model was loaded at context 2048 and the CLI sends 0. Run on 6aaa525b41 (job):
load_in_4bit False -> True, requested_context_length 2048 -> 0, and the log shows Loading ... via mlx-lm (runtime 4-bit affine quantization).
Fix: when a /load omits load_in_4bit and the same model is resident, it keeps the resident's requested precision (_inherit_resident_load_in_4bit), with tests in test_non_gguf_reload_settings.py.

Results on e1eeaf17c5:

Resident load Result
ctx 0 (job) Model already loaded ..., skipping reload, load_in_4bit False -> False, 1 "Model loaded" row in the API monitor
ctx 2048 (job) reloaded for the context change, load_in_4bit False -> False, no 4-bit requantization

The same workflow with the implementation reverted to main fails both cells: ctx 0 (job) and ctx 2048 (job) both give load_in_4bit False -> True, a 4-bit requantize, and 2 "Model loaded" rows.

UI (API monitor page, Chromium 1366x900, same workflow, resident at ctx 0 on both sides): before, the CLI adds a second "Model loaded" row, because it reloaded the model. After, the model is reused and there is a single row.

PR 11477 API monitor before/after

Tests: unsloth_cli/tests/test_inference_chat.py plus studio/backend/tests/test_non_gguf_reload_settings.py: 151 passed. The new CLI tests fail on the base implementation. On the full unsloth_cli/tests suite, the only failures are 4 environment-only tests that also fail on base.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this on main, where unsloth_cli/_inference.py always ships the default load_in_4bit so a Studio-resident 16-bit model gets requantized, and the resident precision is not inherited when another setting forces the reload. Thanks for the staging evidence on both paths, will get this reviewed.

@Lyxot Lyxot self-assigned this Sep 22, 2026
@Lyxot

Lyxot commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Codex review on a staging copy (Lyxot#69, diff identical to this PR at e1eeaf1) converged on the first pass with no findings: Lyxot#69 (comment)

There were no review threads to address on this PR.

CI on the staging PR: 52 passed, 4 skipped, 2 failed. Neither failure touches unsloth_cli or the inference load route:

  • Repo tests (CPU, studio): 11502 passed, 4 failed, all frontend source-contract tests (test_chat_response_details_ui_contract.py x3, test_desktop_reliability_frontend_contract.py x1). This job also fails on current main.
  • Shell installer tests: ROCm GPU-selection cases (_amd_prefer_discrete_gfx: command not found), also failing on this PR's upstream run.

The upstream run's other failures are unrelated too: the three Core zoo jobs fail on two gguf readback-tree provenance tests (test_gguf_readback_tree_provenance.py), the same failures main showed at that time; they pass on the latest main run.

@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. Rechecked against current main: merges cleanly, focused CLI and reload-settings tests pass on the merge, and Codex converged on this head.

@Lyxot

Lyxot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Pushed 7b15f72 on top of the PR: the typed-flag filter the two commands duplicated is now one server_load_opts helper in unsloth_cli/_inference.py, --load-in-4bit documents that leaving it unset keeps the precision of a model the running server already has loaded, and the _inherit_resident_load_in_4bit docstring is one line. No behavior change.

Codex review on the staging copy (Lyxot#69, diff identical to this PR at 7b15f72) converged with no findings: Lyxot#69 (comment)

CI on the staging PR: 51 passed, 4 skipped, 3 failed. None touches unsloth_cli or the inference load route:

  • Repo tests (CPU, studio): 11502 passed, 4 failed, the same frontend source-contract tests as the previous run (test_chat_response_details_ui_contract.py x3, test_desktop_reliability_frontend_contract.py x1). This job also fails on current main.
  • Shell installer tests: the same ROCm GPU-selection cases as before.
  • connection (dsh, stable): npm install -g @deepseek-ai/dsh fails with ETARGET because a dependency version it requests is not published; it passed on the previous staging run.

@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 on 7b15f72. Merges cleanly with current main, focused CLI and reload-settings tests pass, and Codex converged on this head.

@Lyxot
Lyxot merged commit 3c3475e into unslothai:main Sep 22, 2026
54 of 59 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…-bit (unslothai#11477)

`unsloth chat` and `unsloth inference` send `load_in_4bit` to a running Unsloth server only when `--load-in-4bit` or `--no-load-in-4bit` is typed, so the untyped default no longer reloads a resident 16-bit model in 4-bit. A load that omits `load_in_4bit` for the resident model inherits its requested precision, so a reload forced by another setting keeps it.
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