Skip to content

Drop an MTP sidecar llama-server cannot load as --model-draft - #10197

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
Lyxot:studio-mtp-unloadable-drafter
Sep 14, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
Lyxot:studio-mtp-unloadable-drafter

Conversation

@Lyxot

@Lyxot Lyxot commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • judge the resolved MTP drafter as well as the target: a mtp-*.gguf shipping neither token_embd.weight nor <arch>.nextn_shared_target_tensors cannot be opened as --model-draft and is dropped instead of aborting the launch
  • run that check before the fit prices the drafter, so a file that never launches cannot push layers off the GPU
  • record the dropped file as suppressed, so a repeat Apply against the sidecar still on disk does not tear down a healthy server

Why

#10181 fixed one half of #10169: a main GGUF reporting <arch>.nextn_predict_layers > 0 now takes no separate drafter. The reported repository publishes both halves, and the other half still fails.

File nextn_predict_layers Tensors Effect on current main
RVN-Q6_K-mtp.gguf 1 866 no sidecar, fixed by #10181
RVN-Q6_K.gguf absent 851 pairs with the sidecar below
mtp-RVN.gguf 1 16 no token_embd.weight, no shared flag

Selecting a plain quant, or one of its -vision and -multilingual siblings, still downloads the 1.69 GB sidecar and passes it as --model-draft. llama-server loads a draft model as a complete model, so it exits with tensor 'token_embd.weight' not found, and the spawn retry then drops speculative decoding for a load that had a working configuration available. Nothing on main inspects the drafter file itself.

What changed

_mtp_drafter_loads_standalone reads the drafter's header and reports whether it carries the embeddings a draft model needs, either its own token_embd.weight or <arch>.nextn_shared_target_tensors to borrow the target's. Only that tensor is checked, because the rest of the required set is per-architecture: qwen4exp creates no output_norm tensor at all, and the published Flash-Next head ships token_embd without one, so a stricter refusal would reject drafters that work. Split sets, whose first shard does not list every tensor, and unreadable headers fail open and leave the verdict to llama-server.

The check sits in load_model directly after the embedded-head drop, which is before any sizing. Charged to the budget, a drafter that will not launch would move layers off the GPU for VRAM it never needs, and on a tighter budget cost the load its speculative decoding entirely.

The dropped path goes into the existing suppression record. The sidecar stays on disk and the caller and route keep detecting it, so without that record the detected path never matches the launched None and every repeat Apply reloads. For the same reason the drafter_not_found refetch rule stands down for a suppressed drafter: the fetch did find the file, and refetching returns it again.

DSpark and DFlash sidecars are untouched. They borrow token_embd from the target by design and use their own --spec-type.

One adjacent fix: the virtualised-Metal drop now records only the drafter it actually removed. It can fire on a drafter supplied through raw llama.cpp arguments with none of ours launched, where the unconditional assignment cleared the record made above.

Validation

python -m pytest studio/backend/tests/test_mtp_drafter_companion.py \
                 studio/backend/tests/test_llama_cpp_placement.py \
                 studio/backend/tests/test_mmproj_placement_policy.py \
                 studio/backend/tests/test_llama_cpp_mtp_detection.py \
                 studio/backend/tests/test_metal_paravirtual_guard.py -q

995 passed. Tests cover the predicate against the four shapes repositories publish (bare head extract, a head with its own embeddings, a -shared- head, one shard of a split set), the launch on a headless target with and without a usable drafter, the pricing order, the dedupe, and the suppression record the virtualised-Metal drop must preserve.

Each was mutation-checked: reverting the drop branch, forcing the predicate true, removing the refetch clause, removing the suppression seed, or restoring the unconditional paravirtual assignment each fails exactly the test that covers it.

The headers in the table above were read directly from the reported repository over HTTP range requests rather than inferred.


Before and after in the UI (added during review)

Two isolated Studio installs, one built from this PR's merge base 14a2545be and one from head 00eecb7a2, each home SHA-stamped so neither side can serve a stale bundle. The fixture is a local folder holding two real GGUFs written with the shipped writer: a 2.54 GiB gemma-4-12b-it-Q4_K_M.gguf and a 1.66 GiB head-only mtp-gemma-4-12b-it.gguf carrying neither token_embd.weight nor <arch>.nextn_shared_target_tensors. The same directory is handed to both sides by path, so both halves price identical bytes. Model picker, Run settings, Estimated Memory Usage:

