Repository navigation
Stop unsloth chat from reloading a model the server already has - #10257
Conversation
GitHub Actions reproduction — before/afterStaged on fresh upstream The probe is end-to-end on real code, with no model download and no torch: it stands a loopback endpoint that passes the CLI's real Fix reverted — expected-failing run: PR head — passing run: The same passing run also runs the repo's own tests: That last one matters here: upstream Repo tests (CPU) is red on this PR for reasons unrelated to it — Downstream of Two fixes were pushed onto this branch after the original commit: |
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. 🚀 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". |
|
Confirmed unsloth_cli/commands/chat.py still defaults --max-seq-length to 4096 and inference.py to 2048 while studio.py uses 0, so a default attach never matches a resident server. One thing before I review: for a hub model with no running server this drops the chat context from 4096 to the 2048 normalisation, could you confirm that is intended? |
57b5f61 to
0ec66cf
Compare
|
Pushed a revision of this branch. The fix itself is unchanged — both commands now default What changed around it:
Two notes for the description: The Worth stating explicitly that this changes the no-server path too, since the description only covers attach. Local GGUF and MLX loads improve: they now take the checkpoint's trained window instead of a pinned 4096. The transformers backend has no window to read and keeps its 2048 fallback, so Validation: |
`tests/studio/test_cli_context_defaults.py` parses the command sources with `ast` and asserts the `--max-seq-length` default is the literal 0. Reverting both defaults already fails the two forwarding tests in `unsloth_cli/tests/test_inference_chat.py`, so the source-shape check detects nothing they do not, and it would fail a refactor that hoists the default into a shared constant while behaviour is unchanged. CLI option tests also live under `unsloth_cli/tests/`. Replace it with a behaviour test for the path that was untested: with no server, the sentinel reaches `load_chat_backend` and an explicit `--max-seq-length` still gets through. That is where the local default actually changes, so it is worth asserting rather than inferring. Reword the comment on `test_chat_forwards_gguf_runtime_options_to_loader`: 0 matches a server that also asked for nothing, not whatever context a resident server runs. A server launched with an explicit context still reloads, which `_non_gguf_runtime_settings_match` documents as deliberate.
0ec66cf to
4fb2ad8
Compare
|
Correction to my last comment: I should not have squashed your commits. I have restored the four original ones and my changes are now a single commit on top, so the branch history is yours again and only the last commit is mine. The rebase onto Nothing about the content changed from what I described above, and the branch still ends in the same tree. Sorry for the churn. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fb2ad8255
ℹ️ 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".
The help text said 0 gives "2048 for hub models". It does on the transformers backend, whose `<= 0` fallback is that constant, but on Apple Silicon a hub model loads through `MLXInferenceBackend`, where `_resolve_context_lengths` reads the checkpoint's own window: `runtime_context_length` skips the non-positive request and falls through to `max_position_embeddings`. A reader planning around a 2048-token window, and its memory characteristics, would be wrong on that platform. `unsloth studio run` carries the same wording and is left alone here to keep this change to the two commands the branch touches.
|
@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". |
Lyxot
left a comment
There was a problem hiding this comment.
Approving. The bug is real and the fix is the right shape.
GGUF reuse compares requested contexts rather than served ones (LlamaCppBackend._runtime_matches_intent), so a server launched with the sentinel never matched a CLI asking for 4096 — the attach tore down the resident llama-server and relaunched it while chat printed "model stays warm after /exit". The safetensors path mismatches the same way via _resident_context_satisfies. Defaulting both commands to 0 is not a workaround: it is the value LoadRequest.max_seq_length documents as "let a backend that sizes its own window choose the context itself", and it puts chat and inference on the same contract unsloth studio run already used.
Worth recording that the no-server path changes too. GGUF and MLX loads now take the checkpoint's trained window instead of a pinned 4096, which is an improvement; the transformers backend has no window to read and keeps its 2048 fallback, so unsloth chat without a server goes 4096 to 2048 there. That matches what unsloth inference and unsloth studio run already gave on that path, and --help states it.
One case deliberately left alone: a server started with an explicit --context-length 8192 still reloads when a CLI attaches with the sentinel. That is correct, not a gap — 0 means "give me the model default", and _non_gguf_runtime_settings_match documents the reset being honoured on GGUF.
CI: one red check, Repo tests (CPU), failing on tests/studio/test_model_picker_contracts.py::test_override_writes_are_ordered_per_model. It is unrelated to this diff, which touches only unsloth_cli/. That test asserts a literal TypeScript source string, and main rewrote model-overrides.ts in #10160 and #10114; this branch's base predates that. Three other tests in the same file fail on a clean main checkout with no PR involved, so the file is currently broken independently of this change. Merging the branch with current main clears the reported failure. Fixing that file is worth its own issue — string-matching assertions against frontend sources break on any formatting churn.
Running
unsloth chatwhile Studio is open tears down the model Studio already has loaded and starts it again with a 4096 token context, whatever the model actually supports. The CLI prints that the model stays warm while it does this. The cause is that--max-seq-lengthdefaults to a fixed number, so the request never matches the running server.unsloth startwas fixed for this in #10093 and now defaults to 0, meaning use the model default and only ask for a context when the user names one.chatandinferencewere left as they were. This gives them the same default and says so in the help text.Tested against a running Studio. Before, the server process is killed and comes back at 4096. After, the same process is still there with its original context and answers normally.