Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep enhancing prompts from an already downloaded FLUX.3 upsampler quant (#14836)

Daniel Han3af50bd6066f
diff --git a/studio/backend/core/inference/flux3_prompt_upsampler.py b/studio/backend/core/inference/flux3_prompt_upsampler.py
index e0e5355fa51..86c899544e6 100644
--- a/studio/backend/core/inference/flux3_prompt_upsampler.py
+++ b/studio/backend/core/inference/flux3_prompt_upsampler.py
@@ -54,11 +54,13 @@ UPSAMPLER_MODEL_FILES = {
# divergence than the imatrix Q4_K_M for 6% more bytes, at the same speed.
UPSAMPLER_DEFAULT_QUANT = "UD-Q4_K_XL"
UPSAMPLER_MODEL_FILE = UPSAMPLER_MODEL_FILES[UPSAMPLER_DEFAULT_QUANT]
-# Cached earlier defaults, best first, used when UPSAMPLER_MODEL_FILE is absent (fresh installs still download it).
+# What a run reads, best first: an install holding Q4_K_M (the default until UD-Q4_K_XL) keeps enhancing offline.
UPSAMPLER_CACHED_FALLBACK_QUANTS = ("Q8_0", "Q4_K_M")
UPSAMPLER_MODEL_FILE_PREFERENCE = (UPSAMPLER_MODEL_FILE,) + tuple(
UPSAMPLER_MODEL_FILES[quant] for quant in UPSAMPLER_CACHED_FALLBACK_QUANTS
)
+# Q8_0 is closer to BF16 than the default: a complete Q8_0 pair is not offered a smaller download "for better captions".
+UPSAMPLER_SUPERSEDED_FILES = frozenset((UPSAMPLER_MODEL_FILES["Q4_K_M"],))
# Vision projector, needed only for edits (reference images).
UPSAMPLER_MMPROJ_FILE = "mmproj-F16.gguf"
# Expected sizes of the files as built, for the UI before the download starts (the download reads the real ones).
@@ -729,14 +731,17 @@ def _cached_at_any_revision(filename: str, hub_cache: Optional[Path] = None) ->
return None
-def _cached_pair(hub_cache: Optional[Path] = None) -> tuple[Optional[str], Optional[str]]:
+def _cached_pair(
+ hub_cache: Optional[Path] = None, model_files: tuple = UPSAMPLER_MODEL_FILE_PREFERENCE
+) -> tuple[Optional[str], Optional[str]]:
"""The model and projector from ONE revision (the recorded one first), as the downloader pins them; a model
- with no projector at its revision when no revision holds both. Files tried in UPSAMPLER_MODEL_FILE_PREFERENCE order."""
+ with no projector at its revision when no revision holds both. A complete pair of any ``model_files`` beats a
+ model alone, so an interrupted default download does not cost edits their reference images."""
revisions = _candidate_revisions(hub_cache)
model_only = None
- for filename in UPSAMPLER_MODEL_FILE_PREFERENCE:
+ for model_file in model_files:
for revision in revisions:
- model = _cached_file(filename, hub_cache = hub_cache, revision = revision)
+ model = _cached_file(model_file, hub_cache = hub_cache, revision = revision)
if model is None:
continue
mmproj = _cached_file(UPSAMPLER_MMPROJ_FILE, hub_cache = hub_cache, revision = revision)
@@ -840,6 +845,23 @@ def status() -> dict:
if model:
with suppress(OSError):
size = os.path.getsize(model)
+ overridden = _overridden()
+ # Not the unpinned _cached_download_paths: any cached quant completes that one.
+ current_downloaded = (
+ overridden
+ or None not in _cached_pair(model_files = (UPSAMPLER_MODEL_FILE,))
+ or (mmproj is not None and model_name not in UPSAMPLER_SUPERSEDED_FILES)
+ )
+ # Bytes still to fetch: a file already cached at any revision is a blob the hub cache reuses.
+ missing = (
+ []
+ if current_downloaded
+ else [
+ name
+ for name in (UPSAMPLER_MODEL_FILE, UPSAMPLER_MMPROJ_FILE)
+ if _cached_at_any_revision(name) is None
+ ]
+ )
return {
"supported": find_llama_server_binary() is not None,
"downloaded": model is not None,
@@ -852,8 +874,11 @@ def status() -> dict:
"mmproj_filename": UPSAMPLER_MMPROJ_FILE,
"mmproj_size_bytes": UPSAMPLER_FILE_SIZES.get(UPSAMPLER_MMPROJ_FILE),
"mmproj_downloaded": mmproj is not None,
+ "current_filename": UPSAMPLER_MODEL_FILE,
+ "current_downloaded": current_downloaded,
+ "current_missing_bytes": sum(UPSAMPLER_FILE_SIZES.get(name, 0) for name in missing),
# Local files from the env overrides: the repo download is not offered beside them.
- "override": _overridden(),
+ "override": overridden,
"download": download_status(),
}
diff --git a/studio/backend/tests/test_flux3_prompt_upsampler.py b/studio/backend/tests/test_flux3_prompt_upsampler.py
index 2730843c182..5d68df163b4 100644
--- a/studio/backend/tests/test_flux3_prompt_upsampler.py
+++ b/studio/backend/tests/test_flux3_prompt_upsampler.py
@@ -11,6 +11,7 @@ import hashlib
import io
import threading
import time
+from pathlib import Path
import pytest
@@ -1413,6 +1414,142 @@ def test_model_and_projector_come_from_one_revision(monkeypatch):
assert pup._cached_download_paths(pup.UPSAMPLER_ID) is None
+_OLD_REV = "1" * 40
+_NEW_REV = "2" * 40
+
+
+def offline_upsampler_cache(monkeypatch, tmp_path):
+ """An offline HF cache holding what an install made before the UD-Q4_K_XL default has: Q4_K_M + projector."""
+ from core.inference import stt_sidecar
+
+ monkeypatch.setenv("HF_HUB_OFFLINE", "1")
+ monkeypatch.setattr(stt_sidecar, "_active_hf_hub_cache", lambda: tmp_path)
+ monkeypatch.setattr(stt_sidecar, "_read_revision_record", lambda repo: None)
+ repo = tmp_path / f"models--{pup.UPSAMPLER_REPO.replace('/', '--')}"
+
+ def put(revision, name):
+ path = repo / "snapshots" / revision / name
+ path.parent.mkdir(parents = True, exist_ok = True)
+ path.write_bytes(b"gguf")
+ (repo / "refs").mkdir(parents = True, exist_ok = True)
+ (repo / "refs" / "main").write_text(revision)
+ return str(path)
+
+ put(_OLD_REV, pup.UPSAMPLER_MMPROJ_FILE)
+ old = put(_OLD_REV, pup.UPSAMPLER_MODEL_FILES["Q4_K_M"])
+ return put, old
+
+
+def test_an_install_holding_only_the_earlier_q4_k_m_keeps_enhancing_offline(
+ monkeypatch, offline_upsampler_cache
+):
+ _put, old = offline_upsampler_cache
+ assert pup.UPSAMPLER_MODEL_FILE != pup.UPSAMPLER_MODEL_FILES["Q4_K_M"]
+ assert pup.model_path() == old
+ assert pup.mmproj_path().endswith(pup.UPSAMPLER_MMPROJ_FILE)
+ status = pup.status()
+ assert status["downloaded"] and status["filename"] == pup.UPSAMPLER_MODEL_FILES["Q4_K_M"]
+ # The download still fetches the current default: the earlier file does not complete it.
+ assert status["current_downloaded"] is False
+ assert pup._cached_download_paths(pup.UPSAMPLER_ID, revision = _OLD_REV) is None
+
+ sidecar = _FakeSidecar(reply = "An enhanced caption.")
+ monkeypatch.setattr(pup, "find_llama_server_binary", lambda: "/bin/llama-server")
+ monkeypatch.setattr(pup, "get_sidecar", lambda: sidecar)
+ out = pup.enhance_for_generation(["a cat"], family_name = "flux.3-klein", enhance_prompt = None)
+ assert out.status == "applied" and out.encoded("a cat") == "An enhanced caption."
+ assert [call["model"] for call in sidecar.calls] == [old]
+
+
+def test_the_default_quant_wins_once_it_is_downloaded(offline_upsampler_cache):
+ put, _old = offline_upsampler_cache
+ put(_NEW_REV, pup.UPSAMPLER_MMPROJ_FILE)
+ new = put(_NEW_REV, pup.UPSAMPLER_MODEL_FILE)
+ assert pup.model_path() == new
+ assert pup.status()["filename"] == pup.UPSAMPLER_MODEL_FILE
+ assert pup._cached_download_paths(pup.UPSAMPLER_ID) == (
+ new,
+ new.replace(pup.UPSAMPLER_MODEL_FILE, pup.UPSAMPLER_MMPROJ_FILE),
+ )
+
+
+def test_a_complete_earlier_pair_beats_a_default_model_with_no_projector(offline_upsampler_cache):
+ """An interrupted default download (model, no projector) must not hide a complete earlier quant + projector:
+ edits would otherwise drop their reference images."""
+ put, old = offline_upsampler_cache
+ put(_NEW_REV, pup.UPSAMPLER_MODEL_FILE)
+ put(_OLD_REV, pup.UPSAMPLER_MODEL_FILES["Q4_K_M"]) # refs/main back on the complete revision
+ assert pup.model_path() == old
+ assert pup.mmproj_path() == old.replace(
+ pup.UPSAMPLER_MODEL_FILES["Q4_K_M"], pup.UPSAMPLER_MMPROJ_FILE
+ )
+ status = pup.status()
+ assert status["downloaded"] and status["mmproj_downloaded"]
+ # The default is still not complete at one revision, so the control stays offered; both blobs are on disk.
+ assert status["current_downloaded"] is False and status["current_missing_bytes"] == 0
+
+
+def test_a_default_model_alone_still_runs_text_only(offline_upsampler_cache):
+ """No complete pair anywhere: the default model (no projector) still wins over an earlier model alone."""
+ put, old = offline_upsampler_cache
+ Path(old.replace(pup.UPSAMPLER_MODEL_FILES["Q4_K_M"], pup.UPSAMPLER_MMPROJ_FILE)).unlink()
+ new = put(_NEW_REV, pup.UPSAMPLER_MODEL_FILE)
+ assert pup.model_path() == new and pup.mmproj_path() is None
+
+
+def test_an_earlier_quant_serving_still_offers_the_default_download(offline_upsampler_cache):
+ """Run availability (downloaded / mmproj_downloaded) is not download completion: the current default stays
+ offered while an earlier quant serves."""
+ status = pup.status()
+ assert status["downloaded"] and status["mmproj_downloaded"]
+ assert status["current_downloaded"] is False
+ assert status["current_filename"] == pup.UPSAMPLER_MODEL_FILE
+ assert status["current_missing_bytes"] == pup.UPSAMPLER_FILE_SIZES[pup.UPSAMPLER_MODEL_FILE]
+ put, _old = offline_upsampler_cache
+ put(_NEW_REV, pup.UPSAMPLER_MMPROJ_FILE)
+ put(_NEW_REV, pup.UPSAMPLER_MODEL_FILE)
+ status = pup.status()
+ assert status["current_downloaded"] is True and status["current_missing_bytes"] == 0
+
+
+def test_a_q8_0_pair_is_not_offered_the_smaller_default(offline_upsampler_cache):
+ """Q8_0 is closer to BF16 than the default: serving it, the panel offers no download "for better captions"."""
+ put, _old = offline_upsampler_cache
+ put(_NEW_REV, pup.UPSAMPLER_MMPROJ_FILE)
+ put(_NEW_REV, pup.UPSAMPLER_MODEL_FILES["Q8_0"])
+ status = pup.status()
+ assert status["filename"] == pup.UPSAMPLER_MODEL_FILES["Q8_0"] and status["mmproj_downloaded"]
+ assert status["current_downloaded"] is True and status["current_missing_bytes"] == 0
+
+
+def test_an_earlier_model_alone_reports_the_whole_default_download(offline_upsampler_cache):
+ """An earlier quant with no projector serves text-only prompts, but the Download fetches the default model AND the
+ projector: the status names the earlier file and prices both, which the panel reads instead of the projector size."""
+ _put, old = offline_upsampler_cache
+ Path(old.replace(pup.UPSAMPLER_MODEL_FILES["Q4_K_M"], pup.UPSAMPLER_MMPROJ_FILE)).unlink()
+ status = pup.status()
+ assert status["downloaded"] and not status["mmproj_downloaded"]
+ assert status["filename"] == pup.UPSAMPLER_MODEL_FILES["Q4_K_M"] != status["current_filename"]
+ assert status["current_downloaded"] is False
+ assert status["current_missing_bytes"] == (
+ pup.UPSAMPLER_FILE_SIZES[pup.UPSAMPLER_MODEL_FILE]
+ + pup.UPSAMPLER_FILE_SIZES[pup.UPSAMPLER_MMPROJ_FILE]
+ )
+
+
+def test_nothing_downloaded_is_still_unavailable(monkeypatch, tmp_path):
+ from core.inference import stt_sidecar
+
+ monkeypatch.setenv("HF_HUB_OFFLINE", "1")
+ monkeypatch.setattr(stt_sidecar, "_active_hf_hub_cache", lambda: tmp_path)
+ monkeypatch.setattr(stt_sidecar, "_read_revision_record", lambda repo: None)
+ monkeypatch.setattr(pup, "find_llama_server_binary", lambda: "/bin/llama-server")
+ assert pup.model_path() is None and pup.status()["filename"] == pup.UPSAMPLER_MODEL_FILE
+ out = pup.enhance_for_generation(["a cat"], family_name = "flux.3-klein", enhance_prompt = None)
+ assert out.status == pup.STATUS_UNAVAILABLE
+
+
# ── an earlier default quant already in the cache ───────────────────────────────────────────────────────────────────
_REV_A = "a" * 40
_REV_B = "b" * 40
@@ -1457,10 +1594,11 @@ def test_a_cached_earlier_quant_is_used_when_the_default_is_missing(fake_hub):
str(snapshot / pup.UPSAMPLER_MMPROJ_FILE),
)
out = pup.status()
- # Ready: the UI offers no download beside it.
+ # Ready to enhance; the current default is still offered beside it (current_downloaded).
assert (
out["supported"] is True and out["downloaded"] is True and out["mmproj_downloaded"] is True
)
+ assert out["current_downloaded"] is False
assert out["override"] is False
assert out["filename"] == q4 and out["size_bytes"] == len(q4.encode())
diff --git a/studio/frontend/src/features/images/lib/prompt-enhance.ts b/studio/frontend/src/features/images/lib/prompt-enhance.ts
index 28a37609396..c0bc29b43b4 100644
--- a/studio/frontend/src/features/images/lib/prompt-enhance.ts
+++ b/studio/frontend/src/features/images/lib/prompt-enhance.ts
@@ -43,6 +43,11 @@ export interface PromptUpsamplerStatus {
size_bytes: number;
mmproj_size_bytes: number;
mmproj_downloaded: boolean;
+ // False while an earlier quant serves (downloaded above); an older backend without it reads downloaded && mmproj.
+ current_downloaded: boolean;
+ current_missing_bytes: number;
+ // "" from an older backend.
+ current_filename: string;
// Local files from the env overrides: no repo download is offered beside them.
override: boolean;
download: PromptUpsamplerDownload;
@@ -92,18 +97,39 @@ export function parsePromptUpsamplerStatus(raw: unknown): PromptUpsamplerStatus
size_bytes: num(body.size_bytes) ?? 0,
mmproj_size_bytes: num(body.mmproj_size_bytes) ?? 0,
mmproj_downloaded: body.mmproj_downloaded === true,
+ current_downloaded:
+ typeof body.current_downloaded === "boolean"
+ ? body.current_downloaded
+ : body.downloaded === true && body.mmproj_downloaded === true,
+ current_missing_bytes: num(body.current_missing_bytes) ?? 0,
+ current_filename: str(body.current_filename) ?? "",
override: body.override === true,
download,
};
}
-/** The model or its vision projector (edits) is missing, so the Download control stays offered. */
+/** The model, its vision projector (edits) or the current default quant is missing. */
export function upsamplerNeedsDownload(status: PromptUpsamplerStatus): boolean {
- return status.supported && !status.override && (!status.downloaded || !status.mmproj_downloaded);
+ return (
+ status.supported &&
+ !status.override &&
+ (!status.downloaded || !status.mmproj_downloaded || !status.current_downloaded)
+ );
+}
+
+/** An earlier quant serves; a model with no projector counts when it is not the default file (the Download then
+ * fetches both, not the projector alone). */
+export function upsamplerServesEarlierQuant(status: PromptUpsamplerStatus): boolean {
+ if (!status.downloaded || status.current_downloaded) return false;
+ return (
+ status.mmproj_downloaded ||
+ (status.current_filename !== "" && status.filename !== "" && status.filename !== status.current_filename)
+ );
}
/** Bytes the Download button fetches: whichever of the model and the vision projector is still missing. */
export function upsamplerDownloadBytes(status: PromptUpsamplerStatus): number {
+ if (upsamplerServesEarlierQuant(status)) return status.current_missing_bytes;
return (
(status.downloaded ? 0 : status.size_bytes) +
(status.mmproj_downloaded ? 0 : status.mmproj_size_bytes)
diff --git a/studio/frontend/src/features/images/prompt-enhance-panel.tsx b/studio/frontend/src/features/images/prompt-enhance-panel.tsx
index 273233116f7..949615f5ebf 100644
--- a/studio/frontend/src/features/images/prompt-enhance-panel.tsx
+++ b/studio/frontend/src/features/images/prompt-enhance-panel.tsx
@@ -32,6 +32,7 @@ import {
type PromptUpsamplerStatus,
upsamplerDownloadBytes,
upsamplerNeedsDownload,
+ upsamplerServesEarlierQuant,
clearPreviewDigests,
previewSignature,
upsamplerDownloadFraction,
@@ -152,7 +153,9 @@ function UpsamplerDownloadNotice({
) : (
<>
<span className="text-muted-foreground">
- {status.downloaded
+ {upsamplerServesEarlierQuant(status)
+ ? `Prompts are enhanced with an earlier upsampler quant (${status.filename})${status.mmproj_downloaded ? "" : ", edits from the text alone"}. Download the current one${size ? ` (${size})` : ""} for better captions.`
+ : status.downloaded
? `The prompt upsampler's vision projector${size ? ` (${size})` : ""} is not downloaded. Until it is, edits are enhanced from the text alone.`
: `The prompt upsampler${size ? ` (${size})` : ""} is not downloaded. Until it is, prompts run as typed.`}
</span>
diff --git a/studio/frontend/tests/image-prompt-enhance.test.ts b/studio/frontend/tests/image-prompt-enhance.test.ts
index 94607c1f80d..151b6ecf0b8 100644
--- a/studio/frontend/tests/image-prompt-enhance.test.ts
+++ b/studio/frontend/tests/image-prompt-enhance.test.ts
@@ -26,6 +26,7 @@ import {
WARM_RETRY_OUTCOMES,
upsamplerDownloadFraction,
upsamplerNeedsDownload,
+ upsamplerServesEarlierQuant,
upsamplerVariantFor,
withEnhanceChoice,
} from "../src/features/images/lib/prompt-enhance.ts";
@@ -167,9 +168,47 @@ test("status parsing tolerates missing and malformed fields", () => {
const noProjector = { ...full, downloaded: true };
assert.equal(upsamplerNeedsDownload(noProjector), true);
assert.equal(upsamplerDownloadBytes(noProjector), 900_000_000);
- assert.equal(upsamplerNeedsDownload({ ...noProjector, mmproj_downloaded: true }), false);
+ assert.equal(upsamplerNeedsDownload({ ...noProjector, mmproj_downloaded: true, current_downloaded: true }), false);
assert.equal(upsamplerNeedsDownload({ ...full, supported: false }), false);
+ // An earlier quant serving keeps the control offered, sized at the current default.
+ const earlier = parsePromptUpsamplerStatus({
+ supported: true,
+ downloaded: true,
+ mmproj_downloaded: true,
+ filename: "upsampler-Q4_K_M.gguf",
+ size_bytes: 5_600_000_000,
+ mmproj_size_bytes: 900_000_000,
+ current_downloaded: false,
+ current_missing_bytes: 5_900_000_000,
+ });
+ assert.equal(upsamplerServesEarlierQuant(earlier), true);
+ assert.equal(upsamplerNeedsDownload(earlier), true);
+ assert.equal(upsamplerDownloadBytes(earlier), 5_900_000_000);
+ assert.equal(upsamplerNeedsDownload({ ...earlier, override: true }), false);
+ const current = parsePromptUpsamplerStatus({ ...earlier, current_downloaded: true, current_missing_bytes: 0 });
+ assert.equal(upsamplerNeedsDownload(current), false);
+ assert.equal(upsamplerServesEarlierQuant(current), false);
+ // Model-only earlier quant: the Download fetches the default AND the projector.
+ const modelOnly = parsePromptUpsamplerStatus({
+ ...earlier,
+ mmproj_downloaded: false,
+ current_filename: "upsampler-UD-Q4_K_XL.gguf",
+ current_missing_bytes: 6_888_000_000,
+ });
+ assert.equal(upsamplerServesEarlierQuant(modelOnly), true);
+ assert.equal(upsamplerNeedsDownload(modelOnly), true);
+ assert.equal(upsamplerDownloadBytes(modelOnly), 6_888_000_000);
+ // The current default itself with its projector missing is the projector-only case.
+ const currentNoProjector = { ...modelOnly, filename: "upsampler-UD-Q4_K_XL.gguf", current_missing_bytes: 900_000_000 };
+ assert.equal(upsamplerServesEarlierQuant(currentNoProjector), false);
+ assert.equal(upsamplerDownloadBytes(currentNoProjector), 900_000_000);
+ // Without current_filename (not reported) a model with no projector stays the projector-only case.
+ assert.equal(upsamplerServesEarlierQuant({ ...modelOnly, current_filename: "" }), false);
+ const olderBackend = parsePromptUpsamplerStatus({ supported: true, downloaded: true, mmproj_downloaded: true });
+ assert.equal(olderBackend.current_downloaded, true);
+ assert.equal(upsamplerNeedsDownload(olderBackend), false);
+
const empty = parsePromptUpsamplerStatus(null);
assert.deepEqual(
{ supported: empty.supported, downloaded: empty.downloaded, size: empty.size_bytes, repo: empty.repo },