primerz commited on
Commit
2ad8261
·
verified ·
1 Parent(s): cd32279

Upload 2 files

Browse files
Files changed (1) hide show
  1. models.py +32 -57
models.py CHANGED
@@ -176,65 +176,40 @@ def load_controlnets():
176
  def load_sdxl_pipeline(controlnets):
177
  """
178
  Load SDXL pipeline with InstantID support.
179
- controlnets MUST be a list: [identitynet, depthnet]
180
- Following the working example from examplewithface.py
181
  """
182
  print("Loading SDXL checkpoint with InstantID pipeline...")
183
- try:
184
- model_path = download_model_with_retry(MODEL_REPO, MODEL_FILES['checkpoint'])
185
-
186
- # CRITICAL: from_single_file doesn't auto-wrap lists in MultiControlNetModel
187
- # We must do it explicitly (unlike from_pretrained which does it automatically)
188
- if isinstance(controlnets, list) and len(controlnets) > 1:
189
- from diffusers.models.controlnets.multicontrolnet import MultiControlNetModel
190
- print(f" Wrapping {len(controlnets)} ControlNets in MultiControlNetModel...")
191
- controlnet_for_pipeline = MultiControlNetModel(controlnets)
192
- else:
193
- controlnet_for_pipeline = controlnets[0] if isinstance(controlnets, list) else controlnets
194
-
195
- # Use InstantID-enabled pipeline
196
- pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_single_file(
197
- model_path,
198
- controlnet=controlnet_for_pipeline,
199
- torch_dtype=dtype,
200
- use_safetensors=True
201
- ).to(device)
202
-
203
- # Load IP-Adapter weights for InstantID
204
- print("Loading IP-Adapter for InstantID...")
205
- ip_adapter_path = download_model_with_retry(
206
- "InstantX/InstantID",
207
- "ip-adapter.bin"
208
- )
209
- pipe.load_ip_adapter_instantid(ip_adapter_path)
210
- print(" [OK] IP-Adapter loaded (scale will be set dynamically)")
211
-
212
- print(" [OK] InstantID pipeline loaded successfully")
213
- return pipe, True
214
-
215
- except Exception as e:
216
- print(f" [ERROR] Could not load InstantID pipeline: {e}")
217
- import traceback
218
- traceback.print_exc()
219
-
220
- # Fallback to standard pipeline
221
- print(" [WARNING] Falling back to standard SDXL pipeline (no InstantID)")
222
- from diffusers import StableDiffusionXLControlNetImg2ImgPipeline
223
-
224
- # Wrap in MultiControlNetModel for fallback too
225
- if isinstance(controlnets, list) and len(controlnets) > 1:
226
- from diffusers.models.controlnets.multicontrolnet import MultiControlNetModel
227
- controlnet_for_pipeline = MultiControlNetModel(controlnets)
228
- else:
229
- controlnet_for_pipeline = controlnets[0] if isinstance(controlnets, list) else controlnets
230
-
231
- pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
232
- "stabilityai/stable-diffusion-xl-base-1.0",
233
- controlnet=controlnet_for_pipeline,
234
- torch_dtype=dtype,
235
- use_safetensors=True
236
- ).to(device)
237
- return pipe, False
238
 
239
 
240
  # Global variable to track LORA fusion state (like in working example)
 
176
  def load_sdxl_pipeline(controlnets):
177
  """
178
  Load SDXL pipeline with InstantID support.
179
+ EXACTLY following working example: from_pretrained with controlnet list
 
180
  """
181
  print("Loading SDXL checkpoint with InstantID pipeline...")
182
+
183
+ # Load VAE (like working example line 128)
184
+ print("Loading VAE...")
185
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=dtype)
186
+ print(" [OK] VAE loaded")
187
+
188
+ # Load pipeline EXACTLY like working example (line 134-137)
189
+ # Uses from_pretrained, NOT from_single_file!
190
+ # Passes controlnet list directly, NO MultiControlNetModel wrapper!
191
+ print("Loading InstantID pipeline from_pretrained (like working example)...")
192
+ pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained(
193
+ "frankjoshua/albedobaseXL_v21",
194
+ vae=vae,
195
+ controlnet=controlnets, # Pass list directly [identitynet, depthnet]
196
+ torch_dtype=dtype
197
+ )
198
+ pipe = pipe.to(device)
199
+ print(" [OK] Pipeline loaded with from_pretrained")
200
+
201
+ # Load IP-Adapter weights for InstantID (like working example line 139)
202
+ print("Loading IP-Adapter for InstantID...")
203
+ ip_adapter_path = download_model_with_retry(
204
+ "InstantX/InstantID",
205
+ "ip-adapter.bin"
206
+ )
207
+ pipe.load_ip_adapter_instantid(ip_adapter_path)
208
+ pipe.set_ip_adapter_scale(0.8) # Initial scale like working example line 140
209
+ print(" [OK] IP-Adapter loaded (initial scale 0.8)")
210
+
211
+ print(" [OK] InstantID pipeline loaded successfully (matches working example)")
212
+ return pipe, True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
 
215
  # Global variable to track LORA fusion state (like in working example)