Skip to content

Studio: use a cached earlier FLUX.3 upsampler quant when the default is missing - #14842

Merged
danielhanchen merged 2 commits into
mainfrom
studio-flux3-upsampler-cached-quant-fallback
Oct 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-flux3-upsampler-cached-quant-fallback

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

#14177 changed the FLUX.3 prompt upsampler default quant to UD-Q4_K_XL. _cached_pair(), _cached_download_paths() and model_path() only looked up UPSAMPLER_MODEL_FILE, the new default. An install that had already downloaded the previous default flux-3-image-klein-pup-Q4_K_M.gguf (or the Q8_0 file) therefore reported the upsampler as not downloaded, and Enhance prompt stopped working until the new ~6 GB file was fetched. The cached older quant was never used.

Fix

  • New UPSAMPLER_MODEL_FILE_PREFERENCE: the default UD-Q4_K_XL first, then Q8_0 (higher quality), then Q4_K_M.
  • _cached_pair() walks that order and, for each file, the candidate revisions (recorded one first). It still pairs a model with the projector at the same revision, and still falls back to a model with no projector only when no revision holds both. A complete pair of a fallback quant wins over the default with no projector, as it did before across revisions.
  • model_path(), mmproj_path(), status() and the unpinned _cached_download_paths() all go through _cached_pair(), so the status route (downloaded / mmproj_downloaded), the frontend download prompt and the Enhance gates in the generate route agree: a user with the old file sees Enhance as ready.
  • status() now reports the filename and on-disk size of the file in use, not the default name beside an older file.
  • Unchanged: the download spec still fetches UD-Q4_K_XL + mmproj-F16.gguf, so a fresh install gets the new default. The completion check for a pinned download still requires the default at that revision. The UNSLOTH_FLUX3_UPSAMPLER_GGUF / _MMPROJ overrides behave as before, including a missing override path never falling back to the cache.

Tests

New tests in studio/backend/tests/test_flux3_prompt_upsampler.py build a real Hugging Face cache layout under tmp_path (no downloads):

  • only Q4_K_M + projector cached: model_path() returns Q4_K_M and status() reports ready
  • default and fallbacks cached: the default wins
  • Q8_0 is preferred over Q4_K_M
  • a fallback quant pairs with the projector at its own revision
  • a pinned download's completion check still wants the default
  • nothing cached: not ready, and the download targets UD-Q4_K_XL
  • the env override still beats a cached quant
main this branch
tests/test_flux3_prompt_upsampler.py 3 failed, 205 passed 208 passed

The three failures on main are the Q4_K_M only, Q8_0 preference and fallback pairing tests. test_diffusion_flux3.py, test_orchestrator_unload_cancel.py and test_gpu_selection.py also pass.

Not covered

  • A user with only an older quant and no projector still downloads the default plus the projector when they ask for the projector, and the frontend size estimate for that case counts only the projector.
  • No change to the frontend; no live Studio run with a real cached quant.

…is missing

The default prompt upsampler quant moved to UD-Q4_K_XL, but the cache
lookup only checked that file, so installs that already downloaded the
previous Q4_K_M (or Q8_0) default lost Enhance prompt until the new file
was fetched. Look up the default first, then Q8_0, then Q4_K_M, each
paired with the projector at its own revision. Status reports the file in
use. Fresh installs still download UD-Q4_K_XL and the env overrides are
unchanged.
@danielhanchen danielhanchen self-assigned this Oct 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T01:01:55.122541Z b38fbd0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: b38fbd0d73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Oct 23, 2026
… in #14822 (#14852)

pre-commit.ci fails `ruff-format-with-kwargs` again on PRs queued after
00:36 UTC (#14834, #14835, #14836, #14842, #14845):
`studio/backend/tests/test_video_stream_encode.py` was merged in #14822
without the formatter, so every PR's all-files run rewrites it.

Same class as #14817. `python scripts/run_ruff_format.py` (the hook's
entry point, `ruff==0.6.9`) applied to that one file. The AST is
identical before and after, `ruff check` passes, and a full run of the
hook over every tracked Python file on this branch changes nothing else.
@danielhanchen
danielhanchen merged commit c032ada into main Oct 23, 2026
@danielhanchen
danielhanchen deleted the studio-flux3-upsampler-cached-quant-fallback branch October 23, 2026 03:58
danielhanchen added a commit that referenced this pull request Oct 23, 2026
main landed #14842, which also runs from a cached earlier upsampler quant
(UPSAMPLER_MODEL_FILE_PREFERENCE: UD-Q4_K_XL, then Q8_0, then Q4_K_M) and
lets the unpinned _cached_download_paths count any cached quant.

Conflicts in studio/backend/core/inference/flux3_prompt_upsampler.py:
- Run order: took main's UPSAMPLER_CACHED_FALLBACK_QUANTS /
  UPSAMPLER_MODEL_FILE_PREFERENCE (Q8_0 before Q4_K_M) and dropped this
  branch's UPSAMPLER_RUN_FILES (dict order, Q4_K_M before Q8_0).
- _cached_pair: kept this branch's model_files parameter, now defaulting
  to UPSAMPLER_MODEL_FILE_PREFERENCE, so model_path / mmproj_path /
  unpinned _cached_download_paths behave as on main.
- status(): kept main's size_bytes fallback chain and this branch's
  current_filename / current_downloaded / current_missing_bytes. Since
  main's unpinned _cached_download_paths is now satisfied by an earlier
  quant, current_downloaded reads _cached_pair(model_files=(default,))
  instead, so the Download control stays offered while an earlier quant
  serves.

Conflicts in studio/backend/tests/test_flux3_prompt_upsampler.py: kept
both test sets. This branch's "only Q4_K_M cached" test now asserts
current_downloaded is False and a pinned check at that revision is None,
instead of an unpinned _cached_download_paths None (main asserts it
returns the earlier pair). Main's matching test also asserts
current_downloaded is False, replacing its "UI offers no download"
comment.

[skip ci]
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Oct 25, 2026
…mpler quant (unslothai#14836)

## Summary

unslothai#14177 made `flux-3-image-klein-pup-UD-Q4_K_XL.gguf` the default prompt
upsampler file. unslothai#14842 (merged) lets an install that still holds the
earlier default, `flux-3-image-klein-pup-Q4_K_M.gguf`, keep enhancing
from it. But that install then reads as fully downloaded, so the Images
panel never offers the new default, which scores about 39% lower mean KL
divergence for 6% more bytes.

This change, on top of unslothai#14842:

- `status()` reports `current_filename`, `current_downloaded` (the
default pair at one revision) and `current_missing_bytes` (only blobs
not already cached at any revision), apart from `downloaded` /
`mmproj_downloaded`, which still mean "can run".
- The Enhance prompt panel keeps the Download control offered while an
earlier quant serves, says which file is in use, and sizes the button at
what the download actually fetches. A model-only earlier quant is sized
at the default model plus projector, not the projector alone.
- A complete `Q8_0` pair is not offered the smaller default: Q8_0 is
closer to BF16, so "for better captions" would be wrong there.
- An older backend without the new fields reads as before
(`current_downloaded` falls back to `downloaded && mmproj_downloaded`).
- Unchanged: what a run reads (`model_path()` / `mmproj_path()`), the
download spec (UD-Q4_K_XL + `mmproj-F16.gguf`), the env overrides, and a
fresh install.

## Testing

- `studio/backend/tests/test_flux3_prompt_upsampler.py`: 223 passed.
Base vs head differential: 5 tests fixed, 217 unchanged, 0 failing on
head. New tests cover: an install with only Q4_K_M keeps enhancing
offline and is still offered the default; the default wins once
downloaded; a complete earlier pair beats a default model with no
projector; a model-only earlier quant is priced at the whole default
download; a Q8_0 pair is not offered the download (fails without the
guard).
- `studio/frontend/tests/image-prompt-enhance.test.ts`: 12 passed.
- `status()` on an install serving Q4_K_M: about 2.0 ms per call vs 1.5
ms on main (the status route, not the generation path).

## Screenshots

Two isolated Studio installs (merge base vs this branch), both on one HF
cache holding only the Q4_K_M upsampler and projector. The upsampler
status comes from each backend; the image model status is set to a
loaded FLUX.3 klein model in the browser so the panel renders without
image weights.

![Enhance prompt panel before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14836/pr14836_before_after-85a7e6646022.png)

Before: the Q4_K_M install shows no download, so it never gets the
better default. After: the panel names the earlier quant in use and
offers Download (6.0 GB).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant