Skip to content

advertise a diffusion GGUF pick's base companions in the picker - #8289

Closed
mahiatlinux wants to merge 31 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-diffusion-pick-size
Closed

mahiatlinux wants to merge 31 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-diffusion-pick-size

Conversation

@mahiatlinux

Copy link
Copy Markdown
Contributor

Closes #8234.

The bug

A quant row is sized from the GGUF repo alone. The base repo the load cannot run without is never
named, so the number the user agrees to and the number that lands on disk differ by the whole text
encoder.

unsloth/Qwen-Image-Edit-2511-GGUF, BF16:

qwen-image-edit-2511-BF16.gguf                        40.87 GB   <- what the row said
Qwen/Qwen-Image-Edit-2511, 26 companion files         16.86 GB   <- not advertised, and required
TOTAL                                                 57.73 GB

The gap scales the wrong way. At Q2_K (7.47 GB) the unadvertised companions are more than twice
the advertised number, so the rows also compare wrongly against each other.

The total was already computed, one call before any byte moves: loadOrStage fetches
/images/download-plan at pick time and hands its entries straight to the download manager. It was
simply never shown.

What changes

companion_bytes on the plan response, derived. DiffusionDownloadPlanResponse gains the
share of total_bytes that is not the picked checkpoint. A model_validator derives it from the
entries rather than each planner computing its own, so the three that build this shape
(DiffusionBackend, SdCppBackend, VideoBackend) cannot disagree, and a carried value can never
drift from the rows the Downloads panel lists. Both /images/download-plan and
/video/download-plan return this model, so one field covers both pages and no new route appears.

Counted per file, not per repo. Entries carry gguf_bytes: of an entry's bytes, the picked
checkpoint's own share. They differ whenever companions live in the picked repo, which is not
hypothetical: an LTX-2.3 pick reads its VAEs and text projections out of the same
unsloth/LTX-2.3-GGUF entry as the checkpoint (LTX23_EXTRAS_REPO), and charging that whole entry
to the checkpoint would advertise 3.5 GB of companions as free.

The row adds it. ModelSelector takes an optional resolveCompanionBytes, provided through a
context so the eight GgufVariantExpander call sites are untouched. The Images and Video pages
supply it, built from the same plan and the same Advanced values their staging uses, so a row and
the Downloads panel report one number. Chat supplies none, the hook answers 0, and the LLM picker
is byte-identical. A local path stages nothing, so it is not asked.

The memory verdict does not move. getGgufFit still reads v.size_bytes. It judges what the
denoiser needs resident, and folding a text encoder's disk bytes into it would mark quants OOM that
run fine.

Result

Quantizations
  Q2_K                       24.3 GB
  Q6_K                       33.7 GB
  BF16   recommended         57.7 GB

  Includes 16.9 GB of base assets (text encoder, VAE) that every quantization downloads.

Cache-aware, because it rides the entries and _stage already drops a repo the cache serves whole.
A base on disk yields companion_bytes == 0 and the row falls back to the quant's own size, which
is what the panel would fetch.

Note on #8232

On current main the BF16 row above reads ~98.6 GB rather than 57.73 GB, because a GGUF pick still
stages the dense transformer/. That is honest: it is what main downloads today. #8232 fixes that
separately and the figure drops to 57.73 GB with no change here.

Tests

The companion assertion went into the existing partial-cache and LTX-2.3 plan tests rather than
cloning their fixtures. Added one plan test for the per-file split, one route test that the derived
field survives the response, and one picker test that the row includes companions while the fit
badge does not.

video-download-plan-payload.test.ts is re-anchored on loadOrStage. It sliced from the first
getVideoDownloadPlan in the file, which is now the picker's sizing call, so it would have asserted
about a call that stages nothing.

724 backend tests pass (diffusion, video, sd.cpp, both route modules, gated-base, compat-preflight),
ruff clean, frontend typecheck and full unit suite pass. No GPU paths are touched, so nothing was
skipped for hardware.

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

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

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

A quant row was sized from the GGUF repo alone, so an
unsloth/Qwen-Image-Edit-2511-GGUF BF16 pick advertised 40.87 GB and then
fetched 57.73 GB: the base repo's text encoder, VAE, tokenizer and configs
were never named. The gap scales the wrong way, and at Q2_K (7.47 GB) the
unadvertised companions are more than twice the advertised number.

