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: accept a quoted local training base and name single-file checkpoints in the refusal (#14236)

Daniel Han9836ddc68a1a
diff --git a/studio/backend/core/training/diffusion_train_common.py b/studio/backend/core/training/diffusion_train_common.py
index c9c6a0b14a6..bf2965986bc 100644
--- a/studio/backend/core/training/diffusion_train_common.py
+++ b/studio/backend/core/training/diffusion_train_common.py
@@ -38,7 +38,7 @@ from core.inference.diffusion_families import (
from core.inference.diffusion_torchao_patches import install_torchao_int_mm_patch
from core.inference.video_families import _FAMILIES as _VIDEO_REGISTRY
from core.inference.video_families import detect_video_family, supported_video_family_names
-from utils.paths.path_utils import drop_appledouble_metadata
+from utils.paths.path_utils import drop_appledouble_metadata, is_appledouble_metadata
from core.training.diffusion_samples import SAMPLE_FAMILIES, validate_sample_settings
@@ -2095,7 +2095,57 @@ def _assert_trusted_base_model(base_model: str, *, allow_modular: bool = False)
)
# An existing LOCAL base is loaded as a full pipeline, which needs an index; reject a non-pipeline local dir
# before /diffusion/start frees the GPU models.
- _assert_local_base_is_pipeline(base_model, allow_modular = allow_modular)
+ try:
+ _assert_local_base_is_pipeline(base_model, allow_modular = allow_modular)
+ except ValueError as e:
+ shape = _single_file_shape(base_model)
+ if shape is None:
+ raise
+ # Echo only the caller's own path: this runs before the cached-path authorization, so naming a file found
+ # inside the folder would disclose it.
+ what = "is a single-file checkpoint" if shape == "file" else "holds single-file checkpoints"
+ raise ValueError(
+ f"'{base_model}' {what}, which cannot be a training base yet: training loads the base "
+ f"as a diffusers pipeline folder (one subfolder per component). Pick a base from the "
+ f"list instead."
+ ) from e
+
+
+_SINGLE_FILE_SUFFIXES = (".safetensors", ".ckpt", ".gguf")
+# LoRA weights, not a base: a trained Studio / diffusers LoRA folder holds pytorch_lora_weights.safetensors.
+_LORA_WEIGHT_NAMES = ("pytorch_lora_weights.safetensors", "adapter_model.safetensors")
+_NOT_A_CHECKPOINT_FOLDER = (
+ "model_index.json",
+ "modular_model_index.json",
+ "config.json",
+ "adapter_config.json",
+)
+
+
+def _single_file_shape(base_model: str) -> Optional[str]:
+ """ "file" / "folder" when a local base is, or holds (an A1111 / ComfyUI models folder), a single-file
+ checkpoint, else None. Wording only, never a verdict."""
+ try:
+ path = Path(str(base_model or "").strip()).expanduser()
+ if path.is_file():
+ return "file" if _is_checkpoint_name(path) else None
+ if not path.is_dir() or any((path / m).exists() for m in _NOT_A_CHECKPOINT_FOLDER):
+ return None
+ with os.scandir(path) as entries:
+ if any(_is_checkpoint_name(Path(e.path)) and e.is_file() for e in entries):
+ return "folder"
+ except OSError:
+ pass
+ return None
+
+
+def _is_checkpoint_name(path: Path) -> bool:
+ name = path.name.lower()
+ return (
+ name.endswith(_SINGLE_FILE_SUFFIXES)
+ and name not in _LORA_WEIGHT_NAMES
+ and not is_appledouble_metadata(path)
+ )
# One writer and one reader for BOTH trainers, so an SDXL and a DiT run resume from the same bundle shape.
diff --git a/studio/backend/models/training.py b/studio/backend/models/training.py
index da106b19738..3f9b638e332 100644
--- a/studio/backend/models/training.py
+++ b/studio/backend/models/training.py
@@ -104,6 +104,15 @@ def _resolve_inventory_handles(values):
return [_resolve_inventory_handle(item) if isinstance(item, str) else item for item in values]
+def _unquote_pasted_path(value):
+ """Windows "Copy as path" quotes the path; quoted, it never exists and reads as an untrusted repo id."""
+ if isinstance(value, str):
+ text = value.strip()
+ if len(text) >= 2 and text[0] == text[-1] and text[0] in "\"'":
+ return text[1:-1]
+ return value
+
+
def _resolve_inventory_handle(value: str) -> str:
"""Lazy: `models.inference` is large and the CLI imports this module without needing it."""
try:
@@ -976,6 +985,7 @@ class DiffusionTrainingStartRequest(BaseModel):
base_model: str = Field(..., description = "HF repo id or local path to a trainable base")
# Unresolved, family detection and `_assert_trusted_base_model` read `ref:...` as a Hub id.
+ _unquote_the_base = field_validator("base_model", mode = "before")(_unquote_pasted_path)
_resolve_the_base_handle = field_validator("base_model")(_resolve_inventory_handle)
data_dir: str = Field(..., description = "Folder of training images (+ captions)")
output_dir: str = Field(..., description = "Directory to write the LoRA .safetensors into")
diff --git a/studio/backend/tests/test_diffusion_base_precision.py b/studio/backend/tests/test_diffusion_base_precision.py
index fd3d5f6f78a..39f6cdb819f 100644
--- a/studio/backend/tests/test_diffusion_base_precision.py
+++ b/studio/backend/tests/test_diffusion_base_precision.py
@@ -1078,6 +1078,68 @@ def test_assert_trusted_base_model_rejects_local_non_pipeline(tmp_path):
common._assert_trusted_base_model("evil/base")
+def test_quoted_local_base_is_unquoted_before_the_trust_gate(tmp_path):
+ # #9605: Windows "Copy as path" quotes the folder.
+ base = tmp_path / "my sdxl"
+ base.mkdir()
+ (base / "model_index.json").write_text(
+ '{"_class_name":"DiffusionPipeline","transformer":["diffusers","Transformer2DModel"]}'
+ )
+ (base / "transformer").mkdir()
+ (base / "transformer" / "config.json").write_text("{}")
+ (base / "transformer" / "diffusion_pytorch_model.safetensors").write_bytes(b"x")
+ for pasted in (f'"{base}"', f"'{base}'", f' "{base}" '):
+ req = DiffusionTrainingStartRequest(base_model = pasted, data_dir = "d", output_dir = "o")
+ assert req.base_model == str(base)
+ common._assert_trusted_base_model(req.base_model) # no raise
+ for written in ("unsloth/sdxl-base", str(base), '"half', 'a"b"', "\"x'"):
+ req = DiffusionTrainingStartRequest(base_model = written, data_dir = "d", output_dir = "o")
+ assert req.base_model == written
+
+
+def test_single_file_training_base_names_the_checkpoint(tmp_path):
+ # #9605: still refused, but the refusal says why, echoing only the caller's own path.
+ models = tmp_path / "stable-diffusion"
+ models.mkdir()
+ ckpt = models / "sd_xl_base_1.0.safetensors"
+ ckpt.write_bytes(b"x")
+ for base, what in (
+ (models, "holds single-file checkpoints"),
+ (ckpt, "is a single-file checkpoint"),
+ ):
+ with pytest.raises(ValueError, match = what) as err:
+ common._assert_trusted_base_model(str(base))
+ assert f"'{base}' {what}" in str(err.value)
+ with pytest.raises(ValueError) as err:
+ common._assert_trusted_base_model(str(models))
+ assert ckpt.name not in str(err.value)
+ # A macOS AppleDouble sidecar is not a checkpoint.
+ sidecar = tmp_path / "sidecar-only"
+ sidecar.mkdir()
+ (sidecar / "._sd_xl.safetensors").write_bytes(b"\x00\x05\x16\x07" + b"\x00" * 28)
+ # Only the wrapper goes: a name that really ends in a space keeps it.
+ req = DiffusionTrainingStartRequest(base_model = f'"{models} "', data_dir = "d", output_dir = "o")
+ assert req.base_model == f"{models} "
+ # The SDXL repo ships a root checkpoint beside model_index.json.
+ component = tmp_path / "unet"
+ component.mkdir()
+ (component / "config.json").write_text("{}")
+ (component / "diffusion_pytorch_model.safetensors").write_bytes(b"x")
+ partial = tmp_path / "partial-sdxl"
+ partial.mkdir()
+ (partial / "model_index.json").write_text(
+ '{"_class_name":"StableDiffusionXLPipeline","unet":["diffusers","UNet2DConditionModel"]}'
+ )
+ (partial / "sd_xl_base_1.0.safetensors").write_bytes(b"x")
+ lora = tmp_path / "my_lora"
+ lora.mkdir()
+ (lora / "pytorch_lora_weights.safetensors").write_bytes(b"x")
+ for base in (component, partial, lora, sidecar, tmp_path / "empty"):
+ base.mkdir(exist_ok = True)
+ with pytest.raises(ValueError, match = "not a diffusers pipeline directory"):
+ common._assert_trusted_base_model(str(base))
+
+
def test_dit_accelerator_missing_reason_and_info_hide_train_without_a_gpu(monkeypatch):
# Clicking Start on a GPU-less host evicted the Images pipeline, pulled the text encoders, then died in the child: the 4-bit quantizer needs an accelerator. Reject up front.
import torch