Spaces:
Running on Zero
Running on Zero
Robust LoRA load: fall back to UNet-only keys when kohya TE conversion fails
Browse files- pipeline_manager.py +22 -7
pipeline_manager.py
CHANGED
|
@@ -234,14 +234,29 @@ def _build_base_pipeline(cfg):
|
|
| 234 |
# Apply LoRA if this entry is a LoRA model.
|
| 235 |
if cfg.get("type") == "lora":
|
| 236 |
scale = float(cfg.get("lora_scale", 0.8))
|
|
|
|
| 237 |
if cfg.get("lora_repo_id"):
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
try:
|
| 246 |
pipe.fuse_lora(lora_scale=scale)
|
| 247 |
except Exception as e: # noqa
|
|
|
|
| 234 |
# Apply LoRA if this entry is a LoRA model.
|
| 235 |
if cfg.get("type") == "lora":
|
| 236 |
scale = float(cfg.get("lora_scale", 0.8))
|
| 237 |
+
# Resolve to a local .safetensors path (HF repo or direct/Civitai URL).
|
| 238 |
if cfg.get("lora_repo_id"):
|
| 239 |
+
from huggingface_hub import hf_hub_download
|
| 240 |
+
local = hf_hub_download(cfg["lora_repo_id"], cfg["lora_weight_name"]) \
|
| 241 |
+
if cfg.get("lora_weight_name") else None
|
| 242 |
+
if local is None:
|
| 243 |
+
pipe.load_lora_weights(cfg["lora_repo_id"])
|
| 244 |
+
local = "__loaded__"
|
| 245 |
+
else:
|
| 246 |
+
local = _download_url(cfg.get("lora_url"))
|
| 247 |
+
|
| 248 |
+
if local and local != "__loaded__":
|
| 249 |
+
try:
|
| 250 |
+
pipe.load_lora_weights(local)
|
| 251 |
+
except Exception as e: # noqa
|
| 252 |
+
# Some Civitai/kohya LoRAs carry text-encoder keys diffusers can't
|
| 253 |
+
# convert ("list index out of range"). Retry with UNet-only keys —
|
| 254 |
+
# the UNet holds most of the character/style effect.
|
| 255 |
+
print(f"[lora] full load failed ({e}); retrying UNet-only")
|
| 256 |
+
from safetensors.torch import load_file
|
| 257 |
+
sd = load_file(local)
|
| 258 |
+
sd = {k: v for k, v in sd.items() if not k.startswith("lora_te")}
|
| 259 |
+
pipe.load_lora_weights(sd)
|
| 260 |
try:
|
| 261 |
pipe.fuse_lora(lora_scale=scale)
|
| 262 |
except Exception as e: # noqa
|