Repository navigation
Stop a GGUF pick downloading the dense base transformer it never opens - #8232
Conversation
Picking unsloth/Qwen-Image-Edit-2511-GGUF Q6_K fetched the 16.85 GB GGUF and then started a 57.72 GB pull of Qwen/Qwen-Image-Edit-2511, 40.86 GB of which is the dense transformer/ the fast path would denoise with INSTEAD of the GGUF that was just downloaded. The rule this needs already exists one branch above, for the hosted pre-quant checkpoint: an auto quant never downloads a second transformer for a GGUF pick, because a cached shortcut is free and an uncached one costs a whole extra denoiser that leaves the first unused. The base repo's own transformer/ shards are the same purchase and were not covered. So decline the same way when the base shards are not already on disk, in the prefetch and in the loader alike. Nothing else moves: an explicit transformer_quant is opting in and still buys the dense build, a LoRA bake still needs it, and a user who already has the dense base still gets the fast path for free. The loader half also closes a hole of its own. _transformer_prefetched is False exactly when the plan left the shards out, and the dense path would then have pulled them with from_pretrained() under the load lock, after the previous pipeline was evicted, where unload cannot preempt it and progress has already reported 100%.
# Conflicts: # studio/backend/core/inference/diffusion.py
|
Two measurements from testing a related report on 1. The defect is family-specific in a way worth stating, and Same
2. The load-side decline also turns off the CACHED pre-quant fast path, which I do not think is intended.
Measured, same cache root, The user who deliberately downloaded the pre-quant loses the build they downloaded it for, and the badge loses its explanation too: the new branch sets The description promises "a user who already has the dense base cached still gets the fast path, for free, exactly as before", and this is the same promise applied to the pre-quant. Gating the new decline on the pre-quant verdict being absent would keep it, something like only declining when Separately, the label the user sees is wrong on both paths regardless of which way this lands: the Loaded models row reads |
…shards The load-side decline added here fired whenever the prefetch staged no transformer/ shards. That is the right verdict when the fast path's candidate is the dense base, which is the case this branch exists to fix. It is the wrong one when a hosted pre-quant checkpoint is already cached: that stages no shards either, because the small quantised checkpoint replaces them, not because a download was refused. Measured on a warm cache, unsloth/Z-Image-Turbo-GGUF at Q8_0 with unsloth/Z-Image-Turbo-FP8 on disk, loaded the GGUF instead of the fp8 checkpoint that main loads for free. Ask the resolver that actually picks between the two rather than reading an empty stage as a decline: resolve_dense_quant_candidate is the same call the download plan and the memory re-plan already use, so the plan and the load stay on one answer. A None candidate stays 'dense', which is what the plan does too. The branch above is untouched, so an uncached pre-quant is still declined.
|
Confirmed and fixed on the branch. The decline was reading an empty
Measured, warm cache, which is what main does for that pick. The original fix is unaffected. Three tests fail before this change and pass after, plus three more pinning the resolver's no-answer, error and uncached-prequant verdicts. 11 mutants, each caught by its named test, suite green after restoring. Full The PR body's "exactly as before" sentence was wrong as written and now separates the two kinds of "already on disk". |
…will use A byte count above zero says a transformer download STARTED, not that it finished, so one shard left by a cancelled pull read as a cache hit and widened the prefetch into the rest of it. And a gated base and its ungated mirror are two independently addressed caches, so shards resident under the upstream id spared nothing once the companion listing sent the fetch to the mirror. Both ended in the multi-gigabyte second denoiser the branch exists to prevent. The estimate now defers the widening to a callable and hands it the base repo's own listing, split either side of transformer/. That is the one place both facts are knowable: the companions decide which repo is fetched, and the shard names say whether that repo holds all of them. Also: a complete local base directory counts as staged (nothing can be downloaded from a path, and its empty Hub listing is not a refusal), and the resolver's free-disk gate no longer hides a cached pre-quant, which downloads nothing and so is not what that gate is sized for.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02b77383e1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return False | ||
| try: | ||
| fetch_repo = prefer_ungated_mirror(base, files = companion_files) | ||
| return cache_holds_files(fetch_repo, transformer_files) |
There was a problem hiding this comment.
Require current-revision cache hits before widening
When a base repo is republished with the same transformer filenames, a machine that cached the old dense transformer still has every transformer_files path under its local refs/main; this verdict only checks names and is not tied to the model_info SHA that _estimate_download_bytes() just read. The fresh evidence is that the new helper introduced here passes only transformer_files, so _dense_transformer_cached() can return true for a stale revision, _estimate_download_bytes() widens the prefetch, and hf_hub_download then resolves current main and downloads the entire dense transformer again—the second-denoiser download this change is meant to avoid. Thread the current revision/etag into this cache check before widening, as the download-plan cache dropping code does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting, on how the cache actually stores a revision. Blobs are content addressed by etag and snapshots are symlinks into them, so a repo republished with the transformer UNCHANGED gives the new revision the same etags and hf_hub_download re-links the existing blobs without moving a byte. And if the shards genuinely changed, the new etags are the point: downloading them is the load doing what the user asked, not a second denoiser. Either way there is no spurious multi-gigabyte pull for the revision check to prevent. See https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache on the blobs/snapshots/refs layout.
Pinning the probe to the SHA model_info just read would also cost more than it saves. Base repos pick up README and config commits regularly, so a great many users sit one metadata commit behind with every shard already on disk; a SHA-exact check finds no snapshot directory for the current commit and declines the fast path for all of them. That is a common case traded for a corner. The download-plan cache-dropping code is revision exact for a different reason, since it decides which individual files to skip fetching, where being wrong costs correctness rather than speed.
|
Before/after from two isolated Studio installs, merge base The GGUF itself is downloaded on both sides, identical. The item under it is the companion base repo, and that is the whole difference: The plan the panel is drawing:
The 11 shards are the dense transformer the GGUF replaces, so the loader never opened a byte of them. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02b77383e1
ℹ️ 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 False | ||
| try: | ||
| transformer = Path(base).expanduser() / "transformer" | ||
| return transformer.is_dir() and any(transformer.glob("*.safetensors")) |
There was a problem hiding this comment.
Recognize bin-only local transformer checkpoints
When a valid local Diffusers base stores its transformer as diffusion_pytorch_model.bin, this safetensors-only predicate returns false, so _run_load marks the transformer unstaged and an automatic dense quant unnecessarily falls back to the GGUF even though no second download is possible. The fresh evidence beyond the earlier local-base report is the supported bin-only checkpoint format; accept the weight formats that from_pretrained supports rather than requiring *.safetensors.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting, because admitting a .bin-only transformer here makes the outcome worse rather than better. The fit re-check downstream is _dense_transformer_resident_bytes, which reads safetensors headers and returns 0 for a .bin-only transformer, and its own docstring spells out the consequence: a base whose shards it misses skips the fit check entirely and lets the dense build OOM under a plan sized for the GGUF. Reading .bin as staged would walk straight into that. Declining costs the GGUF load, which is the safe side, and the whole preflight is already safetensors-only by construction.
| transformer_files = tuple( | ||
| f | ||
| for f in kept | ||
| if f not in skip and _base_file_downloaded(f, include_transformer = True) | ||
| ) |
There was a problem hiding this comment.
Exclude redundant weight formats from the cache requirement
When a transformer directory publishes both safetensors and .bin weights, this list includes both formats even though Diffusers prefers safetensors (as the pipeline branch above already accounts for). A cache containing the complete safetensors checkpoint but not the unused .bin copy therefore fails _dense_transformer_cached, causing automatic quantization to be disabled despite all weights the dense loader would open already being resident; filter the listing to the format that from_pretrained will select before requiring every file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting. The requirement is exactly the list _prefetch_files stages: base_files comes from _base_file_downloaded, which admits everything under transformer/ including a .bin twin, so the plan and the check cannot disagree about what has to be there. Where they part is a cache filled by from_pretrained rather than by this prefetch, and there the check is strict by a file the fetch would have taken anyway. That reads as not-cached, which declines the fast path and loads the GGUF, and costing speed on an unreadable or partial cache is the documented behaviour of this probe, not a defect in it. It also does not arise on the repos this is for, which ship safetensors only.
…r-rung retry - An explicit Speed=off rewrites an auto request to 'off' and the plan stages no transformer/ on purpose, but the auto-decline block still ran and reported the deliberate bit-exact GGUF as a quant declined for want of shards, in the status payload and in the log. The block is gated on a scheme still being enabled. - Auto's winner having no hosted pre-quant does not mean there is none to open: fp8 winning while only an int8 checkpoint is published is what the lower-rung retry exists for, and declining on the winner alone skipped past it to the GGUF for a checkpoint already on disk. The retry only ever returns a cached rung, so consulting it here costs nothing. - The cache probe reads both roots. _prefetch_files resolves each file through whichever root holds it, so a snapshot left behind by a cache-folder change satisfies the pull without moving a byte, and reading the live root alone declined the fast path for a base entirely on disk.
# Conflicts: # studio/backend/tests/test_diffusion_backend.py
# Conflicts: # studio/backend/core/inference/diffusion.py # studio/backend/tests/test_diffusion_backend.py
…oad request speak for itself Counting the import-time root was wrong, and I had it backwards last round. _prefetch_files would indeed not re-fetch from it, but the prefetch is not what this verdict unlocks: the dense fast path calls from_pretrained pinned to hub_cache_dir(), cannot see the other root, and would download the whole transformer again after eviction. That is the outcome the check exists to prevent, so the probe reads the live root only. And balanced, low_vram and the legacy cpu_offload flag name their policy outright, so the plan omits transformer/ because the dense build is skipped rather than for want of cached bytes. The auto-decline block skips those requests instead of reporting a second-denoiser refusal for them.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b30bfc34d9
ℹ️ 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".
| elif ( | ||
| not _transformer_prefetched | ||
| and not _dense_candidate_is_prequant( |
There was a problem hiding this comment.
Preserve the capacity-gate decline reason
When the dense transformer is fully cached but steady_total_mib exceeds the device budget, _dense_quant_prefetch_needed deliberately returns false at its capacity gate, so this branch interprets _transformer_prefetched=False as missing shards and reports that Auto refused a second download. No download was needed in this case—the quantized build simply cannot fit—and this early decline bypasses the later memory-fit logic that constructs the accurate resident-capacity reason. Carry the prefetch decision reason through or exclude capacity-gated requests before assigning the unstaged-shards explanation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The capacity gate and the unstaged-shards branch reach the same outcome -- the elif still requires _auto_prequant_retry_scheme to return None, so no cached lower rung is skipped, and the load ends on the GGUF either way. What differs is only the explanation string on an Auto: OFF badge, which is below the bar for a code change here.
…gate _dense_transformer_cached judged prefer_ungated_mirror on the companions alone, but _predownload_base hands it companions PLUS the transformer shards, and the upstream only wins when its cache satisfies the whole set. Companions cached under a gated upstream beside a dense transformer cached under the ungated mirror therefore kept the upstream, found no shards there and declined the fast path for weights already on disk one repo over. Pass the same widened list the fetch passes. download_plan called _dense_quant_prefetch_needed eagerly, before the base listing exists, so the cache probe inside it saw no transformer shards and always declined. The plan then scoped narrower than the load it describes, the registry reported scope_file_mismatch and the plan could not adopt the load's own in-flight job for the same base. Pass the callable _run_load passes, so both paths derive the scope from the same listing.
The unsupported-device checks above the decline run for an EXPLICIT scheme only, so on CPU/MPS, non-bf16 CUDA, a stubbed torchao runtime or a family this GPU rules out, an AUTO request reached the new unstaged-shards branch and the badge told the user the base transformer/ shards were not staged. True and irrelevant: caching them cannot enable a quant the host cannot run. The load is unchanged either way (the dense re-plan is already gated on dense_transformer_supported), so this is only about the reason, on the commonest path there is.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2615c73305
ℹ️ 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 False | ||
| try: | ||
| transformer = Path(base).expanduser() / "transformer" | ||
| return transformer.is_dir() and any(transformer.glob("*.safetensors")) |
There was a problem hiding this comment.
Require all local transformer shards before enabling dense load
When a local GGUF base contains only one leftover shard from an interrupted dense-model copy, this any(...) check marks the entire transformer as staged. The auto path can then size only the shards that happen to exist and attempt from_pretrained on the incomplete dense transformer instead of declining immediately to the selected GGUF, potentially doing substantial CPU loading under an understated memory plan before failing back. A local base remains usable for a GGUF even when its unused transformer directory is partial, so verify the shard index/complete monolithic checkpoint rather than treating one safetensors file as completeness.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting: this is hardening against a corrupted local directory, not a reachable defect. _local_base_transformer_present answers 'is this local base's transformer/ on disk', and the premise it states is that nothing can be downloaded from a directory, so a complete one is staged by definition. Getting a half-copied transformer/ there means an interrupted manual copy of a diffusers repo, which is not well-formed input, and the consequence is a loud from_pretrained error on the dense fallback rather than a wrong result or lost data (the memory plan comes from the family table, not the file list, so it is not understated either). A partial local base breaks a great deal more than this path, and index verification here would only move where it surfaces.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |

The bug
Pick
unsloth/Qwen-Image-Edit-2511-GGUFatQ6_K. Studio fetches the 16.85 GB GGUF you asked for, and then starts a 57.72 GB download ofQwen/Qwen-Image-Edit-2511. 40.86 GB of that second download is the densetransformer/, which the fast path then denoises with instead of the GGUF. So you pay for the quant you picked and for a full-precision denoiser you did not, and only the second one runs.The download plan, on current
main, with an empty cache:After this change:
The remaining 16.86 GB is the text encoder, VAE, tokenizer and configs. Those are genuinely required and stay.
Why this shape of fix
The rule already exists, one branch above, for the hosted pre-quant checkpoint:
The base repo's own
transformer/shards are the same purchase, and were not covered by it. This extends that rule to them rather than inventing a new one: when the pick is a GGUF, the scheme was left to us, nothing is being baked, and the dense shards are not already on disk, decline and keep the GGUF.Both halves move together, because the plan and the loader have to agree:
_dense_quant_prefetch_neededdeclines, so the shards are never staged;load_pipelinedeclines on the same verdict, carried as_transformer_prefetched. That half closes a hole of its own:_transformer_prefetchedis False exactly when the plan left the shards out, and the dense path would then have pulled them withfrom_pretrained(subfolder = "transformer")under the load lock, after the previous pipeline was evicted, where unload cannot preempt it and progress has already reported 100%.What "already on disk" means, because there are two of them
An explicit
transformer_quantis opting in to the dense build and still buys it. A LoRA bake still needs it. The mirror is checked alongside the vendor id, so a gated base staged under the unsloth copy is not misread as uncached.Beyond that, two different things can already be on disk, and only one of them is the dense base. Both keep the fast path, for free, exactly as before, but they are not the same test:
transformer/shards are cached._dense_transformer_cachedanswers that, the plan then stages them, and_transformer_prefetchedis True at the load.transformer/shards at all, because the small quantised checkpoint replaces them rather than a download being refused.The second one is why the load side does not read an empty stage as a verdict on its own.
_transformer_prefetchedis False in both cases, for opposite reasons, soload_pipelineasksresolve_dense_quant_candidatewhich of the two the fast path would actually open, and declines only when the answer is the dense base. That is the same resolver the download plan and the memory re-plan already use, so the plan and the load stay on one answer.Measured on a warm cache,
unsloth/Z-Image-Turbo-GGUFatQ8_0withunsloth/Z-Image-Turbo-FP8already cached:which is what
maindoes for that pick, unchanged.The trade-off, which is the part worth arguing with
On a machine with room, an auto GGUF pick used to end up on
dense bf16 + torchao, which the code says beats GGUF per-matmul dequant on speed and quality. After this it will run the GGUF unless the dense base, or a pre-quant checkpoint, is already cached. That is deliberate: 40.86 GB of unrequested download is a worse surprise than a slower denoise, and it is the same call the pre-quant branch already makes. If you would rather keep the upgrade and instead surface the cost up front, say so and I will invert it.Verification
Reproduction and fix both measured against live Hub metadata, no weights downloaded, except the Z-Image case above which was loaded for real to read the resident tensors. Byte totals are from
DiffusionBackend.download_planwith an isolated cache root.The same
Qwen-Image-Edit-2511pick atBF16shows the size independently: 98.59 GB staged before, 57.73 GB after.Tests: 11 added,
studio/backend/tests/test_diffusion_backend.py216 -> 227. Three existing tests in the "an auto quant never buys a second denoiser" section stub the new cache verdict explicitly, since they are about the pre-quant rule and not this one. One failure in that file,test_load_refines_component_placement_after_text_encoder_quantization, is present onmainunchanged and is not from this branch.Mutation tested, 11 mutants, each caught by the named test, suite green after restoring, run on a
git archive HEADcopy rather than the worktree:test_auto_quant_declines_an_uncached_dense_base_dense_transformer_cachedignores the mirrortest_dense_transformer_cached_reads_the_mirror_tootest_dense_transformer_cached_survives_an_unreadable_cachetest_an_explicit_transformer_quant_still_buys_the_dense_basetest_an_unstaged_transformer_still_takes_a_CACHED_prequanttest_the_load_declines_when_the_prefetch_skipped_the_dense_shardstest_a_resolver_with_no_answer_reads_as_the_dense_basetest_a_raising_resolver_reads_as_the_dense_basetest_an_uncached_prequant_still_declines_before_the_candidate_is_askedtest_an_unstaged_prequant_load_still_forbids_the_dense_fallbacktest_the_plan_and_the_load_agree_on_a_cached_prequantFull
studio/backend/tests, run with--continue-on-collection-errors: the sorted FAILED/ERROR line set is identical before and after this branch's changes.