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: match diffusion training access facts to the no-token mirror fetch (#16216)

Daniel Han7af1d001e03a
diff --git a/studio/backend/core/training/diffusion_train_common.py b/studio/backend/core/training/diffusion_train_common.py
index b0742cc08de..df8e40efc72 100644
--- a/studio/backend/core/training/diffusion_train_common.py
+++ b/studio/backend/core/training/diffusion_train_common.py
@@ -946,20 +946,35 @@ def training_precision_preflight_error(resolved_family: str, base_precision: str
return None
-def _training_mirror_access_specs(repo: str, note: str = "") -> dict[str, dict[str, Any]]:
- """Access facts for a gated vendor base and its mirror, using the trainer's fetch policy."""
+def _training_fetch_repo(base: str, token: Optional[str] = None) -> str:
from core.inference.diffusion_families import (
+ _is_local_path,
mirror_repo,
prefer_ungated_mirror,
upstream_is_gated,
)
+ fetched = prefer_ungated_mirror(base, token)
+ # Anonymous training ignores partial caches of gated upstreams.
+ if (
+ not token
+ and upstream_is_gated(base)
+ and not _is_local_path(base)
+ and not os.environ.get("UNSLOTH_DIFFUSION_NO_MIRROR", "").strip()
+ ):
+ fetched = mirror_repo(base) or fetched
+ return fetched
+
+
+def _training_mirror_access_specs(repo: str, note: str = "") -> dict[str, dict[str, Any]]:
+ from core.inference.diffusion_families import mirror_repo, upstream_is_gated
+
mirror = mirror_repo(repo)
if not mirror or not upstream_is_gated(repo):
return {}
facts = {}
for shown in (repo, mirror):
- fetched = prefer_ungated_mirror(shown)
+ fetched = _training_fetch_repo(shown)
gated = upstream_is_gated(fetched)
explanation = (
f"Downloads from {fetched}. The original model license still applies."
@@ -1320,25 +1335,10 @@ class DiffusionLoraConfig:
# A blank Hub token (the Unsloth default when none is configured) must load anonymously, not as an explicit
# empty credential.
token = self.hf_token.strip() if isinstance(self.hf_token, str) else self.hf_token
- from core.inference.diffusion_families import (
- _is_local_path,
- mirror_repo,
- prefer_ungated_mirror,
- upstream_is_gated,
- )
-
if resolved_family == "sdxl":
fetch_base_model = self.base_model
else:
- fetch_base_model = prefer_ungated_mirror(self.base_model, token or None)
- # Gated upstream with no token only: prefer the mirror even with a cached shard; UNSLOTH_DIFFUSION_NO_MIRROR still wins, and a local clone wins over both.
- if (
- not token
- and upstream_is_gated(self.base_model)
- and not _is_local_path(self.base_model)
- and not os.environ.get("UNSLOTH_DIFFUSION_NO_MIRROR", "").strip()
- ):
- fetch_base_model = mirror_repo(self.base_model) or fetch_base_model
+ fetch_base_model = _training_fetch_repo(self.base_model, token or None)
# Blank caption_column means "text", matching the start route's fingerprint.
caption_column = str(self.caption_column or "").strip() or "text"
bucketing = None if self.bucketing is None else _coerce_bool(self.bucketing)
diff --git a/studio/backend/tests/test_diffusion_base_precision.py b/studio/backend/tests/test_diffusion_base_precision.py
index c66d3714f38..c69ba58722d 100644
--- a/studio/backend/tests/test_diffusion_base_precision.py
+++ b/studio/backend/tests/test_diffusion_base_precision.py
@@ -1111,3 +1111,34 @@ def test_lowp_probe_skips_off_cuda_and_raises_on_a_failing_gemm():
# The seed is set before conversion: the probe must not move the training draws.
assert torch.equal(torch.get_rng_state(), cpu_state)
assert torch.equal(torch.cuda.get_rng_state(), cuda_state)
+
+
+ "vendor",
+ [
+ "black-forest-labs/FLUX.1-dev",
+ "black-forest-labs/FLUX.2-dev",
+ "black-forest-labs/FLUX.2-klein-base-9B",
+ ],
+)
+def test_training_access_facts_follow_no_token_mirror_with_cached_vendor_shard(
+ monkeypatch, tmp_path, vendor
+):
+ from core.inference import diffusion_families as families
+ from utils import hf_cache_settings
+
+ monkeypatch.delenv("UNSLOTH_DIFFUSION_NO_MIRROR", raising = False)
+ snapshot = (
+ tmp_path / ("models--" + vendor.replace("/", "--")) / "snapshots" / "rev" / "transformer"
+ )
+ snapshot.mkdir(parents = True)
+ (snapshot / "diffusion_pytorch_model-00001-of-00003.safetensors").write_bytes(b"x")
+ monkeypatch.setattr(hf_cache_settings, "active_hf_hub_cache", lambda: str(tmp_path))
+ assert families._upstream_is_cached(vendor)
+
+ mirror = families.mirror_repo(vendor)
+ facts = common._training_mirror_access_specs(vendor)[vendor]
+ fetched = _cfg(base_model = vendor, hf_token = "").normalized().fetch_base_model
+ assert fetched == mirror
+ assert facts["gated"] is False
+ assert mirror in facts["note"]