Repository navigation
Studio: resolve the repo-root MTP drafter after the MTP/ GGUF rename - #7031
Conversation
The Gemma 4 QAT GGUF repos renamed the higher-precision MTP/ subdir copies from gemma-4-...-<quant>-MTP.gguf to mtp-gemma-4-...-<quant>.gguf, so their basenames now start with the same mtp- prefix as the small repo-root drafter (mtp-gemma-4-E4B-it.gguf). The drafter selectors filtered candidates by a mtp- basename prefix and took the first in sort order. With the new names the MTP/ copies also match, and because MTP/ (uppercase) sorts before the lowercase root file, selection flipped to the large BF16 copy under MTP/ instead of the root drafter both functions document they should pick. Restrict both selectors, and the companion byte estimate, to root-level mtp-*.gguf so the MTP/ copies stay explicit-selection only: - core/inference/llama_cpp.py _pick_mtp (loader auto-download) - hub/utils/gguf_plan.py preferred_mtp_sibling (Hub variant plans) - routes/inference.py _remote_gguf_companion_bytes (VRAM headroom) Also reuse a drafter already in the local cache before downloading, so a device that already holds a copy on disk does not re-fetch it. Old-scheme names keep working (they have no root-level mtp- sibling to mis-select). Adds regression tests for the new naming, both selection paths, and the on-disk reuse.
There was a problem hiding this comment.
Code Review
This pull request updates the MTP drafter resolution and download logic to ensure that the small repo-root drafter is preferred over the higher-precision subdirectory copies under MTP/ (which now share the mtp- prefix). It also introduces local cache reuse via _cached_repo_mtp_drafter to avoid unnecessary re-downloads. The review feedback correctly identifies a platform-compatibility issue on Windows, where path checks using only forward slashes (/) will fail to detect subdirectory files, and provides a code suggestion to handle backslashes as well.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if not drafters: | ||
| continue | ||
| root = sorted(f for f in drafters if "/" not in f) | ||
| chosen = snap / (root[0] if root else sorted(drafters)[0]) |
There was a problem hiding this comment.
On Windows, local paths returned by scanning the HF cache directory may contain backslashes (\) instead of forward slashes (/). Using only '"/" not in f' to identify root-level files will fail on Windows, causing subdirectory files (like MTP\mtp-...) to be incorrectly classified as root-level files. Since uppercase 'M' sorts before lowercase 'm', this would cause the larger subdirectory drafter to be selected over the root drafter on Windows, defeating the purpose of this fix. To ensure platform independence, check for both forward and backward slashes.
| chosen = snap / (root[0] if root else sorted(drafters)[0]) | |
| root = sorted(f for f in drafters if "/" not in f and "\\" not in f) |
There was a problem hiding this comment.
The candidate paths here come from _gguf_snapshot_files, which returns Path.relative_to(snapshot).as_posix(), so they use forward slashes on every OS including Windows; the online path likewise consumes list_repo_files, whose repo-relative paths are always posix. So a backslash-separated MTP\... can never reach this filter and the '/' check is sufficient. Verified by seeding an MTP/ copy in a snapshot: the returned path is MTP/mtp-...gguf (no backslash) and is correctly excluded.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 400cdb9e74
ℹ️ 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".
| cached = self._cached_repo_mtp_drafter(hf_repo) | ||
| if cached: | ||
| logger.info(f"Reusing cached MTP drafter: {cached}") | ||
| return cached |
There was a problem hiding this comment.
Avoid reusing stale cached MTP drafters online
Because this cache probe runs before _download_companion_gguf, online loads return the first cached drafter from any HF snapshot and never let hf_hub_download check the current revision/etag. If a Gemma GGUF repo updates mtp-gemma-...gguf under the same filename, _download_gguf can fetch the new main weights while this path keeps pairing them with a stale cached draft (or old MTP/ copy), which can make llama-server load an incompatible drafter; limit this reuse to offline mode or verify the cached file is from the current revision.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5aec80f: the cache-reuse probe is now gated to offline mode. Online loads go back through _download_companion_gguf/hf_hub_download, which resolves the current revision and refetches the drafter when its etag changed, so freshly downloaded weights are never paired with a stale cached draft. This matches the offline-only cross-snapshot reuse already used for the main GGUF in _download_gguf.
Reuse the cached drafter only when HF is offline. Online, route back through _download_companion_gguf/hf_hub_download so the current revision is checked (etag) and a changed drafter is refetched, matching the offline-only cross-snapshot reuse already used for the main GGUF. This avoids pairing freshly downloaded weights with a stale cached draft. Make the reuse tests offline and add an online-skips-reuse test.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5aec80f476
ℹ️ 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".
| root = sorted(f for f in drafters if "/" not in f) | ||
| chosen = snap / (root[0] if root else sorted(drafters)[0]) |
There was a problem hiding this comment.
Prefer root drafters across cached snapshots
When HF_HUB_OFFLINE is set and the HF cache has multiple snapshots, this chooses the first snapshot that contains any drafter and only prefers the root mtp-*.gguf within that single snapshot. If a newer partial/pre-fix snapshot contains only MTP/mtp-...-BF16.gguf while an older complete snapshot still has the small repo-root drafter, offline loads will return the large MTP/ copy, reintroducing the VRAM/download regression this change is trying to avoid. Scan all snapshots for root drafters before falling back to subdir copies.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5fd0d3b: _cached_repo_mtp_drafter now collects drafters across all cached snapshots and prefers any repo-root mtp-*.gguf before falling back to an MTP/ copy, so a partial newer snapshot can no longer shadow the small root drafter in an older one. Added test_download_mtp_prefers_root_across_snapshots_offline to pin it.
Offline reuse scanned snapshots one at a time and returned the first snapshot that held any drafter, only preferring root within it. A newer partial snapshot with just the MTP/ copy could shadow the small root drafter in an older snapshot. Collect drafters across all snapshots and prefer any repo-root file before an MTP/ copy.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fd0d3b806
ℹ️ 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".
| (roots if "/" not in f else subdirs).append(snap / f) | ||
| # Root before any MTP/ copy, across every snapshot, so a partial newer | ||
| # snapshot can't shadow the small root drafter in an older one. | ||
| for cand in sorted(roots) + sorted(subdirs): |
There was a problem hiding this comment.
Preserve HF snapshot order for cached drafters
When offline cache contains multiple snapshots for the same repo and more than one has a root mtp-*.gguf, this sorts the absolute snapshot paths and can pick an older drafter even though utils.models.model_config._iter_hf_cache_snapshots deliberately yields snapshots newest-first and _download_gguf resolves the main model from that order. In that situation the load can pair a newer cached main GGUF with a stale MTP drafter from another revision; keep the collected root candidates in snapshot order while still preferring roots over MTP/ copies.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fcf3360: the cross-snapshot collection now preserves _iter_hf_cache_snapshots newest-first order (root still preferred over MTP/ copies) instead of sorting by snapshot path, so the reused drafter comes from the same newest snapshot the main GGUF is resolved from. Added test_download_mtp_reuse_follows_snapshot_order_offline.
Collecting root candidates and sorting by absolute snapshot path could pick a drafter from an older snapshot. _iter_hf_cache_snapshots yields newest first and the main GGUF is resolved in that order, so preserve it (root still preferred over MTP/ copies) to avoid pairing a fresh main weight with a stale drafter revision.
|
@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". |
Summary
The Gemma 4 QAT mobile GGUF repos renamed the higher-precision MTP drafter copies under
MTP/:MTP/gemma-4-E4B-it-BF16-MTP.ggufMTP/mtp-gemma-4-E4B-it-BF16.ggufMTP/gemma-4-E4B-it-Q8_0-MTP.ggufMTP/mtp-gemma-4-E4B-it-Q8_0.ggufThe
-MTPsuffix was dropped and amtp-prefix was added, so theMTP/basenames now begin with the samemtp-prefix as the small repo-root draftermtp-gemma-4-E4B-it.gguf(unchanged).The problem
The drafter selectors filter candidates by a
mtp-basename prefix and take the first in sort order. Under the new names everyMTP/copy also matches that filter, and becauseMTP/(uppercaseM) sorts ahead of the lowercase rootmtp-..., selection flips to the largest copy,MTP/mtp-gemma-4-E4B-it-BF16.gguf(about 172 MB), instead of the root drafter (about 60 MB) that both functions document they should pick.Effect when loading a Gemma 4 quant in Studio: speculative decoding still works and output is unchanged (the target verifies every drafted token), but Studio fetches the larger BF16 copy and reserves more VRAM than intended. On the Hub download path it attaches that copy into
MTP/, where the loader's root-only local detection then cannot find it.The fix
Restrict the drafter selection, and the companion byte estimate, to root-level
mtp-*.ggufso theMTP/copies stay explicit-selection only:core/inference/llama_cpp.py_pick_mtp(loader auto-download)hub/utils/gguf_plan.pypreferred_mtp_sibling(Hub variant plans)routes/inference.py_remote_gguf_companion_bytes(VRAM headroom estimate)Also reuse a drafter already in the local cache before downloading, so a device that already holds a copy on disk (the root file, or an older
MTP/copy from a prior build) is reused rather than re-fetched.Compatibility
Old-scheme repos keep working: their
MTP/...-MTP.ggufcopies have no root-levelmtp-sibling to mis-select, so the root drafter is still chosen. The classification predicates are unchanged, soMTP/copies remain excluded from the main-model and quant menus under both naming schemes.Tests
studio/backend/tests/test_mtp_drafter_companion.py:preferred_mtp_siblingandbuild_gguf_variant_plansasserting the root drafter wins over the newMTP/copies._pick_mtpselection pinned through the companion-download seam.MTP/copy when no root file is present.Adjacent MTP and llama.cpp suites run clean (800 passed alongside; the single unrelated
wait_for_healthhttpx monkeypatch failure reproduces identically onmain).