Spaces:
Runtime error
Runtime error
Update models.py
Browse files
models.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
Models.py - Following examplewithface.py EXACTLY
|
| 3 |
NO MultiControlNetModel wrapper!
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
import torch
|
| 7 |
import time
|
|
@@ -119,7 +119,7 @@ def load_sdxl_pipeline(controlnets):
|
|
| 119 |
pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained(
|
| 120 |
"frankjoshua/albedobaseXL_v21",
|
| 121 |
vae=vae,
|
| 122 |
-
controlnet=controlnets, #
|
| 123 |
torch_dtype=dtype
|
| 124 |
)
|
| 125 |
print(" [OK] Pipeline created with direct controlnet list")
|
|
@@ -160,7 +160,8 @@ def load_lora(pipe):
|
|
| 160 |
|
| 161 |
def fuse_lora_with_scale(pipe, lora_scale):
|
| 162 |
"""
|
| 163 |
-
|
|
|
|
| 164 |
"""
|
| 165 |
global lora_path_cached
|
| 166 |
|
|
@@ -168,20 +169,27 @@ def fuse_lora_with_scale(pipe, lora_scale):
|
|
| 168 |
return False
|
| 169 |
|
| 170 |
try:
|
| 171 |
-
# Unload previous
|
| 172 |
try:
|
|
|
|
| 173 |
pipe.unload_lora_weights()
|
| 174 |
except:
|
| 175 |
pass
|
| 176 |
|
| 177 |
-
# Load LoRA
|
| 178 |
-
print(f" [LORA] Loading
|
| 179 |
pipe.load_lora_weights(lora_path_cached)
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
return True
|
| 183 |
except Exception as e:
|
| 184 |
-
print(f" [ERROR] LoRA failed: {e}")
|
|
|
|
|
|
|
| 185 |
return False
|
| 186 |
|
| 187 |
|
|
@@ -363,7 +371,7 @@ def setup_ip_adapter(pipe, image_encoder):
|
|
| 363 |
|
| 364 |
print(" [OK] IP-Adapter fully loaded with InstantID architecture")
|
| 365 |
print(f" - Resampler: 4 layers, 20 heads, 16 output tokens")
|
| 366 |
-
print(f" - Face embeddings: 512D
|
| 367 |
|
| 368 |
return image_proj_model, True
|
| 369 |
|
|
|
|
| 1 |
"""
|
| 2 |
Models.py - Following examplewithface.py EXACTLY
|
| 3 |
NO MultiControlNetModel wrapper!
|
| 4 |
+
Using fuse_lora with scale (examplewithface.py line 267)
|
| 5 |
"""
|
| 6 |
import torch
|
| 7 |
import time
|
|
|
|
| 119 |
pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained(
|
| 120 |
"frankjoshua/albedobaseXL_v21",
|
| 121 |
vae=vae,
|
| 122 |
+
controlnet=controlnets, # ↠LIST [identitynet, zoedepthnet] - NO WRAPPER!
|
| 123 |
torch_dtype=dtype
|
| 124 |
)
|
| 125 |
print(" [OK] Pipeline created with direct controlnet list")
|
|
|
|
| 160 |
|
| 161 |
def fuse_lora_with_scale(pipe, lora_scale):
|
| 162 |
"""
|
| 163 |
+
Following examplewithface.py lines 266-267:
|
| 164 |
+
Load LoRA weights and FUSE them into the model
|
| 165 |
"""
|
| 166 |
global lora_path_cached
|
| 167 |
|
|
|
|
| 169 |
return False
|
| 170 |
|
| 171 |
try:
|
| 172 |
+
# Unload and unfuse previous LoRA if exists
|
| 173 |
try:
|
| 174 |
+
pipe.unfuse_lora()
|
| 175 |
pipe.unload_lora_weights()
|
| 176 |
except:
|
| 177 |
pass
|
| 178 |
|
| 179 |
+
# Load LoRA weights (examplewithface.py line 266)
|
| 180 |
+
print(f" [LORA] Loading weights...")
|
| 181 |
pipe.load_lora_weights(lora_path_cached)
|
| 182 |
+
|
| 183 |
+
# CRITICAL: Fuse LoRA into model (examplewithface.py line 267)
|
| 184 |
+
print(f" [LORA] Fusing with scale {lora_scale}...")
|
| 185 |
+
pipe.fuse_lora(lora_scale)
|
| 186 |
+
print(f" [OK] LoRA fused into model")
|
| 187 |
|
| 188 |
return True
|
| 189 |
except Exception as e:
|
| 190 |
+
print(f" [ERROR] LoRA fusion failed: {e}")
|
| 191 |
+
import traceback
|
| 192 |
+
traceback.print_exc()
|
| 193 |
return False
|
| 194 |
|
| 195 |
|
|
|
|
| 371 |
|
| 372 |
print(" [OK] IP-Adapter fully loaded with InstantID architecture")
|
| 373 |
print(f" - Resampler: 4 layers, 20 heads, 16 output tokens")
|
| 374 |
+
print(f" - Face embeddings: 512D → 16x2048D")
|
| 375 |
|
| 376 |
return image_proj_model, True
|
| 377 |
|