DiffusionDownloadPlanResponse gains companion_bytes, derived by a validator
from the entries rather than computed in each planner, so DiffusionBackend,
SdCppBackend and VideoBackend cannot disagree and both /images/download-plan
and /video/download-plan carry it. Entries carry gguf_bytes so the split is
per file: an LTX-2.3 pick reads its VAEs and text projections out of the same
unsloth/LTX-2.3-GGUF entry as the checkpoint, and charging that entry to the
checkpoint would advertise 3.5 GB of companions as free.

ModelSelector takes resolveCompanionBytes through a context, so the eight
GgufVariantExpander call sites are untouched. The Images and Video pages
supply it from the same plan and Advanced values their staging uses. Chat
supplies none and the LLM picker is unchanged. getGgufFit still reads
size_bytes: it judges what the denoiser needs resident, and disk bytes would
invent OOM rows.

Cache-aware, since it rides the entries _stage already drops for a warm repo,
so a base on disk leaves the row showing the quant's own size.
Codex was right that a repo's companions are not constant across its quants.
h3_text_encoder_filename pairs a -Q2_ transformer with the Q2 Qwen3-VL encoder
and every other quant with the Q4 one, sd_cpp_text_encoders_for swaps the
FLUX.2-klein 9B encoder for the 4B default, and ltx23_extras_files keys its
VAEs and text projections on the checkpoint variant. One sample answer added to
every row misreported whichever tier it did not come from, by multiple GB.

The picker now sends the filenames it is displaying to a new
/images/companion-sizes and /video/companion-sizes, which plan each candidate
exactly as the load will run it and answer a filename -> bytes map. Only the
first candidate carries the precision check, since that verdict never reads the
filename, and the rest run four at a time so an expander resolves in about the
time one row would. A candidate whose plan fails is omitted rather than
reported as 0, so its row keeps the size it already had.

The sd.cpp and video planners now drop repos the cache already serves whole, as
the diffusers planner does in _stage. Without it the advertised size charged
again for the VAEs and text encoders an earlier quant fetched, and the panel
listed assets the user already had. sd.cpp reads its sizes from model_info
rather than get_paths_info so one call answers both the sizes and the commit a
cache hit has to match.
@mahiatlinux
mahiatlinux force-pushed the fix/studio-diffusion-pick-size branch from f9b1300 to 83dacba Compare August 10, 2026 02:49
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 83dacbafd4

ℹ️ 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 thread studio/backend/core/inference/video.py Resolved
Three follow-ups from review.

_te_prequant_hub_files and _denoiser_prequant_hub_files had info.sha in hand
and discarded it, so their repos never reached the shas map and the new
cached-repo filter could not drop them: _files_already_cached returns no hits
without a revision by design. A pre-cast encoder or pre-quantized denoiser
already on disk stayed in the plan, was charged to the row, and was preflighted
for space it did not need. Both helpers now record the commit through one
_record_plan_sha helper.

The picker keyed a stored answer on the filenames alone. Changing precision or
memory mode hands it a new resolver but the same rows, so the previous
settings' totals kept satisfying the freshness check while the replacement was
in flight, and a click could stage tens of GB the row never advertised. The key
now carries the resolver identity.

Collapsing an expander only suppressed the setState; the request itself ran on.
On the 63-quant LTX repo that leaves the backend planning every candidate
against the Hub for a listing nobody is waiting for. The effect now aborts, and
the signal reaches both companion-sizes routes, matching the variant listing
above it.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 16d2cc0d31

ℹ️ 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 thread studio/backend/routes/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
Two follow-ups from review.

Sizing an expander planned every candidate independently, and each plan listed
the checkpoint repo and the base repo again: about 126 model_info calls for the
63 quants of unsloth/LTX-2.3-GGUF, enough to exhaust the Hub rate limit and
fail the downloads that follow. The semaphore bounded concurrency, never
volume. plan_metadata.shared_plan_metadata scopes one listing per repo to the
batch through a context variable, so the planners keep their signatures and a
caller that does not opt in still goes to the Hub every time. The first
candidate already runs alone, so it warms the listings the rest read.

An unreachable Hub does not raise: the planners answer with an empty
best-effort plan so the load can still fall back to its own inline pull. The
batch recorded that floor as a companion size of 0, which is the endpoint
contract inverted, and the row then advertised the GGUF alone for a pick that
fetches multi-GB companions inline. Plans now carry sizing_failed, set where
each planner swallows the error, and a candidate carrying it is omitted so its
row keeps the size it already had.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 1ad5fdbce4

