From db5746acc73759b983908de1f4b0ca6f0131ea39 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 1 Jul 2026 07:33:53 +0000 Subject: [PATCH] Studio diffusion LoRA: sanitize dots out of adapter aliases The LoRA alias is used as the diffusers PEFT adapter name, and PEFT rejects names containing "." (module name can't contain "."). sanitize_alias kept dots, so a LoRA whose filename carries a version tag (e.g. Qwen-Image-2512-Lightning-8steps-V1.0-bf16) failed to apply with a 400. Replace dots too; the alias stays a valid native filename stem. Adds regression coverage for internal dots. --- studio/backend/core/inference/diffusion_lora.py | 9 ++++++--- studio/backend/tests/test_diffusion_lora.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/studio/backend/core/inference/diffusion_lora.py b/studio/backend/core/inference/diffusion_lora.py index bb4fa1f0a9..630857323d 100644 --- a/studio/backend/core/inference/diffusion_lora.py +++ b/studio/backend/core/inference/diffusion_lora.py @@ -79,15 +79,18 @@ def sanitize_alias(raw: str) -> str: """Deterministic, filesystem- and prompt-tag-safe alias from an id/stem. The native `` tag resolves NAME as a filename stem, so the alias must - contain no path separators, spaces, colons, or angle brackets. Collisions across - sources are broken by the caller (materialize_native_dir) with a numeric suffix. + contain no path separators, spaces, colons, or angle brackets. It is also used as the + diffusers PEFT adapter name, which additionally forbids "." (PEFT treats it as a module + path separator), so dots are replaced too -- many real LoRA filenames carry a version + like "V1.0". Collisions across sources are broken by the caller (materialize_native_dir + / the diffusers manager) with a numeric suffix. """ stem = raw.rsplit("/", 1)[-1] for ext in _ALL_EXTS: if stem.lower().endswith(ext): stem = stem[: -len(ext)] break - stem = re.sub(r"[^A-Za-z0-9._-]+", "_", stem).strip("._-") + stem = re.sub(r"[^A-Za-z0-9_-]+", "_", stem).strip("_-") return stem or "lora" diff --git a/studio/backend/tests/test_diffusion_lora.py b/studio/backend/tests/test_diffusion_lora.py index 4bf8b85f0e..de5aefefcc 100644 --- a/studio/backend/tests/test_diffusion_lora.py +++ b/studio/backend/tests/test_diffusion_lora.py @@ -20,6 +20,13 @@ def test_sanitize_alias_strips_path_ext_and_unsafe_chars(): assert dl.sanitize_alias("owner/repo-name") == "repo-name" assert dl.sanitize_alias("weird:<>chars.gguf") == "weird_chars" assert dl.sanitize_alias("") == "lora" + # Internal dots (version tags like "V1.0") must be replaced: the alias becomes a + # diffusers PEFT adapter name and PEFT rejects "." in module/adapter names. + assert ( + dl.sanitize_alias("Qwen-Image-2512-Lightning-8steps-V1.0-bf16") + == "Qwen-Image-2512-Lightning-8steps-V1_0-bf16" + ) + assert "." not in dl.sanitize_alias("model.v1.0.safetensors") def test_inject_prompt_tags_appends_with_spacing():