Estimated Memory Usage for a local GGUF with a head-only MTP sidecar, before and after

before after
GPU / Total 66.15 GiB 34.49 GiB
Weights 4.20 GiB 2.54 GiB
Draft cache 30.00 GiB line absent
KV cache 30.00 GiB 30.00 GiB
Compute buffers 1.95 GiB 1.95 GiB

The panel charged the sidecar's 1.66 GiB and reserved a 30 GiB draft KV cache for it, so the estimate was 31.66 GiB above what the load actually asks for. That is the figure the chat-load admission guard reads, which is how this reached a 409 against a running training job. POST /api/inference/estimate-memory at n_ctx 8192 moves with it, weights_bytes 4.199 GB to 2.539 GB; the panel's own figures are larger because it prices Auto, which resolves to the model's native 131,072 tokens across 4 slots.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 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-14T13:04:36.281073Z fea9657 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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…draft

Preferring an embedded MTP head over a repo-root `mtp-*.gguf` fixed one half of unslothai#10169. The reported repository publishes both halves, and the other half still aborts the launch: `RVN-Q6_K-mtp.gguf` reports `qwen35.nextn_predict_layers = 1` and now takes no sidecar, while `RVN-Q6_K.gguf` and its `-vision` and `-multilingual` siblings omit the key entirely. Those headless quants still pair with `mtp-RVN.gguf`, which carries 16 tensors, no `token_embd.weight` and no `nextn_shared_target_tensors`, so llama-server exits with "tensor 'token_embd.weight' not found" and the spawn retry drops speculative decoding for a load that had a working configuration available.

The resolved drafter is now judged as well as the target. A file that ships neither `token_embd.weight` nor `<arch>.nextn_shared_target_tensors` is dropped and the load continues without it. Only `token_embd` is checked: the rest of the required set is per-architecture, qwen4exp creates no `output_norm` tensor at all, and a published Flash-Next head ships `token_embd` without one, so a tighter refusal would reject drafters that work. Split sets and unreadable headers are left for llama-server to judge.

The check runs before the fit prices anything, so a drafter that will not launch cannot push layers off the GPU for VRAM it never needs. The dropped file is recorded as suppressed, since it stays on disk and the caller keeps detecting it: without that record every repeat Apply tears down a healthy server. For the same reason the `drafter_not_found` refetch rule stands down for a suppressed drafter, which refetching would only find again. DSpark and DFlash sidecars are untouched; they borrow `token_embd` from the target by design.

The virtualised-Metal drop now records only the drafter it actually removed. It can fire on a drafter supplied through llama.cpp arguments with none of ours launched, where the unconditional assignment cleared the record above.

The memory estimate applies the same judgement. `_estimate_gguf_required_gb` prices a load independently of the launch planner, and it charged a configured `mtp-*.gguf` for every drafting mode, so a sidecar the load now drops still cost VRAM in the panel and in the chat-load admission guard, which could refuse a load that fits while training runs.
@Lyxot
Lyxot force-pushed the studio-mtp-unloadable-drafter branch from 792ce64 to 9ae7238 Compare September 2, 2026 13:11
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 9ae7238b11

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

Checked main and nothing inspects the drafter file itself, so a head-only mtp-*.gguf still goes through as --model-draft after #10181; the pricing order and the suppression record both look right to me, will get this reviewed.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed main never inspects the sidecar itself, so a head-only mtp-*.gguf still gets passed as --model-draft and priced into the fit, and the check landing before sizing plus the suppression record both look right. Will get this reviewed.

…ole split set

Three changes on top of the drop this branch adds. The drop itself is right: on
llama-server b10909-mix-bea84f7, a head-only sidecar passed as --model-draft beside
its target ends the launch with "check_tensor_dims: tensor 'token_embd.weight' not
found", and one carrying nextn_shared_target_tensors serves. Both verdicts measured,
not inferred, over the four shapes repositories publish plus a false flag, a flag
under the wrong architecture prefix, and a head with no output_norm.