ℹ️ 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 thread studio/backend/routes/inference.py Resolved
Two follow-ups from review, both on last round's work.

Aborting the fetch closes the client request and nothing else: FastAPI runs the
handler to completion on an ASGI disconnect, so the abort added for the picker
stopped no server-side work at all. Both companion-sizes routes now take the
Request and the batch checks is_disconnected after the semaphore, where a
queued candidate has not started yet. A plan already in flight still finishes;
nothing further is scheduled.

plan_model_info deliberately left failures uncached so one transient miss could
not decide the batch. The cost is that an offline or rate-limiting Hub is
retried once per candidate, which is 63 slow failures for an LTX expander
instead of a prompt answer. Failures are now remembered and re-raised for the
batch: each candidate reports no size, which is what a retry would have reached
anyway. Nothing is remembered outside shared_plan_metadata.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 549cb74a40

ℹ️ 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 thread studio/backend/core/inference/video.py Resolved
Two follow-ups from review.

An LTX-2.3 or MiniMax-H3 checkpoint shares one entry with its companions, and
the cached-repo filter is all-or-nothing, so a second quant of the same family
kept that entry whole for the sake of one missing GGUF and was charged again
for the VAEs, connectors and encoder the first quant had already fetched.
Retained entries keep their whole file list, which the scoped job key is
matched on, but are now sized from _files_missing_from_live_root. That probe is
for sizing only: _files_already_cached still decides what to stage and stays
all-or-nothing, because a set split across the two roots is complete in
neither. A retained entry is pinned to hub_cache_dir(), so the live root is
exactly what it will transfer, and any doubt over-advertises.

Rows also stayed clickable while the sizing batch ran, showing the GGUF-only
number, so a pick made in that window staged the full plan: the advertised
versus downloaded gap this change exists to close. useCompanionBytes now
reports pending, and a row with no size yet shows an ellipsis and cannot be
selected. A downloaded quant costs nothing more and stays clickable throughout.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 033efd4ef9

ℹ️ 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 thread studio/backend/routes/inference.py Resolved
…ing share

Four follow-ups from review.

A row waited on the batch and exempted anything already downloaded. Both were
wrong. downloaded covers the checkpoint alone, so a GGUF fetched from the Hub
page has its companions missing, and loadOrStage skips the plan entirely for an
already-downloaded pick and fetches them inline. The batch can also come back
without a given filename, because a candidate the Hub would not size is omitted
by contract, and the row then read that absence as zero companions. Both now
resolve the same way: a row waits on its own entry in the map, whatever the
batch or the cache says.

_assert_base_repo_accessible called HfApi().model_info directly, outside the
batch cache, so an open base still cost one uncached lookup per row: about 63
redundant probes for an LTX expander. It goes through plan_model_info now, and
its verdict is a property of the repo, not the candidate.

The diffusers planner kept a partially cached base entry whole and summed every
file, so an interrupted pull, or configs another model had already fetched,
were advertised as fresh download bytes. It now sizes from
_files_missing_from_live_root like the sd.cpp and video planners. The
split-root test moves with it: the list stays whole for job adoption, and the
bytes are what the pinned load will actually refetch.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 4ce8d42261

ℹ️ 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 thread studio/backend/core/inference/video.py Resolved
_run_load pre-downloads the checkpoint before _resolve_checkpoint_path can be
reached, so unpinning that one changed nothing on its own, and the LTX-2.3
extras loader had the same gap. Both now reuse the other root.

That makes all six video fetch sites agree with the download plan, which drops
a repo either root serves whole: without it the picker advertised no transfer
after a cache-folder change and the load then pulled the checkpoint or the
extras into the live root anyway.

Pinned with a test over the sources rather than a behavioural one. The defect
has been the same three rounds running, always a call site nobody updated, and
only reading every call catches the next one.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

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

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

Two follow-ups from review.

Candidates plan on worker threads sharing one cache dict, so two racing the
same key both passed the membership check. That duplicated the Hub call, and
once failures became cacheable the loser's error could land on top of the
winner's listing and omit every row that needed it. Each key now has a single
producer through a slot the others wait on, with the event set in a finally so
a producer that dies cannot strand them.

_resolve_checkpoint_path fetched the pre-cast encoder with a bare
hf_hub_download, pinned to one root, while the plan drops that repo when either
root serves it whole. A checkpoint the picker reported as no transfer was then
downloaded again at load. It goes through the shared helper with
reuse_other_cache_root now, like every other fetch the filter judges.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 75221d6eab

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

