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 <lora:NAME:w> filename stem. Adds regression coverage for internal dots.
This commit is contained in:
parent
80feeb1f0c
commit
db5746acc7
2 changed files with 13 additions and 3 deletions
|
|
@ -79,15 +79,18 @@ def sanitize_alias(raw: str) -> str:
|
|||
"""Deterministic, filesystem- and prompt-tag-safe alias from an id/stem.
|
||||
|
||||
The native `<lora:NAME:w>` 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"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue