Repository navigation
Studio: harden DSpark/MTP drafter detection and companion reclaim - #8037
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2922fd365e
ℹ️ 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".
| return ( | ||
| _drafter_stem_rank(candidate.name, kind = "mtp"), | ||
| _drafter_total_size(candidate), |
There was a problem hiding this comment.
Apply specificity ranking to root-level MTP candidates
The new family-specificity key is used only when sorting candidates collected from MTP/; the root-level branch below still returns the first matching sorted(d.iterdir()) entry. Consequently, when the longer family does not happen to sort first—for example mtp-model.gguf and mtp-model_v2-Q8_0.gguf beside model_v2-Q4_K_M.gguf, or when the base candidate is in start_dir and the exact candidate is in search_root—detect_mtp_file still launches the base-family drafter despite _drafter_stem_rank identifying the exact one. Collect and rank root candidates as well before returning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it means my own test for that fix was passing by luck: mtp-DeepSeek-V4-Flash-0731-Q8_0.gguf happens to sort ahead of mtp-DeepSeek-V4-Flash-Q8_0.gguf because 0 precedes Q. Your counterexample does not:
model_v2-Q4_K_M.gguf + mtp-model.gguf + mtp-model_v2-Q8_0.gguf
picked: mtp-model.gguf (want mtp-model_v2-Q8_0.gguf)
Fixed in b7dc1c3: the root branch now collects every name-and-family match across both scanned directories, sorts by _drafter_stem_rank, and only then runs the file / _launchable / accept checks in that order. The sort is stable, so equal specificity keeps the previous directory order and nothing else about root preference moves.
Two tests, both failing before the change: the in-folder case above, and the cross-directory one you raised, where the base sits beside the weight and the exact match only in search_root.
detect_dspark_file was already safe here since it collects into one list and ranks with _rank, which carries the same key.
…round validation like the load
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7dc1c377f
ℹ️ 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".
| continue | ||
| if accept is not None and not accept(launch): | ||
| root_candidates.append(f) | ||
| for f in sorted(root_candidates, key = lambda c: _drafter_stem_rank(c.name, kind = "mtp")): |
There was a problem hiding this comment.
Rank specificity before preferring root MTP copies
In a multi-model directory where mtp-model.gguf is at the scan root but the matching MTP/mtp-model_v2-Q8_0.gguf is in the companion subdirectory beside model_v2-Q4_K_M.gguf, this loop still returns the less-specific root drafter before subdirectory candidates are even collected. Fresh evidence beyond the earlier root-to-root report is this cross-tier case: family specificity is only applied within each layout, so collect or compare both tiers before returning while retaining root preference only for equally specific families.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and my previous fix only closed the within-tier half:
model_v2-Q4_K_M.gguf + mtp-model.gguf + MTP/mtp-model_v2-Q8_0.gguf
picked: mtp-model.gguf (want mtp-model_v2-Q8_0.gguf)
The root loop returned before the companion directory was ever scanned.
Fixed in cfe9737. Both tiers are now collected first, each keeps its own internal ordering (root by specificity then scan order, subdir by _smallest_first), and the tier order is decided by the better specificity of the two:
order = (
(_emit_subdir, _emit_root)
if _best_rank(subdir_candidates) < _best_rank(root_candidates)
else (_emit_root, _emit_subdir)
)_best_rank defaults to 0, the worst score, so an empty tier never wins. Root therefore keeps its preference at equal specificity, which is every published layout, and loses only where the root file names a different family and so is not this weight's drafter at all. accept still falls through to the second tier, so a caller with extra rules keeps scanning.
Two tests: the cross-tier case above, and a negative control that mtp-model.gguf still beats MTP/model-Q8_0-MTP.gguf for model-Q4_K_M.gguf. 655 tests pass across the detection, picker, offline-cache and resolver suites.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfe97370b0
ℹ️ 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 root file names a different family and is not this weight's drafter. | ||
| order = ( | ||
| (_emit_subdir, _emit_root) | ||
| if _best_rank(subdir_candidates) < _best_rank(root_candidates) |
There was a problem hiding this comment.
Rank only launchable MTP candidates across tiers
When the root contains a dangling or incomplete release-specific candidate plus a usable base-family candidate, _best_rank(root_candidates) still uses the unusable candidate to put the root tier first; _emit_root then skips that candidate and returns the base-family drafter before checking a more-specific usable copy under MTP/. For example, beside model_v2_release-*.gguf, a broken mtp-model_v2_release.gguf, usable mtp-model.gguf, and usable MTP/mtp-model_v2-Q8_0.gguf select mtp-model.gguf. Filter root candidates for launchability before comparing tier ranks, or compare the first actually emittable candidate from each tier.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced exactly as described:
model_v2_release-Q4_K_M.gguf
mtp-model_v2_release.gguf dangling link, most specific
mtp-model.gguf usable, least specific
MTP/mtp-model_v2-Q8_0.gguf usable, more specific
picked: mtp-model.gguf (want mtp-model_v2-Q8_0.gguf)
The broken candidate spoke for the root tier in the comparison and was then skipped at emission.
Fixed in 23cb2c2 by taking your first option: root candidates are filtered for is_file() and _launchable() at collection, so only launchable files reach _best_rank or the emit loop. That also makes the two tiers symmetric, since the subdir tier has always filtered at collection. The now-redundant check inside _emit_root is gone; the try/except OSError around _drafter_launch_path stays, for a file that disappears between collection and emission.
accept is deliberately not part of the comparison: it is caller-specific, a rejection is meant to keep scanning, and if it rejects everything in the chosen tier the other tier is still tried.
test_an_unusable_candidate_does_not_win_the_tier_comparison pins the case above. 656 tests pass.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23cb2c2364
ℹ️ 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 root file names a different family and is not this weight's drafter. | ||
| order = ( | ||
| (_emit_subdir, _emit_root) | ||
| if _best_rank(subdir_candidates) < _best_rank(root_candidates) |
There was a problem hiding this comment.
Exclude rejected candidates from tier ranking
For a native-grant-backed load, _best_rank still considers candidates that the accept callback will reject. If the root tier contains a most-specific out-of-grant candidate, a less-specific accepted root candidate, and MTP/ contains an accepted candidate of intermediate specificity, line 1930 chooses the root tier based on the rejected file; _emit_root then skips that file and returns the base-family drafter without considering the more-specific accepted subdirectory copy. Rank the first acceptable candidate in each tier, just as this change now filters unlaunchable candidates before comparing tiers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
You are right and I was wrong to rule this out last round. I argued accept should stay out of the comparison because a rejection keeps scanning; that is true within a tier but does not save the tier comparison, which is exactly the failure you describe. Reproduced:
model_v2_release-Q4_K_M.gguf
mtp-model_v2_release.gguf rejected by accept, most specific
mtp-model.gguf accepted, least specific
MTP/mtp-model_v2-Q8_0.gguf accepted, more specific
picked: mtp-model.gguf (want mtp-model_v2-Q8_0.gguf)
Fixed in 0472c51 by taking your second option, which subsumes the launchability filter as well: each tier is now represented by the first candidate that survives every filter, i.e. the one it would really launch.
def _first_pick(candidates: list[Path]) -> Optional[tuple[int, str]]:
for c in candidates:
try:
launch = _drafter_launch_path(c)
except OSError:
continue
if accept is not None and not accept(launch):
continue
return _drafter_stem_rank(c.name, kind = "mtp"), launch
return NoneRanks are then compared between those two picks, with root still winning ties. This also removes the _emit_root / _emit_subdir / _best_rank trio in favour of one helper, so there is a single place where "what would this tier launch" is decided.
Three cases verified against the same tree: the accept skew above, the dangling-link skew from the previous round, and the negative control that mtp-model.gguf still beats MTP/model-Q8_0-MTP.gguf at equal specificity. 734 tests pass.
|
@codex review |
|
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". |
Follow-up to #7968. Three drafter-detection bugs found while reviewing that PR after it merged, each with a regression test that fails without its fix.
detect_dspark_fileaccepted a sidecar it cannot openIt never checked that the candidate is a readable file, where
detect_mtp_filealways has. Two shapes reach it:llama-server then gets a
--model-draftit cannot open, which fails the whole load rather than falling back to no speculative decoding. Now guarded withlaunch.is_file(), which follows the link and so covers both.A base-family sidecar attached to a longer-named sibling's weights
_drafter_matches_weightrequires the drafter's family to prefix the weight at a non-alphanumeric boundary. That blocks one direction of aDeepSeek-V4-Flash/DeepSeek-V4-Flash-0731pair but not the other:Both are real Hub filenames, and
ggml-org/DeepSeek-V4-Flash-GGUFandggml-org/DeepSeek-V4-Flash-0731-GGUFare flat repos, so one scan folder for both hits it.The prefix rule cannot be tightened to equality:
unsloth/gemma-4-12B-it-qat-GGUFreally does shipmtp-gemma-4-12B-it.ggufbesidegemma-4-12B-it-qat-*.gguf. So the remaining direction is settled by ranking instead, with a new_drafter_stem_rankputting the longest matching family first in both detectors. The qat pairing has its own negative-control test.The deletion predicates never saw the directory
_repo_file_matchespassedfile_name, which huggingface_hub sets tofile_path.nameand our own recovery scan toentry.name. Both are basenames, sodspark/andMTP/were invisible to every predicate keyed on the parent directory.Harmless for
dspark-<model>.gguf, whose basename carries the marker. Not harmless for the other published scheme,<model>-dspark.gguf: its basename looks like an ordinaryQ8_0quant, so deleting the genuineQ8_0variant also unlinked the sidecar theQ4_K_Mstill needed, and_has_remaining_main_ggufnever went false, so no companion could ever be reclaimed._repo_file_matchesnow rebuilds the snapshot-relative path. Quant labels are unchanged by the prefix (extract_quant_labelreturnsUD-Q4_K_XLeither way), so only the directory-keyed answers move.The test fixture was also passing relative paths as
file_name, which is why this never showed up; it now mirrors production and the new test fails without the fix (Deleted 2 file(s) ... variant Q8_0).Testing
727 backend tests pass across the detection, deletion, picker, offline-cache and training-guard suites. Each fix was confirmed to fail its test when reverted.