pre-commit-ci Bot and others added 2 commits August 10, 2026 07:00
_files_already_cached probed the recorded commit alone, so a snapshot fetched
under an explicit revision with no refs/main read as cached. Nothing here can
open that: every resolver, including the denoiser twin's _cached_in_root, goes
through refs/main. The entry was dropped, the picker advertised no transfer,
and the load pulled the multi-GB file inline.

Both probes must now hit. The pinned one is freshness, since a republished repo
leaves refs/main on the superseded blob; the unpinned one is reachability.
Fixed here rather than by threading a revision through each fetch, because the
mismatch is one rule about what "cached" means and every caller wants the same
answer. Erring toward staging costs nothing: hf_hub_download returns the
pointer without a transfer.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 6ef40ce380

ℹ️ 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 +20128 to +20129
resolved = DiffusionDownloadPlanResponse(**plan)
return None if resolved.sizing_failed else resolved.companion_bytes

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 Mark name-guessed LTX plans as incomplete

For an LTX-2.3 GGUF whose repo and filename omit the 2.3/2_3/23b markers, this accepts the video plan as a complete size even though _pick_looks_like_ltx23() classifies it as LTX-2.0 and omits the 2.3 connector, VAE, and vocoder assets. Such renamed checkpoints are supported because the actual loader identifies 2.3 from the GGUF header in is_ltx23_checkpoint(), then downloads those omitted assets inline, so the picker understates the selection by multiple companion files. Inspect the available header while sizing or set sizing_failed when the name heuristic cannot establish the version.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not taking this one. The gap is real but both remedies cost more than it does. Setting sizing_failed when the name cannot establish the version marks every ordinary LTX-2.0 pick unsizable, since 'cannot establish' is the default for any unmarked name, so the common case loses its size to protect a renamed one. Reading the header while sizing means a range request per candidate, which is exactly what _pick_looks_like_ltx23 exists to avoid and what the batch cache work has been removing. The residual is a renamed 2.3 checkpoint understating by its extras, which is the behaviour the plan's own docstring already accepts: under-guessing falls back to the loader pulling them, as it did before this PR. Published unsloth repos carry the marker in every filename.

@danielhanchen

Copy link
Copy Markdown
Member

Reviewed this end to end. The shape is right and the derivation holds up: I could not get the three planners to disagree, and the mirror substitution sizes the repo the fetch actually resolves to. Two things I want to change before this goes in, one of them a real regression, plus a coverage gap on the sd.cpp half.

I merged main and pushed one fix to your branch (c44332a2), so pull before your next push.

1. An unreachable or rate limited Hub makes every quant row permanently unselectable

This is the one blocker. _answer returns None for a sizing_failed plan, so the row is omitted from sizes. useCompanionBytes only removes a name from blocked when it gets a finite number, or when the request itself throws. A 200 carrying an empty map removes nothing, and blocked feeds disabled={unusableLocal || awaitingSize}.

Real planner, Hub down:

$ python3 -c "... DiffusionBackend().download_plan('unsloth/FLUX.1-dev-GGUF', gguf_filename='flux1-dev-Q2_K.gguf', model_kind='gguf')"
{'entries': [{'repo_id': 'unsloth/FLUX.1-dev-GGUF', 'files': ['flux1-dev-Q2_K.gguf'], 'bytes': 0,
              'gguf_filename': 'flux1-dev-Q2_K.gguf', 'gguf_bytes': 0},],
 'total_bytes': 0, 'sizing_failed': True, 'incompatible_reason': None}

Every candidate of that repo answers the same way, so the route replies 200 {"sizes": {}}. Replaying your effect body verbatim against that response:

Hub unreachable  -> blocked: [ 'flux1-dev-Q2_K.gguf', 'flux1-dev-Q4_K_M.gguf', 'flux1-dev-BF16.gguf' ]
request threw    -> blocked: []
Hub answered     -> blocked: []

So on an offline host, or against a Hub that is rate limiting (the 63-quant case plan_metadata.py was written for), the Images and Video pickers stop working entirely: every quant shows a spinner ellipsis and nothing is clickable, including a model that is already fully on disk and would load from cache. On main today that same row shows the GGUF size and loads. Being unable to pick a model is a worse outcome than the understatement this PR removes, and the load path already has its own inline fallback for exactly this case.

