Spaces:
Running
on
Zero
Running
on
Zero
Update model.py
Browse files
model.py
CHANGED
|
@@ -140,8 +140,18 @@ class ModelHandler:
|
|
| 140 |
print("Loading LoRA weights...")
|
| 141 |
self.pipeline.load_lora_weights(Config.REPO_ID, weight_name=Config.LORA_FILENAME)
|
| 142 |
|
| 143 |
-
# ---
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# 6. Load Preprocessors
|
| 147 |
print("Loading Preprocessors (Zoe, LineArt)...")
|
|
@@ -157,7 +167,7 @@ class ModelHandler:
|
|
| 157 |
|
| 158 |
try:
|
| 159 |
# Convert PIL to CV2
|
| 160 |
-
cv2_img = cv2.cvtColor(np.array(image), cv2.
|
| 161 |
faces = self.app.get(cv2_img)
|
| 162 |
|
| 163 |
if len(faces) == 0:
|
|
|
|
| 140 |
print("Loading LoRA weights...")
|
| 141 |
self.pipeline.load_lora_weights(Config.REPO_ID, weight_name=Config.LORA_FILENAME)
|
| 142 |
|
| 143 |
+
# --- NEW: Fuse LoRA at build time with fixed strength ---
|
| 144 |
+
print(f"Fusing LoRA with scale {Config.LORA_STRENGTH}...")
|
| 145 |
+
self.pipeline.fuse_lora(lora_scale=Config.LORA_STRENGTH)
|
| 146 |
+
print(" [OK] LoRA fused.")
|
| 147 |
+
|
| 148 |
+
# --- NEW: Optimize UNet with torch.compile ---
|
| 149 |
+
try:
|
| 150 |
+
print("Compiling UNet with torch.compile...")
|
| 151 |
+
self.pipeline.unet = torch.compile(self.pipeline.unet, mode="reduce-overhead", fullgraph=True)
|
| 152 |
+
print(" [OK] UNet compiled.")
|
| 153 |
+
except Exception as e:
|
| 154 |
+
print(f" [WARNING] torch.compile failed: {e}. Running without compilation.")
|
| 155 |
|
| 156 |
# 6. Load Preprocessors
|
| 157 |
print("Loading Preprocessors (Zoe, LineArt)...")
|
|
|
|
| 167 |
|
| 168 |
try:
|
| 169 |
# Convert PIL to CV2
|
| 170 |
+
cv2_img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB_BGR)
|
| 171 |
faces = self.app.get(cv2_img)
|
| 172 |
|
| 173 |
if len(faces) == 0:
|