Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -253,6 +253,12 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 253 |
# keys exist in this family either (PEFT's native format keeps `lora_alpha` in a sidecar `adapter_config.json`
|
| 254 |
# we never fetch, not as tensors), so these fall to the same `alpha = rank` default every other module gets.
|
| 255 |
native_ab = re.compile(r"^(.+)\.(lora_[AB])\.\w+\.weight$")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
# Family B (Kohya-style): `lora_unet_blocks_N_TARGET.(lora_down|lora_up|alpha)` — covers SB and Fluid
|
| 258 |
# Enhancer. `lora_down`/`lora_up` are the same A/B convention under a different name.
|
|
@@ -275,6 +281,12 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 275 |
elif name.startswith("blocks."):
|
| 276 |
name = "transformer_blocks." + name[len("blocks."):]
|
| 277 |
name = name.replace("final_layer.adaln_proj.linear", "norm_out.linear")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
name = name.replace(".attn.out_proj", ".attn.to_out.0")
|
| 279 |
name = name.replace(".mlp.fc2", ".ff.net.2")
|
| 280 |
name = name.replace(".mlp.fc1", ".ff.net.0.proj")
|
|
@@ -336,6 +348,17 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 336 |
print(f"[lora-convert] '{module_base}' isn't a real target — skipping", flush=True)
|
| 337 |
continue
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
match = standard_ab.match(key)
|
| 340 |
if match:
|
| 341 |
raw_base, ab = match.groups()
|
|
|
|
| 253 |
# keys exist in this family either (PEFT's native format keeps `lora_alpha` in a sidecar `adapter_config.json`
|
| 254 |
# we never fetch, not as tensors), so these fall to the same `alpha = rank` default every other module gets.
|
| 255 |
native_ab = re.compile(r"^(.+)\.(lora_[AB])\.\w+\.weight$")
|
| 256 |
+
# Confirmed against `lora1`'s own debug dump (`transformer_blocks.0.attn.to_k.lora_down`,
|
| 257 |
+
# `transformer_blocks.0.adaln_proj.linear.lora_down`): already-diffusers-native base names, but with Kohya's
|
| 258 |
+
# `lora_down`/`lora_up` suffixes and no `.weight` — distinct from `native_ab` above (needs an adapter-name
|
| 259 |
+
# segment plus `.weight`) and from `kohya_ab` below (needs the fused `lora_unet_blocks_N_TARGET` prefix). No
|
| 260 |
+
# qkv-splitting needed here either way: these base names already have separate `to_q`/`to_k`/`to_v`.
|
| 261 |
+
native_kohya_suffix_ab = re.compile(r"^(?:diffusion_model\.)?(.+)\.(lora_down|lora_up)$")
|
| 262 |
|
| 263 |
# Family B (Kohya-style): `lora_unet_blocks_N_TARGET.(lora_down|lora_up|alpha)` — covers SB and Fluid
|
| 264 |
# Enhancer. `lora_down`/`lora_up` are the same A/B convention under a different name.
|
|
|
|
| 281 |
elif name.startswith("blocks."):
|
| 282 |
name = "transformer_blocks." + name[len("blocks."):]
|
| 283 |
name = name.replace("final_layer.adaln_proj.linear", "norm_out.linear")
|
| 284 |
+
name = name.replace("final_layer.video_out", "proj_out")
|
| 285 |
+
name = name.replace("final_layer.audio_out", "audio_proj_out")
|
| 286 |
+
name = name.replace("final_layer.norm", "norm_out.norm")
|
| 287 |
+
name = name.replace("video_patch_proj", "proj_in")
|
| 288 |
+
name = name.replace("audio_patch_proj", "audio_proj_in")
|
| 289 |
+
name = name.replace("condition_proj", "context_embedder")
|
| 290 |
name = name.replace(".attn.out_proj", ".attn.to_out.0")
|
| 291 |
name = name.replace(".mlp.fc2", ".ff.net.2")
|
| 292 |
name = name.replace(".mlp.fc1", ".ff.net.0.proj")
|
|
|
|
| 348 |
print(f"[lora-convert] '{module_base}' isn't a real target — skipping", flush=True)
|
| 349 |
continue
|
| 350 |
|
| 351 |
+
match = native_kohya_suffix_ab.match(key)
|
| 352 |
+
if match:
|
| 353 |
+
raw_base, direction = match.groups()
|
| 354 |
+
module_base = rename_base(raw_base) # covers the final_layer.*/patch_proj/condition_proj renames too
|
| 355 |
+
ab = "lora_A" if direction == "lora_down" else "lora_B"
|
| 356 |
+
if f"{module_base}.weight" in base_shapes:
|
| 357 |
+
out[f"{LORA_KEY_PREFIX}.{module_base}.{ab}.weight"] = tensor
|
| 358 |
+
else:
|
| 359 |
+
print(f"[lora-convert] '{raw_base}' renamed to '{module_base}', which isn't a real target — skipping", flush=True)
|
| 360 |
+
continue
|
| 361 |
+
|
| 362 |
match = standard_ab.match(key)
|
| 363 |
if match:
|
| 364 |
raw_base, ab = match.groups()
|