The asymmetry is also arbitrary from the user's side: a chunk whose fetch rejects releases its rows, a chunk that succeeds and answers nothing does not, and both mean "the Hub would not tell us".

Minimal change I would make, in companion-bytes.ts:

        try {
          const answered = await resolve(repoId, chunk, controller.signal);
          for (const name of chunk) {
            const value = answered?.get(name);
            if (typeof value === "number" && Number.isFinite(value)) {
              sizes.set(name, value);
            }
            // Answered is answered. A row with no size falls back to the checkpoint figure it
            // showed before any of this, which is what the load will pull from cache anyway;
            // leaving it blocked makes an offline or rate-limited Hub unpickable.
            blocked.delete(name);
          }
        } catch {
          for (const name of chunk) blocked.delete(name);
        }

If you would rather keep the block for a single unplannable row inside an otherwise healthy batch, then release only when the whole chunk came back empty. Either is fine by me. What is not fine is the current state, where the picker can be bricked by a 429.

I did not push this one, since it reverses a policy you documented deliberately in CompanionBytes, and it is your call which of the two shapes you want.

2. The sd.cpp planner half has no regression coverage

I reverted each fix one at a time and ran the tests that claim to guard it. Every backend fix that has a test is genuinely guarded. The gaps are all on one side.

# fix reverted tests run result
F1 _derive_companion_bytes derivation neutered to a self-assign 3 named tests caught, 3 failed
F2 diffusion entry sized from files instead of transferring 2 named tests caught, 2 failed
F3 gguf_bytes no longer zeroed when the checkpoint is cached test_diffusion_backend.py, test_diffusion_routes.py not caught, 393 passed
F4 pre-cast encoder staged with None instead of its commit test_a_cached_precast_encoder_is_not_charged_again caught, 1 failed
F5 _files_already_cached back to the pinned probe alone test_a_commit_pinned_copy_with_no_ref_does_not_count_as_cached caught, 1 failed
F6 _drop_cached_entries re-sizing removed test_a_second_ltx23_quant_is_not_charged_for_the_extras_it_shares caught, 1 failed
F7 video charges the whole shared entry to the checkpoint test_video_backend.py caught, 4 failed
F8 sd.cpp cached-repo drop removed test_sd_cpp_backend.py, test_diffusion_gated_base.py not caught, 116 passed
F9 sizing_failed ignored, the floor reported as the answer test_diffusion_routes.py caught, 1 failed
F10 unloadable head candidate raises instead of passing the baton test_diffusion_routes.py caught, 1 failed
F11 client-disconnect check removed from _one test_diffusion_routes.py caught, 1 failed
F12 plan_model_info batch cache bypassed test_diffusion_routes.py caught, 3 failed
F13 sd.cpp entry sized from names instead of transferring test_sd_cpp_backend.py, test_diffusion_gated_base.py not caught, 116 passed
F14 sd.cpp gguf_bytes set to the whole checkpoint entry test_sd_cpp_backend.py, test_diffusion_gated_base.py not caught, 116 passed
F15 sd.cpp sizing_failed hardcoded to False test_sd_cpp_backend.py not caught, 77 passed
F16 diffusion sizing_failed hardcoded to False test_diffusion_backend.py not caught, 292 passed
F17 sd.cpp companion preflight removed (pre-existing) test_diffusion_gated_base.py caught, 2 failed

F7 needs a note, because it is the pattern I have been burned by twice this week. My first revert of it set gguf_bytes from the running entry total inside add, and all 178 tests passed. It only failed once I reverted it the way the code behaved before the split, charging the whole entry after every file is in. The tests do cover the per-file split, but only against the final value, so a partial regression to it walks through.

The four not-caught rows on sd.cpp are the real gap. SdCppDiffusionBackend.download_plan gained four behaviours here (drop a repo the cache serves whole, size from transferring, split gguf_bytes off the checkpoint entry, set sizing_failed) and all four can be deleted with the sd.cpp and gated-base suites green. sd.cpp is the planner that serves a GGUF pick on a host with no GPU, which is where a wrong row hurts most, and it is one of the three you name in the PR body as unable to disagree. Right now nothing checks that it does not.

F16 matters more than it looks now that finding 1 is on the table: sizing_failed decides whether a row can be clicked at all, and the only thing asserting it is a route test built on a hand-written dict. Nothing checks that a failing _estimate_download_bytes sets it.

F3 I am not worried about. The diffusion checkpoint entry is always a single file, so gguf and gguf in transferring cannot be false while the entry survives _files_already_cached; it reads as defensive rather than uncovered.