The rule moves to utils/models/gguf_metadata.py, where every other GGUF header read
already lives. It was reading the header through gguf.GGUFReader, which maps the
whole file, with no cache, on two paths: the load and _estimate_gguf_required_gb.
That second one is reached from POST /api/inference/estimate-memory, which documents
itself as safe to call on every settings change, and from kv-cache-estimate, which
prices the file term up to three times per request per picker row. The projector
capability read two lines above it goes through the (path, mtime, size) cache; this
now does too, over the same streaming parser _parse_gguf_has_classifier_head uses,
so no mmap and no gguf import on a request path. Repairing a rejected sidecar in
place is still picked up, since the key carries mtime and size.

split.count > 1 no longer exempts a file from the check. llama-server opens sibling
shards by FILENAME, so a lone file whose header merely claims to be a split set was
accepted untested and then ended the launch anyway. The verdict now comes from
colocated_split_shards, the same helper _gguf_has_classifier_head fans out over: a
complete set is judged across every shard, so embeddings living in shard 2 keep the
set, and a set whose shards are not all here still fails open.

The auto-Vulkan-crash replay that comes up on CPU returns before the commit block,
so it kept the previous load's _mtp_draft_path and _mtp_draft_suppressed_path. That
was inert while only virtualised Metal could suppress a drafter, since an
auto-Vulkan fallback cannot happen there. An unloadable sidecar can be suppressed on
any platform, and a carried-over suppressed path stands the drafter_not_found
refetch down for a load that dropped nothing of its own.
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed this against a real llama-server rather than from the source, because the premise turns on a detail the shipped binary decides. Pushed three changes in bca0212; the drop itself is correct and stays.

The premise holds, and the metadata branch is load-bearing

I built the drafter shapes as real GGUFs and passed each one to llama-server b10909-mix-bea84f7 as --model-draft beside its target, then compared the launch outcome against _mtp_drafter_loads_standalone:

drafter shape predicate llama-server
carries token_embd.weight True serves
head only, no flag False check_tensor_dims: tensor 'token_embd.weight' not found, launch ends
head only, nextn_shared_target_tensors = true True serves
head only, flag set to false False launch ends
head only, flag under another arch prefix False launch ends
head only, flag set, no output_norm True serves

So the error string in the description is the real one, and the shared-target branch is not a guess: that flag is what admits a head into borrow_shared_tensor in src/llama-model-loader.cpp, and without it the tensor gate refuses the file even though a target is present. Leaving output_norm out of the check is right for the same reason you gave. Worth recording that common/speculative.cpp sets mparams.model_shared = model_tgt while llama_model_default_params leaves it null, which is why the same file serves as a draft and fails the --fit measurement pass.

What changed

split.count > 1 no longer exempts a file. llama-server opens sibling shards by filename, so a lone file whose header merely claims to be a split set was accepted untested and then ended the launch anyway. That is the one case in the matrix where the predicate and the server disagreed. The verdict now comes from colocated_split_shards, the helper _gguf_has_classifier_head already fans out over: a complete set is judged across every shard, so embeddings living in shard 2 keep the set, and a set whose shards are not all present still fails open. Your fail-open on an unreadable header is untouched, and still the right call.

The rule moved to utils/models/gguf_metadata.py. It was going through gguf.GGUFReader, which maps the whole file, uncached, on two paths now. The second is _estimate_gguf_required_gb, reached from POST /api/inference/estimate-memory, whose own docstring says it is safe to call on every settings change, and from kv-cache-estimate, which prices the file term up to three times per request per picker row. The projector capability read two lines above yours already goes through the (path, mtime, size) cache; this now does too, over the streaming parser _parse_gguf_has_classifier_head uses, so there is no mmap and no gguf import on a request path. Because the key carries mtime and size, repairing a rejected sidecar in place is still picked up.

The CPU-fallback return now records the drafter. The auto-Vulkan-crash replay returns before the commit block, so it kept the previous load's _mtp_draft_path and _mtp_draft_suppressed_path. That was inert while only virtualised Metal could suppress a drafter, since an auto-Vulkan fallback cannot happen there. Your change makes suppression reachable on any platform, and a carried-over suppressed path stands the drafter_not_found refetch down for a load that dropped nothing of its own.

On your two open replies

Both are fair. The refetch guard is right for the paravirtual drop as well, and it arguably fixes a live bug there: an -hf load on a virtualised Mac hit _fallback_drafter_not_found, so that arm returned False on every repeat Apply and defeated the record the field exists to keep.

The one thing I would still like is a distinct reason. A dropped-but-present sidecar reports drafter_not_found, and chat-settings-sheet.tsx then tells a local load to place a file that is already there. The precedent is in this file already: the DFlash header rejection records _dflash_sidecar_absent and surfaces it as spec_dflash_retry_pending, and spec_dspark_sidecar_absent does the same for the other exclusion from that arm. This adds a third exclusion with no flag, so a client sees drafter_not_found with both existing flags false and still prompts for a reload that now dedupes. Happy for that to be a follow-up rather than growing this one.

Validation

1174 passed across the six files this branch touches. Full studio-backend leg and the cross-platform staging run (Linux, Windows, Apple Silicon macOS) are going now; I will follow up if either says otherwise.

# Conflicts:
#	studio/backend/utils/models/gguf_metadata.py
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
…ays what is wrong

The suppression record said THAT a drafter was dropped but not WHY, and two separate
consumers need to know: whether repairing the file should reload, and which fallback
reason the client is told. Both drops now carry a reason, "unloadable" or "paravirtual".

Repairing a rejected sidecar in place did nothing until an unrelated reload. The dedupe
counts a deliberately dropped drafter as launched and compares resolved paths, so
replacing a head-only mtp-*.gguf with a self-contained one at the same path still reports
the model as already loaded and the header check never reran. It is re-asked now, but
only for the unloadable drop: the paravirtual one is a property of the build, so the same
bytes would be dropped again and the reload would buy nothing. The predicate is cached on
(path, mtime, size), so an untouched file is not reparsed.

A present, unopenable sidecar reported drafter_not_found, which tells a local load to
place a file that is already on disk and offers a remote load a refetch this branch
deliberately stands down. It also sits in the frontend's RETRYABLE_SPEC_FALLBACKS, so
Apply kept sending a reload the backend then deduped through already_loaded. It reports
drafter_unloadable now, with copy that names the real remedy. The field is Optional[str],
so an older client falls through to the generic message rather than breaking, and the new
reason is absent from the retry set by construction.

Tests: repairing an unloadable drafter in place reloads, repairing a paravirtually
suppressed one does not, the reason is reported for a dropped sidecar and still
drafter_not_found for a genuinely absent one, and drafter_unloadable is not repairable
client-side. 1202 passed across the studio backend suites this touches.
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ains itself

The fallback that records a reason was reachable only for the name-only Gemma shape.
RVN-Q6_K.gguf, the quant this branch exists for, reports no nextn_predict_layers and
carries no -mtp in its name, so the sidecar beside it was its only MTP signal: clearing
mtp_draft_path made is_mtp_model read false, _mtp_drafter_missing recognised Gemma alone,
and neither Auto nor forced MTP reached _fallback_drafter_not_found. Speculative decoding
went off with spec_fallback_reason null, so the panel had nothing to show for it.

The dropped path is kept as a signal in both predicates, gated on the drop having
happened. is_mtp_model sees it so the MTP arms are entered at all, and
_mtp_drafter_missing sees it so the arm taken is the fallback rather than _emit_mtp:
emitting MTP with no drafter is what aborts llama-server, which is the failure this
branch removes. A model that never had a sidecar is untouched, and a Gemma name already
satisfied the first clause, so neither existing path changes.

Tests: the reported non-Gemma quant now reports drafter_unloadable under both auto and
forced mtp and emits no --model-draft, and a plain quant with no sidecar at all still
records no reason. 1205 passed across the studio backend suites this touches.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
@unslothai unslothai deleted a comment from Lyxot Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…er runs

The re-check added in 00eecb7 answers on the next /load, and `adoptable` in
use-chat-model-runtime skips /load entirely when residentSpeculativeNeedsRepair says
there is nothing to repair. With drafter_unloadable outside the retry set, replacing the
sidecar in place did exactly what the settings sheet tells the user to do and then
nothing happened, because the request that would have noticed was never sent. The
comment on that gate already says as much: a repairable speculative fallback is the one
case where an identical request is not a no-op.

So it belongs in the set. An unchanged file still dedupes, which is what makes declining
the shortcut cheap rather than a teardown: the re-check asks the predicate, gets the same
verdict, and _runtime_matches_intent adopts, so the load returns through already_loaded
without touching the server. That safety is the earlier commit's doing, and it is why
this cannot loop.

No sendsGgufPath exclusion, unlike drafter_not_found. That one is guarded on
`intent.gguf_path is None` because it drives a refetch; this re-check sits in the drafter
comparison, guarded on `intent.gguf_path is not None or intent.compare_mtp_draft`, so a
standalone .gguf load reaches it too.

Frontend suite: 105 passed in resident-config-match.test.ts, and the whole studio/frontend
suite shows the same 226 pre-existing failures as the merge base, zero new.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026

@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: ed670b6e00

ℹ️ 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 on lines +10780 to +10783
_mtp = getattr(config, "gguf_mtp_file", None)
if not (
_mtp and Path(_mtp).is_file() and not _mtp_drafter_loads_standalone(str(_mtp))
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate cached estimates when drafter contents change

When an unloadable sidecar has already been estimated and the user follows the new guidance to replace it in place, this content-dependent predicate is not necessarily reevaluated: _gguf_resident_file_gb caches the result for 30 seconds using the main model path and settings, without the MTP sidecar's identity or metadata version in its key. During that window the memory panel continues omitting the now-loadable drafter and its potentially large runtime reserve even though the backend rechecks and launches it; include the sidecar's file identity in the cache key or invalidate the cached estimate after replacement.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accurate as a description, but below the bar for a change here, and I checked the two things that would have raised it.

The admission guard does not share that cache. routes/inference.py:13501 calls _estimate_gguf_required_gb directly rather than going through _gguf_resident_file_gb, so the 409-against-training path and the load itself always recompute and always see the repaired file. Had the guard read the cached value this would be a 409-class bug and I would have fixed it. What is left is the memory PANEL showing a figure up to 30 s stale after the file is swapped underneath it, and it under-reports rather than over-blocks, so it cannot refuse a load that fits.

And the cache omits file identity for every file it keys on, not just the sidecar: the key is (identifier, gguf_variant, str(main), disable_vision, speculative_type, extras, token fingerprint, local_only), with no mtime or size for the main weight either. Replace the main GGUF in place today, on main, and the same 30 s window applies. Keying only the drafter's identity would make this one term sharper than the weights term beside it, which is the inconsistency rather than the fix.

So: transient, self-healing in 30 s, display-only, guarded where it counts, and a pre-existing property of that cache rather than something this branch introduces. Happy to reconsider if you can point at a consumer of the cached value that refuses or resizes a load.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 14, 2026 12:31
…dropped

The unloadable-drafter drop cleared the configured path whenever the detected
sidecar could not load standalone, without first checking whether llama_extra_args
already names its own --model-draft. Draft flags are last-wins, so the user's file
is the one llama-server opens and the rejected sibling is never passed; dropping it
anyway made the load read as drafterless and _build_speculative_flags emitted the
ngram or default fallback before the extras were appended, so a valid override
stopped running as MTP at all.

Skip the drop when the extras own the draft path, matching the idiom the adjacent
paravirtual drop already uses.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 0514474982

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

Same code, fewer lines: collapse the multi-line explanations to their load-bearing
sentence and drop the restatements. The measured llama-server behaviour behind the
predicate is kept, since nothing in the tree records it otherwise.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: fea9657e39

ℹ️ 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
danielhanchen merged commit 645a350 into unslothai:main Sep 14, 2026
47 of 53 checks passed
danielhanchen added a commit that referenced this pull request Sep 14, 2026
The kwarg-spacing hook rewrites one line in _split_fits_capacity that #10197
left unformatted, so pre-commit.ci fails on every open PR: it runs --all-files
against the PR merged into main, and the drift arrives from main rather than
from the PR. Reproduced on a clean checkout of main with no PR applied.

Formatting only, no semantic change.
danielhanchen added a commit that referenced this pull request Sep 14, 2026
* fix(studio): drop an MTP sidecar llama-server cannot load as --model-draft

Preferring an embedded MTP head over a repo-root `mtp-*.gguf` fixed one half of #10169. The reported repository publishes both halves, and the other half still aborts the launch: `RVN-Q6_K-mtp.gguf` reports `qwen35.nextn_predict_layers = 1` and now takes no sidecar, while `RVN-Q6_K.gguf` and its `-vision` and `-multilingual` siblings omit the key entirely. Those headless quants still pair with `mtp-RVN.gguf`, which carries 16 tensors, no `token_embd.weight` and no `nextn_shared_target_tensors`, so llama-server exits with "tensor 'token_embd.weight' not found" and the spawn retry drops speculative decoding for a load that had a working configuration available.

The resolved drafter is now judged as well as the target. A file that ships neither `token_embd.weight` nor `<arch>.nextn_shared_target_tensors` is dropped and the load continues without it. Only `token_embd` is checked: the rest of the required set is per-architecture, qwen4exp creates no `output_norm` tensor at all, and a published Flash-Next head ships `token_embd` without one, so a tighter refusal would reject drafters that work. Split sets and unreadable headers are left for llama-server to judge.

The check runs before the fit prices anything, so a drafter that will not launch cannot push layers off the GPU for VRAM it never needs. The dropped file is recorded as suppressed, since it stays on disk and the caller keeps detecting it: without that record every repeat Apply tears down a healthy server. For the same reason the `drafter_not_found` refetch rule stands down for a suppressed drafter, which refetching would only find again. DSpark and DFlash sidecars are untouched; they borrow `token_embd` from the target by design.

The virtualised-Metal drop now records only the drafter it actually removed. It can fire on a drafter supplied through llama.cpp arguments with none of ours launched, where the unconditional assignment cleared the record above.

The memory estimate applies the same judgement. `_estimate_gguf_required_gb` prices a load independently of the launch planner, and it charged a configured `mtp-*.gguf` for every drafting mode, so a sidecar the load now drops still cost VRAM in the panel and in the chat-load admission guard, which could refuse a load that fits while training runs.

* Judge an MTP drafter from the cached header reader, and across its whole split set

Three changes on top of the drop this branch adds. The drop itself is right: on
llama-server b10909-mix-bea84f7, a head-only sidecar passed as --model-draft beside
its target ends the launch with "check_tensor_dims: tensor 'token_embd.weight' not
found", and one carrying nextn_shared_target_tensors serves. Both verdicts measured,
not inferred, over the four shapes repositories publish plus a false flag, a flag
under the wrong architecture prefix, and a head with no output_norm.

The rule moves to utils/models/gguf_metadata.py, where every other GGUF header read
already lives. It was reading the header through gguf.GGUFReader, which maps the
whole file, with no cache, on two paths: the load and _estimate_gguf_required_gb.
That second one is reached from POST /api/inference/estimate-memory, which documents
itself as safe to call on every settings change, and from kv-cache-estimate, which
prices the file term up to three times per request per picker row. The projector
capability read two lines above it goes through the (path, mtime, size) cache; this
now does too, over the same streaming parser _parse_gguf_has_classifier_head uses,
so no mmap and no gguf import on a request path. Repairing a rejected sidecar in
place is still picked up, since the key carries mtime and size.

split.count > 1 no longer exempts a file from the check. llama-server opens sibling
shards by FILENAME, so a lone file whose header merely claims to be a split set was
accepted untested and then ended the launch anyway. The verdict now comes from
colocated_split_shards, the same helper _gguf_has_classifier_head fans out over: a
complete set is judged across every shard, so embeddings living in shard 2 keep the
set, and a set whose shards are not all here still fails open.

The auto-Vulkan-crash replay that comes up on CPU returns before the commit block,
so it kept the previous load's _mtp_draft_path and _mtp_draft_suppressed_path. That
was inert while only virtualised Metal could suppress a drafter, since an
auto-Vulkan fallback cannot happen there. An unloadable sidecar can be suppressed on
any platform, and a carried-over suppressed path stands the drafter_not_found
refetch down for a load that dropped nothing of its own.

* Record why a drafter was suppressed, so a repair reloads and the UI says what is wrong

The suppression record said THAT a drafter was dropped but not WHY, and two separate
consumers need to know: whether repairing the file should reload, and which fallback
reason the client is told. Both drops now carry a reason, "unloadable" or "paravirtual".

Repairing a rejected sidecar in place did nothing until an unrelated reload. The dedupe
counts a deliberately dropped drafter as launched and compares resolved paths, so
replacing a head-only mtp-*.gguf with a self-contained one at the same path still reports
the model as already loaded and the header check never reran. It is re-asked now, but
only for the unloadable drop: the paravirtual one is a property of the build, so the same
bytes would be dropped again and the reload would buy nothing. The predicate is cached on
(path, mtime, size), so an untouched file is not reparsed.

A present, unopenable sidecar reported drafter_not_found, which tells a local load to
place a file that is already on disk and offers a remote load a refetch this branch
deliberately stands down. It also sits in the frontend's RETRYABLE_SPEC_FALLBACKS, so
Apply kept sending a reload the backend then deduped through already_loaded. It reports
drafter_unloadable now, with copy that names the real remedy. The field is Optional[str],
so an older client falls through to the generic message rather than breaking, and the new
reason is absent from the retry set by construction.

Tests: repairing an unloadable drafter in place reloads, repairing a paravirtually
suppressed one does not, the reason is reported for a dropped sidecar and still
drafter_not_found for a genuinely absent one, and drafter_unloadable is not repairable
client-side. 1202 passed across the studio backend suites this touches.

* Keep a dropped sidecar as an MTP signal, so the motivating quant explains itself

The fallback that records a reason was reachable only for the name-only Gemma shape.
RVN-Q6_K.gguf, the quant this branch exists for, reports no nextn_predict_layers and
carries no -mtp in its name, so the sidecar beside it was its only MTP signal: clearing
mtp_draft_path made is_mtp_model read false, _mtp_drafter_missing recognised Gemma alone,
and neither Auto nor forced MTP reached _fallback_drafter_not_found. Speculative decoding
went off with spec_fallback_reason null, so the panel had nothing to show for it.

The dropped path is kept as a signal in both predicates, gated on the drop having
happened. is_mtp_model sees it so the MTP arms are entered at all, and
_mtp_drafter_missing sees it so the arm taken is the fallback rather than _emit_mtp:
emitting MTP with no drafter is what aborts llama-server, which is the failure this
branch removes. A model that never had a sidecar is untouched, and a Gemma name already
satisfied the first clause, so neither existing path changes.

Tests: the reported non-Gemma quant now reports drafter_unloadable under both auto and
forced mtp and emits no --model-draft, and a plain quant with no sidecar at all still
records no reason. 1205 passed across the studio backend suites this touches.

* Let a repaired drafter reach the backend, or the content re-check never runs

The re-check added in 00eecb7 answers on the next /load, and `adoptable` in
use-chat-model-runtime skips /load entirely when residentSpeculativeNeedsRepair says
there is nothing to repair. With drafter_unloadable outside the retry set, replacing the
sidecar in place did exactly what the settings sheet tells the user to do and then
nothing happened, because the request that would have noticed was never sent. The
comment on that gate already says as much: a repairable speculative fallback is the one
case where an identical request is not a no-op.

So it belongs in the set. An unchanged file still dedupes, which is what makes declining
the shortcut cheap rather than a teardown: the re-check asks the predicate, gets the same
verdict, and _runtime_matches_intent adopts, so the load returns through already_loaded
without touching the server. That safety is the earlier commit's doing, and it is why
this cannot loop.

No sendsGgufPath exclusion, unlike drafter_not_found. That one is guarded on
`intent.gguf_path is None` because it drives a refetch; this re-check sits in the drafter
comparison, guarded on `intent.gguf_path is not None or intent.compare_mtp_draft`, so a
standalone .gguf load reaches it too.

Frontend suite: 105 passed in resident-config-match.test.ts, and the whole studio/frontend
suite shows the same 226 pre-existing failures as the merge base, zero new.

* Keep an advanced-argument --model-draft when the detected sidecar is dropped

The unloadable-drafter drop cleared the configured path whenever the detected
sidecar could not load standalone, without first checking whether llama_extra_args
already names its own --model-draft. Draft flags are last-wins, so the user's file
is the one llama-server opens and the rejected sibling is never passed; dropping it
anyway made the load read as drafterless and _build_speculative_flags emitted the
ngram or default fallback before the extras were appended, so a valid override
stopped running as MTP at all.

Skip the drop when the extras own the draft path, matching the idiom the adjacent
paravirtual drop already uses.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tighten the comments added by this change

Same code, fewer lines: collapse the multi-line explanations to their load-bearing
sentence and drop the restatements. The measured llama-server behaviour behind the
predicate is kept, since nothing in the tree records it otherwise.

---------

Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

2 participants