Repository navigation
Unsloth Studio: re-fit the context window when MTP speculative decoding reserves extra memory - #9572
Closed
danielhanchen wants to merge 5 commits into
Closed
danielhanchen wants to merge 5 commits into
danielhanchen wants to merge 5 commits into
Conversation
…ver priced Auto drops a drafter that does not fit rather than shrink the context for it, and clears the MTP overhead when it does, so the context it settles on is fit against a budget with no reserve in it. Reloading the same model replays that resolved context as max_seq_length, which makes it explicit, and forcing the drafter in the dropdown re-arms the reserve. The explicit branch then spends the shortfall on another GPU instead of on the context that never accounted for it, which is the reporter's 31 GB model taking a second card to hold a 2.18 GB drafter at 112896. Reproduced with his numbers: 262144 -> 122624 under Auto with the drafter dropped, then the forced load re-fits to 100864 and stays on one card. The value the client sends does not change, only its provenance: resolveLoadMaxSeqLength gained a detailed variant naming the branch that supplied it, and the same-model replay is reported as max_seq_length_auto_derived. The dedupe comparison, the staged preset config and the settings sheet all keep reading the same number. The re-fit is gated on three things together -- the context was ours, the speculative choice is forced rather than Auto, and the reserve costs GPU memory -- so a context the user typed is still honored verbatim, Auto still keeps its context and drops the drafter, and a load with no reserve is untouched. It prices the cards the context was fit for rather than the whole pool, since a pooled budget would find room for the reserve and leave the extra card in place, which is the thing being complained about. Fixes #9550
Resolve preset-policy.ts / use-chat-model-runtime.ts conflicts against main's loadedContextLength / pinnedMaxSeqLength arguments. Re-fit now reads main's _fit_ctx_checkpoints (the old _effective_ctx_checkpoints is bound later on main), prices the base cards with _subset_model_size and per-device compute buffers, selects the base placement at the unreserved fraction, and treats a drafter forced through advanced arguments as forced. Trim comments.
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. |
…ew test's preset source
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
From #9550, the same 31.0 GB model loaded twice:
The second load keeps 112896 and pays the reserve on top, pulling in the 8 GiB card, instead of re-deriving a context that fits with the reserve.
mtp_overhead_fn, so the context it settles on was fit with no reserve in it.max_seq_length(resolveLoadMaxSeqLengthreturnsloadedContextLength), which makesexplicit_ctxtrue, so the planner honors it verbatim and spends the shortfall on another GPU.The replay itself is needed (sending 0 on a pinned reload would ask for the native context), so it stays.
Fix
resolveLoadMaxSeqLengthDetailedreturns the value plus where it came from;resolveLoadMaxSeqLengthis a thin wrapper, so every existing caller is unchanged.LoadRequest.max_seq_length_auto_derived(defaultFalse) carries that provenance toGgufLoadIntent.n_ctx_auto_derived. Old clients keep verbatim honoring.if explicit_ctx:, the context is re-fit only when it was ours, the drafter is forced (dropdown or advanced arguments, i.e. anything that bypasses the Auto drop probe), and the reserve costs GPU memory. The re-fit prices the cards the context was originally fit for, so the drafter shrinks the context instead of adding a card. It only ever moves downwards.With the reporter's numbers:
A context the user typed, Auto speculation, and loads with no reserve all take the existing path unchanged.
Tests
studio/backend/tests/test_mtp_context_refit_9550.py: the reserve costs context, Auto still drops the drafter, forcing MTP (dropdown and--spec-type draft-mtpin advanced arguments) re-fits, and a user-typed context is still honored verbatim. Disabling the re-fit fails the forced cases.studio/frontend/tests/load-max-seq-length-source.test.ts: provenance per branch.tscclean, 9322/9322 node tests pass.Fixes #9550