3. The frontend tests assert source text, not behaviour

All nine tests in gguf-variant-row-size.test.ts are readFileSync plus includes. They pin the exact spelling of lines like v.size_bytes + (companionBytes.get(v.filename) ?? 0) and disabled={unusableLocal || awaitingSize}, and one asserts the absence of the string Promise.all(. They pass on any file containing those characters and fail on a rename that changes nothing.

I understand why: the test runner is node --experimental-strip-types over tests/**/*.test.ts with no DOM, so a hook cannot be rendered. But the part of this PR with the most logic in it, the chunk loop and the blocked set in useCompanionBytes, is exactly the part with no behavioural test, and finding 1 lives there. Pulling that loop out into a plain async function taking a resolver and returning {sizes, blocked} would make it testable under the existing runner with no new dependency. That is how I reproduced finding 1: the loop lifted verbatim into a standalone script.

4. On the three specific things I set out to check

The derivation. It cannot be overridden. _derive_companion_bytes runs mode="after" on every construction and assigns unconditionally, no planner returns a companion_bytes key, and F1 confirms all three consumers break when it is neutered. Absent or zero total_bytes gives max(0, 0 - 0) == 0, which is right.

One note to save someone a bad afternoon later: this only works because DiffusionDownloadPlanResponse does not set validate_assignment. With it on, an after-validator that assigns to its own model recurses:

$ python3 -c "pydantic 2.13.4 ... model_config={'validate_assignment': True} + a mode='after' validator that assigns"
RecursionError with validate_assignment=True

Nothing mutates total_bytes after construction today, so the field cannot go stale; it is worth one comment saying why the config stays as it is.

The max(0, ...) clamp is doing more work than it looks. Under the F7 revert, sum(gguf_bytes) exceeds total_bytes and the clamp turns a wrong answer into a plausible-looking 0 rather than a visible one. Not worth changing, but it is part of why F7's first revert slipped past.

Cached companions. Correct, and it is the part I most expected to find broken. _stage sizes from _files_missing_from_live_root, _drop_cached_entries re-totals video, and sd.cpp does the same, so an already-cached base gives companion_bytes == 0 rather than over-reporting. Verified by F2, F4, F6 and by test_download_plan_stages_only_what_the_cache_is_missing. Only the sd.cpp side is untested.

Gated-base mirror substitution. Right. fetch_base = prefer_ungated_mirror(...) and the entry is staged under fetch_base with base_rev = self._current_sha(fetch_base) when the mirror differs, so the cache probe and the entry both name the repo the fetch resolves to, at that repo's own commit. test_download_plan_pins_each_probe_to_the_commit_it_just_read covers it.

One residual, a question rather than a finding: the sizes for that entry still come from the vendor listing, {name: file_sizes.get((base, name), 0) for name in base_files}, keyed on base while the entry is fetch_base. That is correct exactly while the mirror is a name-identical copy. A mirror that re-shards would miss every key and size the base at 0, which understates in the same direction as the original bug. Is name identity something we guarantee for unsloth/* mirrors, or is it convention?

5. Test runs

On my merge of main into your head (c44332a2), run from studio/backend, the two suites separately:

tests/                20382 passed, 5 failed, 87 skipped, 15 errors   (944s)
hub/tests/              429 passed                                     (11s)

All 5 failures and all 15 errors are pre-existing and unrelated. I checked out origin/main into a separate worktree and reproduced every one of them there: test_kv_cache_estimation.py::TestTransformersIntrospection::test_resolves_real_transformers_arches (transformers 5.4.0 no longer reports a sliding window for cohere2), test_mcp_stdio_improvements.py, and test_studio_api.py (no server binary in this environment). None of those files are in the diff.

The suites this PR actually touches, on the merged tree:

tests/test_diffusion_backend.py tests/test_diffusion_routes.py tests/test_diffusion_gated_base.py
tests/test_sd_cpp_backend.py tests/test_video_backend.py     686 passed

Frontend:

npx tsc --noEmit    exit 0
npm test            1537 pass, 0 fail

6. What I pushed

The merge of main surfaced two genuine failures of your own test_every_video_fetch_reads_either_cache_root. main added two hf_hub_download_with_xet_fallback call sites in video.py after you branched, the MiniMax-H3 modular_model_index.json read and the H3 pre-cast encoder fetch, and both are pinned to the live cache root. Your guard test caught both, which is the test earning its keep: the comment on it says the miss is always one call site nobody updated, and that is exactly what happened.

Fixed in c44332a2 by passing reuse_other_cache_root = True at both sites, with the docstring line that said "pinned to the live cache root" corrected. tests/test_video_backend.py and tests/test_video_h3_te_quant.py: 211 passed.

Your base also predated #8281 and #8304, so the merge takes the test_diffusion_training.py preflight fixes, the backend job cap raise from 15 to 30 minutes, and the PSModulePath fix for parity (windows-latest). CI is queued on the new head.

One heads up: studio/frontend/tests/video-download-plan-payload.test.ts is edited by this PR and by #8305 as well, so expect a textual conflict there whichever lands second.

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up, and it changes what I would do with this PR. Please read this before spending time on the conflicts.

The PR is unmergeable right now, and no CI can run at all

$ gh api repos/unslothai/unsloth/pulls/8289 -q '.mergeable, .mergeable_state, .head.sha'
false
dirty
c44332a230d7d9a4e6c47ae85e0ea583d63e9e99

$ gh api repos/unslothai/unsloth/commits/c44332a23.../check-runs -q .total_count
0

Zero check runs on the head. A pull_request workflow needs the merge ref, and GitHub cannot build one for a conflicted PR, so nothing has started. The single fail that gh pr checks reports is pre-commit.ci - pr with error during mergeable check, which is the same symptom rather than a code problem. So "CI is red" here means "CI cannot begin", and my merge of main earlier is not what caused it.

Why it went dirty: #8036 landed, and it ships this feature

main took 13 commits since I merged it into your branch a bit over an hour ago. One of them is 5a2d9e185, #8036, "Fix image model dependency downloads and show full footprint", merged at 07:33 UTC.

That PR is 4331 insertions across 32 files, and its second bullet is the problem this PR exists to fix:

Report and display the full required footprint separately from remaining download bytes, with a checkpoint-versus-assets tooltip in the model selector.

main today, in models/inference.py:

class DiffusionDownloadPlanResponse(BaseModel):
    entries: List[DiffusionDownloadPlanEntry] = ...
    total_bytes: int = Field(0, description = "Sum of the remaining download entries, 0 when ready or unknown")
    required_bytes: int = Field(0, description = "Full declared footprint of every file the load requires, including cached files")
    checkpoint_bytes: int = Field(0, description = "Declared size of the selected checkpoint within required_bytes")

required_bytes - checkpoint_bytes is your companion_bytes, computed from the other end. And main's pickers.tsx already renders it on the row:

  const totalBytes = checkpointBytes + companionBytes;
  ...
  {formatBytes(checkpointBytes)} model + {formatBytes(companionBytes)} required assets

with data-model-download-footprint on the element and a per-variant fetch batched on a new dependency_key from hub/services/models/gguf_variants.py, which is that PR's answer to the same rate-limit problem plan_metadata.py solves here.

The 43 conflict hunks across 12 files are not merge noise, they are two implementations of one feature meeting. core/inference/video.py alone has 18.

I checked the pieces I thought might still be unique to this PR, and most of them are not:

  • reuse_other_cache_root on the video fetches: main has it. I scanned every hf_hub_download_with_xet_fallback call site in main's video.py and 0 are missing it, including the two MiniMax-H3 sites I fixed in c44332a2. That commit is redundant against current main; resolve it away.
  • The gated-base mirror pinned to its own commit: main has it, diffusion.py:2352, mirror_revision = self._current_sha(fetch_base, hf_token).
  • Cache-aware plans in all three planners including sd.cpp: main has it, and its test_sd_cpp_backend.py grew 248 lines, which is the coverage gap I flagged in my last comment.

What does look genuinely unique to this PR:

  • The unpinned reachability probe in _files_already_cached. main rewrote that function too, with a size check against declared_sizes this PR does not have, but it still probes only the pinned revision. Your point stands there: every loader resolves through refs/main, so a snapshot fetched under an explicit commit with no ref is one no load can open. That is a real bug on current main and it is a small, self-contained fix.
  • sizing_failed. main has no equivalent, so it silently reports a floor as an answer. Worth keeping, though see finding 1 in my previous comment about what the frontend then does with it.
  • The refusal of a base snapshot assembled from two cache roots in _predownload_base.

What I would do

I would not resolve these conflicts. Reconciling two independent 2000-line implementations of the same feature through a 43-hunk merge is how both end up half-applied, and the merge would also have to decide between two rewrites of _files_already_cached and two different batching strategies for the same rate limit.

My suggestion is to branch fresh off current main and re-land only the deltas above as small separate PRs, starting with the refs/main reachability probe, which is a genuine bug in what just shipped and stands entirely on its own. Then close this one pointing at those. If instead you think this PR's shape is the better one, say so and we should revert or supersede #8036's picker half deliberately rather than let a merge arbitrate it.

Either way it is your call and I am happy with either. I just did not want you to resolve 43 hunks first and find out afterwards.

Everything in my previous comment still holds as a measurement of this branch's own logic, but note the numbers there were taken against main at 84801896e, before #8036.

Sorry for the collision. Two PRs converging on the same picker row in the same week is on us for not spotting the overlap earlier, not on you.

The picker skipped companion sizing for a local GGUF path. Only the checkpoint
is on disk: the base branch in download_plan is independent of whether repo_id
is local, so a local pick whose family resolves a remote base still stages its
text encoder and VAE. The row showed the checkpoint alone, and because a local
pick also reads as downloaded, loadOrStage went straight to the load and
fetched those companions inline.

The existing local-path test pins _resolve_base_repo to the local directory, so
it never covered this. Added one for the local checkpoint with a remote base.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 3b74fdd466

ℹ️ 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 thread studio/backend/core/inference/video.py Resolved
_h3_te_quant_hub_files listed the hosted quantized conditioner without handing
its commit back, and both cache probes need one, so a 27 GB artifact already on
disk was retained and charged. The generic encoder and denoiser helpers were
given shas_out earlier and this one was missed each time.

It also goes through plan_model_info now, so an expander stops re-listing that
repo once per candidate.
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 43d09b9d25

ℹ️ 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 1911 to +1914
h3_te_repo, h3_te_files = self._h3_te_quant_hub_files(
self._h3_te_quant_scheme_verified(fam, text_encoder_quant, base, hf_token), api
self._h3_te_quant_scheme_verified(fam, text_encoder_quant, base, hf_token),
api,
shas,

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 Reuse the fallback cache in the H3 conditioner loader

When Studio's cache folder changes and the hosted MiniMax-H3 conditioner exists only in the import-time cache root, recording its SHA here lets _drop_cached_entries omit the roughly 27 GB artifact, and _fetch_h3_te_quant successfully finds that fallback copy. However, the subsequent load_h3_quantized_text_encoder call in video_minimax_h3_te.py:338-340 resolves the artifact again with cache_dir but without reuse_other_cache_root=True, so it downloads the file into the live root despite the plan advertising no transfer (or fails offline and falls back to the omitted dense encoder). Make the actual conditioner loader reuse the other cache root as well.

Useful? React with 👍 / 👎.

Comment on lines +1334 to +1336
const companionQueryFilenames = useMemo(
() => (displayVariants ?? []).map((variant) => variant.filename),
[displayVariants],

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 Size collapsed single-quant rows before enabling them

When On Device has exactly one cached GGUF and “Show all quantizations” is off, renderDownloadedGgufRow returns renderSoleQuantGgufRow instead of mounting this expander, so this new companion query never runs. That row still displays only variant.size_bytes at pickers.tsx:3655-3659 and marks the pick downloaded; if the GGUF was obtained without its diffusion/video base, clicking it bypasses the download plan and fetches the missing multi-GB companions inline. Apply companion sizing to the collapsed sole-quant row too, or keep it expanded until its full size is known.

Useful? React with 👍 / 👎.

repo, files, shas.get(repo)
).issuperset(files):
continue
missing = DiffusionBackend._files_missing_from_live_root(repo, files, shas.get(repo))

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 Count fallback-root hits for per-file H3 assets

When MiniMax-H3's two component files are split across the live and import-time cache roots, this calculation charges every file absent from the live root even though _run_load_h3_native resolves each requested file independently with reuse_other_cache_root=True at video.py:1175-1184. No bytes transfer in that case, but the plan advertises the fallback-root VAE as a new multi-GB download and can fail the disk preflight unnecessarily. For native H3 entries, calculate missing files across both roots rather than applying the live-root snapshot rule used by diffusers bases.

Useful? React with 👍 / 👎.

@Etherll

Etherll commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

superseded by merged #8036

@Etherll Etherll closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: a diffusion GGUF pick advertises the GGUF size only, not the base companions it also downloads

3 participants