Repository navigation
Studio: fit the context again when MTP is forced on a reload - #12231
Conversation
|
Codex review coverage (run on the mirror NilayYadav#125, since Codex does not answer on upstream PRs):
Also fixed from review in Tests: |
|
Review record for #12231, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#185. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
…reset (#18379) ## Problem With Context on Auto, reloading the same GGUF model fitted the context again only when the active preset was the untouched built-in Default. Under a saved preset, or after any Run settings edit such as Temperature (which marks Default as modified), changing the KV cache type, vision or the GPU set and clicking Reload model kept the old context: - A change that frees memory (f16 to q8_0 KV) did not grow the context. - A change that needs more memory (q8_0 to f16 KV) kept the old context and gave up something else instead. In the run below, the vision projector moved to the CPU. ## Cause `resolveLoadMaxSeqLength` (`preset-policy.ts`) returned 0 for an Auto GGUF load only when `presetSource === "builtin-default"`. Under `custom` and `modified`, a same-model reload resent `loadedContextLength`, the context the resident model was fitted to, with `max_seq_length_auto_derived: true`. The backend treats any positive `max_seq_length` as explicit. It fits a resent value again only when MTP is forced, an exception added by #12231 for the MTP case of this bug (#9550). This PR removes the resend itself. ## Fix - An Auto GGUF load always sends 0, so a reload is sized like a fresh load whatever preset is active. - `isReplayedLoadContext` and the frontend's `max_seq_length_auto_derived` field are removed. This reload was their only sender. - The memory estimate on the model config page follows the same rule. - The config page's two fixed-layer checks (estimate and Apply) now treat an unset per-model GPU memory mode as the standing preference, as `performLoad` does. Without this, with fixed layers and an inherited Manual mode, the estimate would price a context of 0 while Reload keeps the resident context. ## Unchanged - A typed Context Length is still sent as typed. - Manual GPU memory with fixed layers still keeps the resident context on a same-model reload (`performLoad`), since `--fit off` would otherwise launch at the native context. - Rollback after a failed model switch can still resend the previous model's fitted context. - Non-GGUF, MLX and the backend. The backend still accepts `max_seq_length_auto_derived` from API clients. - Picking the resident model again after an Auto load still uses it without a reload. ## Verification Live A/B through the real UI with Playwright. The same backend served the `main` and PR frontend builds. The model was `unsloth/Qwen3.5-9B-GGUF` Q4_K_M on an RTX 6000 Ada with about 10 GB of VRAM free, so Auto fits below the native context. The `/load` body was captured in the browser, and the context was read from `/api/inference/status`. | Step | `main`, Default untouched | `main`, Temperature edited | PR, Temperature edited | |---|---|---|---| | Load on Auto, f16 KV | 64,512 | 64,512 | 64,512 | | KV f16 to q8_0, Reload | sends `0`, gets 96,768 | sends `64512`, stays 64,512 | sends `0`, gets 96,768 | | KV q8_0 to f16, Reload | | sends `96768`, stays 96,768 with `--no-mmproj-offload` | sends `0`, gets 64,512, projector on GPU | In the `main` q8_0 to f16 step, the model was already at 96,768 (reached through the Default path) before the Temperature edit. Tests: - `replayed-load-context.test.ts`, which asserted the resend, is replaced by `auto-context-reload.test.ts`. The new file also covers the inherited Manual estimate case. The same-model reload cases in `context-pin-survives-load.test.ts` and the two fixed-layer contract tests in `test_model_picker_contracts.py` are updated. - `npm test` has 8 failures, the same 8 as on unmodified `main`, and none involve this change. `npm run typecheck` passes, and ESLint output for the changed files is unchanged. - The Python tests that read the changed frontend files (29 modules, 1,507 tests) pass. --------- Co-authored-by: Lyxot <[email protected]>
When Auto can't fit the MTP drafter, it turns it off and keeps the largest context. Studio then says to pick MTP in Settings to force it at a smaller context. With a saved or custom preset active, doing that reloaded at the same context that was fitted without the drafter, so the model spilled onto a second GPU instead of shrinking the context.
The reload now marks a context that is just the one the last load picked. When a drafter is forced, that context is fitted again the same way a fresh MTP load is, and it can only go down. A Context Length you type is still used as typed, and Auto is unchanged.
Tested on 2x L40S with Qwen3.6-27B-MTP UD-Q8_K_XL (real Studio, saved preset, MTP picked, Reload model):
This replaces #9572. That PR does not fix the bug: on real GPUs it still loads 120,064 across both cards, exactly like main.
Fixes #9550
Before / after in Studio
Forcing MTP on a same-model reload of the context Auto fitted without the drafter (
unsloth/Qwen3.5-4B-MTP-GGUFQ4_K_M, B200 held to about 12 GiB free, 4 parallel slots). Both sides use the same device headroom and the exact/api/inference/loadpayload the chat UI sends for that reload (max_seq_length= loaded context,max_seq_length_auto_derived= true,speculative_type=mtp). Both sides pass--load-mode autoas advanced arguments because this host'sllama-server --helpprobe was slow.852795db9): the drafter is loaded at the replayed 79.9k context; Studio's own estimate is 13.80 GiB against about 12 GiB free, which is flagged in the run settings.33711e388): the replayed context is re-fitted with the drafter, like a fresh MTP load, and lands at 56.1k with no memory warning.