Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -207,6 +207,15 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 207 |
standard_ab = re.compile(r"^(?:diffusion_model\.)?(.+)\.(lora_[AB])\.weight$")
|
| 208 |
standard_alpha = re.compile(r"^(?:diffusion_model\.)?(.+)\.alpha$")
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
# Family B (Kohya-style): `lora_unet_blocks_N_TARGET.(lora_down|lora_up|alpha)` — covers SB and Fluid
|
| 211 |
# Enhancer. `lora_down`/`lora_up` are the same A/B convention under a different name.
|
| 212 |
kohya_ab = re.compile(
|
|
@@ -280,6 +289,15 @@ def _convert_diffusion_model_lora(raw: dict, base_shapes: dict, swap_fc1: bool)
|
|
| 280 |
# adapter's dtype to match the wrapped base layer's.
|
| 281 |
tensor = raw_tensor.to(torch.bfloat16)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
match = standard_ab.match(key)
|
| 284 |
if match:
|
| 285 |
raw_base, ab = match.groups()
|
|
|
|
| 207 |
standard_ab = re.compile(r"^(?:diffusion_model\.)?(.+)\.(lora_[AB])\.weight$")
|
| 208 |
standard_alpha = re.compile(r"^(?:diffusion_model\.)?(.+)\.alpha$")
|
| 209 |
|
| 210 |
+
# Family C: already-diffusers-native, PEFT's own serialization layout — `{module}.lora_A.<adapter>.weight`,
|
| 211 |
+
# confirmed against the debug dump's `transformer_blocks.0.*`/`token_refiner.refiner_blocks.*` shapes: no
|
| 212 |
+
# fused `qkv_proj` to split (`to_q`/`to_k`/`to_v` are already separate), no `mlp.fc1`/`fc2` to rename (already
|
| 213 |
+
# `ff.net.0.proj`/`ff.net.2`). The `<adapter>` segment is whatever adapter name the file happened to be saved
|
| 214 |
+
# under (e.g. "default") — discarded, since each file gets its own `adapter_name` here regardless. No `.alpha`
|
| 215 |
+
# keys exist in this family either (PEFT's native format keeps `lora_alpha` in a sidecar `adapter_config.json`
|
| 216 |
+
# we never fetch, not as tensors), so these fall to the same `alpha = rank` default every other module gets.
|
| 217 |
+
native_ab = re.compile(r"^(.+)\.(lora_[AB])\.\w+\.weight$")
|
| 218 |
+
|
| 219 |
# Family B (Kohya-style): `lora_unet_blocks_N_TARGET.(lora_down|lora_up|alpha)` — covers SB and Fluid
|
| 220 |
# Enhancer. `lora_down`/`lora_up` are the same A/B convention under a different name.
|
| 221 |
kohya_ab = re.compile(
|
|
|
|
| 289 |
# adapter's dtype to match the wrapped base layer's.
|
| 290 |
tensor = raw_tensor.to(torch.bfloat16)
|
| 291 |
|
| 292 |
+
match = native_ab.match(key)
|
| 293 |
+
if match:
|
| 294 |
+
module_base, ab = match.groups()
|
| 295 |
+
if f"{module_base}.weight" in base_shapes:
|
| 296 |
+
out[f"{LORA_KEY_PREFIX}.{module_base}.{ab}.weight"] = tensor
|
| 297 |
+
else:
|
| 298 |
+
print(f"[lora-convert] '{module_base}' isn't a real target — skipping", flush=True)
|
| 299 |
+
continue
|
| 300 |
+
|
| 301 |
match = standard_ab.match(key)
|
| 302 |
if match:
|
| 303 |
raw_base, ab = match.groups()
|