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: only resolve int8 text encoder files that are published (#17503)

Daniel Han091294901198
diff --git a/studio/backend/core/inference/diffusion_te_prequant.py b/studio/backend/core/inference/diffusion_te_prequant.py
index eefaf59eef6..02e2afff299 100644
--- a/studio/backend/core/inference/diffusion_te_prequant.py
+++ b/studio/backend/core/inference/diffusion_te_prequant.py
@@ -173,6 +173,73 @@ TE_INT8_CONVROT_VARIANT_FILES: dict[str, dict[str, dict[str, tuple[str, str]]]]
},
}
+# Table files the Hub listed on 2026-11-11. Others are pending: used only once local or Hub-listed, else int8 takes the
+# fp8 file beside it. Pending rows stay so an upload needs no Studio release.
+TE_INT8_CONVROT_PUBLISHED: frozenset[tuple[str, str]] = frozenset(
+ {
+ ("unsloth/flux.2-dev-fp8", "FLUX.2-dev-text_encoder-INT8-ConvRot.safetensors"),
+ ("unsloth/krea-2-turbo-fp8", "Krea-2-Turbo-text_encoder-INT8-ConvRot.safetensors"),
+ ("unsloth/moss-image-sft-fp8", "MOSS-Image-SFT-text_encoder-INT8-ConvRot.safetensors"),
+ ("unsloth/qwen-image-2.1-fp8", "Qwen-Image-2.1-text_encoder-INT8-ConvRot.safetensors"),
+ ("unsloth/qwen-image-fp8", "Qwen-Image-text_encoder-INT8-ConvRot.safetensors"),
+ (
+ "unsloth/flux-3-image-klein-fp8",
+ "flux-3-image-klein-text_encoder-INT8-ConvRot.safetensors",
+ ),
+ (
+ "unsloth/flux-3-image-klein-base-fp8",
+ "flux-3-image-klein-base-text_encoder-INT8-ConvRot.safetensors",
+ ),
+ }
+)
+
+# Set to return table rows even when pending, so error reasons can name the missing file.
+_TE_INT8_INCLUDE_PENDING: ContextVar[bool] = ContextVar(
+ "unsloth_te_int8_include_pending", default = False
+)
+
+_pending_logged: set[tuple[str, str]] = set()
+
+
+def te_int8_convrot_published(repo_id: Optional[str], filename: Optional[str]) -> bool:
+ """Whether the hosted int8 ConvRot file exists (published list, else local / Hub-listed). Never raises."""
+ if not repo_id or not filename:
+ return False
+ key = (str(repo_id).strip().lower(), str(filename))
+ if key in TE_INT8_CONVROT_PUBLISHED:
+ return True
+ try:
+ source = TePrequantSource(kind = "repo", location = str(repo_id), filename = str(filename))
+ listed = bool(te_prequant_sources_confirmed({"text_encoder": source}))
+ except Exception: # noqa: BLE001 - unanswerable: not published
+ listed = False
+ if not listed and key not in _pending_logged:
+ _pending_logged.add(key)
+ logger = _module_logger()
+ if logger is not None:
+ logger.info(
+ "diffusion.te_prequant: int8 ConvRot text encoder %s/%s is not published yet; an int8 request "
+ "uses the fp8 text encoder file in that repo instead",
+ repo_id,
+ filename,
+ )
+ return listed
+
+
+@contextmanager
+def _cache_only_scope(local_files_only: Optional[bool]):
+ if not local_files_only:
+ yield
+ return
+ from .diffusion_prequant import _LOCAL_FILES_ONLY
+
+ token = _LOCAL_FILES_ONLY.set(True)
+ try:
+ yield
+ finally:
+ _LOCAL_FILES_ONLY.reset(token)
+
+
# Module names of the Linears an int8 ConvRot file stores int8: decoder q/k/v/o + gate/up/down of a Qwen / Llama /
# Mistral / Gemma stack (``...layers.N.``; vision towers name their blocks ``blocks`` / ``attention`` and stay bf16)
# and T5's SelfAttention q/k/v/o + DenseReluDense wi_0/wi_1/wo. The builder quantizes exactly these and the loader
@@ -240,15 +307,29 @@ def quantize_int8_convrot_weight(weight: Any, group_size: int = 256) -> tuple[An
return torch.round(rotated / scale).clamp(-127, 127).to(torch.int8), scale
-def family_te_int8_convrot(fam: Any, component: str) -> Optional[tuple[str, ...]]:
- """``(repo_id, filename)`` of the family's hosted int8 ConvRot encoder for ``component``, or None. A family view
- carrying a variant base with its own encoder (``TE_INT8_CONVROT_VARIANT_FILES``) gets that variant's file only."""
+def family_te_int8_convrot(
+ fam: Any,
+ component: str,
+ *,
+ include_pending: Optional[bool] = None,
+) -> Optional[tuple[str, ...]]:
+ """``(repo_id, filename)`` of the family's hosted int8 ConvRot encoder for ``component``, or None (also when
+ unpublished, unless ``include_pending``)."""
name = str(getattr(fam, "name", fam) or "").strip().lower()
base = str(getattr(fam, "base_repo", "") or "").strip().lower()
variant = TE_INT8_CONVROT_VARIANT_FILES.get(name, {}).get(base)
- if variant is not None:
- return variant.get(component)
- return TE_INT8_CONVROT_FILES.get(name, {}).get(component)
+ entry = (
+ variant.get(component)
+ if variant is not None
+ else TE_INT8_CONVROT_FILES.get(name, {}).get(component)
+ )
+ if entry is None:
+ return None
+ if include_pending is None:
+ include_pending = _TE_INT8_INCLUDE_PENDING.get()
+ if include_pending or te_int8_convrot_published(entry[0], entry[1]):
+ return entry
+ return None
def te_prequant_mirror_path(repo_id: Optional[str], name: Optional[str]) -> Optional[str]:
@@ -418,14 +499,15 @@ def explicit_int8_hosted_components(
standalone = {"text_encoder_4": HIDREAM_LLAMA_REPO}
# TE4 is matched against its own standalone repo, the rest against the selected base.
component_base = standalone.get(component) or base or getattr(fam, "base_repo", "")
- got = te_prequant_sources_for_base(
- fam,
- str(component_base or ""),
- te_quant_mode = "int8",
- target = target,
- components = (component,),
- **({"standalone_component_bases": standalone} if standalone else {}),
- ).get(component)
+ with _cache_only_scope(local_files_only):
+ got = te_prequant_sources_for_base(
+ fam,
+ str(component_base or ""),
+ te_quant_mode = "int8",
+ target = target,
+ components = (component,),
+ **({"standalone_component_bases": standalone} if standalone else {}),
+ ).get(component)
out[component] = bool(
got is not None
and not (got.kind == "repo" and _is_fp8_te_name(got.filename))
@@ -471,6 +553,7 @@ def explicit_int8_unavailable_reason(
"""Why an explicit int8 request cannot take the int8 ConvRot file(s) ``fam`` names, or None when it can (or the
family names none). Names each unconfirmed file so an int8-only host (Apple Silicon) reports the missing file.
Never raises."""
+ token = _TE_INT8_INCLUDE_PENDING.set(True)
try:
name = str(getattr(fam, "name", "") or "").strip().lower()
named = []
@@ -507,6 +590,8 @@ def explicit_int8_unavailable_reason(
return f"the hosted int8 ConvRot text encoder {', '.join(named)} for {getattr(fam, 'name', fam)} {where}"
except Exception: # noqa: BLE001 - unanswerable: no reason to add
return None
+ finally:
+ _TE_INT8_INCLUDE_PENDING.reset(token)
def _auto_pick(te_quant_mode: Any) -> bool:
@@ -765,7 +850,7 @@ def int8_convrot_te_runs_fp16(fam: Any, target: Any) -> bool:
def hosted_int8_convrot_te_runs_on(fam: Any, target: Any) -> bool:
"""Whether an explicit int8 encoder request on ``fam`` loads the hosted int8 ConvRot file on ``target`` without the
fp8 fallback: the family hosts the file (and the lm_head trim it needs is on) and the device runs it as plain
- tensors. Pure: no IO."""
+ tensors. No IO for a published file; a pending one is asked of the Hub once (``te_int8_convrot_published``)."""
try:
if not int8_convrot_te_runs_on(target):
return False
@@ -903,6 +988,11 @@ def resolve_te_prequant_source(
# int8 file first, then the fp8 names in the same repo, so a miss takes fp8 rather than the dense shards.
hosted = family_te_int8_convrot(fam, component)
if hosted is None:
+ if family_te_int8_convrot(
+ fam, component, include_pending = True
+ ) is not None and not _family_has_torchao_int8(fam):
+ # Unpublished: fp8 beside it serves, unless the family has a torchao int8 schedule.
+ return resolve_te_prequant_source(fam, component, "fp8")
return None
repo_id, filename, *hosted_component = hosted
fp8 = resolve_te_prequant_source(fam, component, "fp8")
@@ -1406,12 +1496,13 @@ def _te_prequant_pipe_kwargs(
from .diffusion_precision import TE_QUANT_FP8, normalize_te_quant, te_quant_supported
from .diffusion_text_encoder_trim import family_trims_lm_head
- sources = te_prequant_sources_for_base(
- fam,
- base,
- te_quant_mode = te_quant_mode,
- target = target,
- )
+ with _cache_only_scope(local_files_only):
+ sources = te_prequant_sources_for_base(
+ fam,
+ base,
+ te_quant_mode = te_quant_mode,
+ target = target,
+ )
# Non-empty only for a hosted scheme (see te_prequant_sources' gate).
mode = normalize_te_quant(te_quant_mode) or TE_QUANT_FP8
injected: dict[str, Any] = {}
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.py
index dfa1f89ae20..45106a03a81 100644
--- a/studio/backend/core/inference/video.py
+++ b/studio/backend/core/inference/video.py
@@ -952,7 +952,7 @@ def _assert_video_precision_for_target(
if (
te_mode == "int8"
and model_kind in ("pipeline", "single_file")
- and family_te_int8_convrot(fam, "text_encoder") is not None
+ and family_te_int8_convrot(fam, "text_encoder", include_pending = True) is not None
and int8_convrot_te_runs_on(target)
):
# An unpublished file otherwise failed inside the load, after the eviction.
diff --git a/studio/backend/tests/test_diffusion_image_te_default.py b/studio/backend/tests/test_diffusion_image_te_default.py
index c9c22ada3da..865b98a71a4 100644
--- a/studio/backend/tests/test_diffusion_image_te_default.py
+++ b/studio/backend/tests/test_diffusion_image_te_default.py
@@ -831,7 +831,12 @@ def test_explicit_int8_under_offload_checks_torchao_when_the_file_will_not_load(
run()
-def test_hidream_loads_the_hosted_int8_te4_on_mps(monkeypatch):
+def rows_published(monkeypatch):
+ monkeypatch.setattr(tpq, "te_int8_convrot_published", lambda *a, **k: True)
+
+
+def test_hidream_loads_the_hosted_int8_te4_on_mps(monkeypatch, rows_published):
import core.inference.diffusion_hidream as dh
import core.inference.diffusion_precision as prec
import transformers
diff --git a/studio/backend/tests/test_diffusion_te_int8_missing_file.py b/studio/backend/tests/test_diffusion_te_int8_missing_file.py
index a8a57cb28a6..cb6c43830c5 100644
--- a/studio/backend/tests/test_diffusion_te_int8_missing_file.py
+++ b/studio/backend/tests/test_diffusion_te_int8_missing_file.py
@@ -20,7 +20,7 @@ from core.inference.video_families import _FAMILIES as _VIDEO_FAMILIES # noqa:
CUDA_BF16 = types.SimpleNamespace(device = "cuda", dtype = torch.bfloat16, backend = "cuda", index = 0)
MPS_BF16 = types.SimpleNamespace(device = "mps", dtype = torch.bfloat16, backend = "mps", index = 0)
-# The named files the Hub did not list on 2026-10-25 (HfApi().list_repo_files on each repo).
+# Files the Hub did not list on 2026-11-11 (FLUX.2-klein-9B-FP8 is private).
UNPUBLISHED = {
"FLUX.1-schnell-text_encoder_2-INT8-ConvRot.safetensors",
"FLUX.2-klein-4B-text_encoder-INT8-ConvRot.safetensors",
@@ -46,6 +46,7 @@ def hub(monkeypatch):
monkeypatch.delenv(KEEP_LM_HEAD_ENV, raising = False)
monkeypatch.setattr(tpq, "_confirmed_cache", {})
+ monkeypatch.setattr(tpq, "_pending_logged", set())
monkeypatch.setattr(tpq, "_held_locally", lambda *a, **k: False)
monkeypatch.setattr(tpq, "_hub_offline", lambda: False)
@@ -92,8 +93,8 @@ def test_cuda_explicit_int8_has_the_hosted_fp8_file_behind_the_missing_one(name,
assert sources
for source in sources.values():
chain = tpq.te_candidate_filenames(source)
- assert chain[0] in UNPUBLISHED
- assert any("fp8" in n.lower() for n in chain[1:]), chain
+ assert not set(chain) & UNPUBLISHED, chain
+ assert chain and all("fp8" in n.lower() for n in chain), chain
assert prec.preflight_te_quant("int8", fam, fam.base_repo, CUDA_BF16) == "fp8"
@@ -182,3 +183,124 @@ def test_cuda_load_reports_the_fp8_fallback_for_an_explicit_int8(monkeypatch):
assert outcome.status == prec.RESOLVED_FELL_BACK
assert "int8 ConvRot text encoder is not available" in outcome.reason
assert "fp8 was used instead" in outcome.reason
+
+
+def _table_entries():
+ rows = [e for comps in tpq.TE_INT8_CONVROT_FILES.values() for e in comps.values()]
+ rows += [
+ e
+ for bases in tpq.TE_INT8_CONVROT_VARIANT_FILES.values()
+ for comps in bases.values()
+ for e in comps.values()
+ ]
+ return {(str(e[0]).lower(), e[1]) for e in rows}
+
+
+def test_every_table_row_is_published_or_pending():
+ entries = _table_entries()
+ published = set(tpq.TE_INT8_CONVROT_PUBLISHED)
+ pending = {e for e in entries if e[1] in UNPUBLISHED}
+ # A new row must be added to the published list (after its upload) or to UNPUBLISHED here.
+ assert entries == published | pending
+ assert not published & pending
+ assert published <= entries
+ assert {e[1] for e in pending} == UNPUBLISHED
+
+
[email protected]("entry", sorted(tpq.TE_INT8_CONVROT_PUBLISHED))
+def test_a_published_row_needs_no_hub_call(entry, monkeypatch):
+ monkeypatch.setattr(
+ tpq, "_held_locally", lambda *a, **k: pytest.fail("published rows are not probed")
+ )
+ monkeypatch.setattr(
+ tpq, "te_prequant_hub_files", lambda *a, **k: pytest.fail("published rows are not probed")
+ )
+ assert tpq.te_int8_convrot_published(*entry)
+
+
+def test_a_pending_row_is_hidden_and_logged_once(hub, monkeypatch, caplog):
+ calls = []
+
+ def hub_files(pending, _api):
+ calls.append(sorted(s.filename for s in pending.values()))
+ return {}
+
+ monkeypatch.setattr(tpq, "te_prequant_hub_files", hub_files)
+ messages = []
+ monkeypatch.setattr(
+ tpq,
+ "_module_logger",
+ lambda: types.SimpleNamespace(info = lambda *a: messages.append(a[0] % a[1:])),
+ )
+ fam = _ALL["z-image"]
+ for _ in range(3):
+ assert tpq.family_te_int8_convrot(fam, "text_encoder") is None
+ assert tpq.family_te_int8_convrot(fam, "text_encoder", include_pending = True) is not None
+ assert calls == [["Z-Image-Turbo-text_encoder-INT8-ConvRot.safetensors"]]
+ assert len(messages) == 1 and "not published yet" in messages[0] and "fp8" in messages[0]
+
+
+def test_a_pending_row_is_never_asked_of_the_hub_offline(hub, monkeypatch):
+ monkeypatch.setattr(tpq, "_hub_offline", lambda: True)
+ monkeypatch.setattr(
+ tpq, "te_prequant_hub_files", lambda *a, **k: pytest.fail("offline: no Hub call")
+ )
+ assert tpq.family_te_int8_convrot(_ALL["lumina-2"], "text_encoder") is None
+
+
+def test_a_pending_row_engages_once_the_hub_lists_it(hub, monkeypatch):
+ _cuda(monkeypatch)
+ monkeypatch.setattr(
+ tpq,
+ "te_prequant_hub_files",
+ lambda pending, _api: {c: s.filename for c, s in pending.items()},
+ )
+ fam = _ALL["z-image"]
+ source = tpq.resolve_te_prequant_source(fam, "text_encoder", "int8")
+ assert source.filename == "Z-Image-Turbo-text_encoder-INT8-ConvRot.safetensors"
+ assert any("fp8" in n.lower() for n in source.fallback_filenames)
+
+
+def test_a_pending_row_engages_once_it_is_cached_locally(hub, monkeypatch):
+ _cuda(monkeypatch)
+ monkeypatch.setattr(tpq, "_held_locally", lambda repo, name, token: "INT8-ConvRot" in str(name))
+ monkeypatch.setattr(
+ tpq, "te_prequant_hub_files", lambda *a, **k: pytest.fail("cached: no Hub call")
+ )
+ fam = _ALL["wan2.2-ti2v-5b"]
+ source = tpq.resolve_te_prequant_source(fam, "text_encoder", "int8")
+ assert source.filename == "Wan2.2-TI2V-5B-text_encoder-INT8-ConvRot.safetensors"
+
+
[email protected]("name", ["z-image", "wan2.2-ti2v-5b", "flux.1"])
+def test_cuda_load_of_a_pending_row_downloads_only_the_fp8_file(name, hub, monkeypatch):
+ import core.inference.diffusion_prequant as dpq
+
+ _cuda(monkeypatch)
+ fam = _ALL[name]
+ component = next(iter(tpq.TE_INT8_CONVROT_FILES[name]))
+ source = tpq.te_prequant_sources_for_base(
+ fam, fam.base_repo, te_quant_mode = "int8", target = CUDA_BF16, components = (component,)
+ )[component]
+ asked = []
+
+ def download(src, filename, *a, **k):
+ asked.append(filename)
+ return f"/fake/{filename}"
+
+ monkeypatch.setattr(dpq, "_download_checkpoint_name", download)
+ path = tpq._resolve_checkpoint_path(source, None, cache_dir = "/nonexistent")
+ assert asked and not set(asked) & UNPUBLISHED
+ assert path.endswith(asked[-1]) and "fp8" in asked[-1].lower()
+
+
+def test_a_cache_only_preflight_never_asks_the_hub_for_a_pending_row(hub, monkeypatch):
+ _cuda(monkeypatch)
+ monkeypatch.setattr(
+ tpq, "te_prequant_hub_files", lambda *a, **k: pytest.fail("cache-only: no Hub call")
+ )
+ fam = _ALL["lumina-2"]
+ takes = tpq.explicit_int8_hosted_components(
+ fam, fam.base_repo, CUDA_BF16, local_files_only = True
+ )
+ assert takes and not any(takes.values())
diff --git a/studio/backend/tests/test_diffusion_te_shared_files.py b/studio/backend/tests/test_diffusion_te_shared_files.py
index 9b7a84afa49..07f1af9c215 100644
--- a/studio/backend/tests/test_diffusion_te_shared_files.py
+++ b/studio/backend/tests/test_diffusion_te_shared_files.py
@@ -24,6 +24,13 @@ from core.inference.diffusion_families import _FAMILIES, detect_family # noqa:
from core.inference.diffusion_prequant import ALLOW_LOCAL_PREQUANT_PATH_ENV # noqa: E402
CUDA_BF16 = types.SimpleNamespace(device = "cuda", dtype = torch.bfloat16)
+
+
+def rows_published(monkeypatch):
+ monkeypatch.setattr(tpq, "te_int8_convrot_published", lambda *a, **k: True)
+
+
GROUP = 256
@@ -113,7 +120,7 @@ def _fam(name):
],
)
def test_identical_encoders_resolve_the_shared_file_for_their_base(
- name, base, component, repo, filename
+ name, base, component, repo, filename, rows_published
):
fam = _fam(name)
sources = tpq.te_prequant_sources_for_base(
@@ -128,7 +135,7 @@ def test_identical_encoders_resolve_the_shared_file_for_their_base(
assert sources[component].filename == filename
-def test_klein_9b_int8_falls_back_to_its_own_fp8_file_never_the_4b_one():
+def test_klein_9b_int8_falls_back_to_its_own_fp8_file_never_the_4b_one(rows_published):
fam = _fam("flux.2-klein")
nine = tpq.te_prequant_sources_for_base(
fam, "black-forest-labs/FLUX.2-klein-9B", te_quant_mode = "int8", target = CUDA_BF16
@@ -369,7 +376,7 @@ def test_text_only_qwen3_int8_convrot_file_loads_and_tracks_the_dense_hidden_sta
assert cos > 0.99
-def test_klein_int8_file_has_the_fp8_file_behind_it():
+def test_klein_int8_file_has_the_fp8_file_behind_it(rows_published):
fam = detect_family("black-forest-labs/FLUX.2-klein-4B")
source = tpq.resolve_te_prequant_source(fam, "text_encoder", "int8")
assert source.filename == "FLUX.2-klein-4B-text_encoder-INT8-ConvRot.safetensors"
diff --git a/studio/backend/tests/test_video_te_quant_default.py b/studio/backend/tests/test_video_te_quant_default.py
index aac15514e2d..58086e0f42a 100644
--- a/studio/backend/tests/test_video_te_quant_default.py
+++ b/studio/backend/tests/test_video_te_quant_default.py
@@ -166,7 +166,12 @@ def test_wan_is_not_equivalent_to_other_encoders():
assert not tpq.te_base_equivalent(WAN_BASES[2], "Qwen/Qwen-Image")
-def test_wan_int8_resolves_the_convrot_file_then_the_fp8_one():
+def rows_published(monkeypatch):
+ monkeypatch.setattr(tpq, "te_int8_convrot_published", lambda *a, **k: True)
+
+
+def test_wan_int8_resolves_the_convrot_file_then_the_fp8_one(rows_published):
for name in ("wan2.2-ti2v-5b", "wan2.2-t2v-a14b", "wan2.1-t2v-1.3b", "wan2.1-t2v-14b"):
source = tpq.resolve_te_prequant_source(_family(name), "text_encoder", "int8")
assert source.location == WAN_REPO
@@ -177,7 +182,7 @@ def test_wan_int8_resolves_the_convrot_file_then_the_fp8_one():
), name
-def test_wan_int8_needs_no_lm_head_trim(monkeypatch):
+def test_wan_int8_needs_no_lm_head_trim(monkeypatch, rows_published):
"""UMT5EncoderModel has no lm_head, so the keep-lm_head switch cannot push it onto the fp8 file."""
from core.inference.diffusion_text_encoder_trim import KEEP_LM_HEAD_ENV