mamungtai-sat pormungtai commited on
Commit
884da37
·
1 Parent(s): 5cc4c4c

Make clip_skip best-effort (retry without it on version incompat) (#9)

Browse files

- Make clip_skip best-effort (retry without it on version incompat) (f5aec9817f0426d29708536c9a1e28fa9f430880)


Co-authored-by: pormungtailaw <pormungtai@users.noreply.huggingface.co>

Files changed (1) hide show
  1. pipeline_manager.py +14 -4
pipeline_manager.py CHANGED
@@ -255,6 +255,18 @@ def _face_embeds(image):
255
  # ---------------------------------------------------------------------------
256
  # Generation
257
  # ---------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
258
  def run_generation(cfg, mode, prompt, negative_prompt, ref_image,
259
  steps, guidance, denoise, ip_scale, width, height, seed):
260
  """Run one generation. MUST be called inside a @spaces.GPU context."""
@@ -309,8 +321,7 @@ def run_generation(cfg, mode, prompt, negative_prompt, ref_image,
309
  call.pop("width"); call.pop("height")
310
  call["image"] = ref_image.convert("RGB")
311
  call["strength"] = float(denoise)
312
- out = i2i(**call).images[0]
313
- return out
314
 
315
  elif mode == "ip_adapter":
316
  if ref_image is None:
@@ -327,5 +338,4 @@ def run_generation(cfg, mode, prompt, negative_prompt, ref_image,
327
  embeds = _face_embeds(ref_image).to(DEVICE)
328
  call["ip_adapter_image_embeds"] = [embeds]
329
 
330
- out = pipe(**call).images[0]
331
- return out
 
255
  # ---------------------------------------------------------------------------
256
  # Generation
257
  # ---------------------------------------------------------------------------
258
+ def _safe_call(pipe_obj, call):
259
+ """Run the pipeline; if clip_skip trips a version incompatibility, retry without it."""
260
+ try:
261
+ return pipe_obj(**call).images[0]
262
+ except (AttributeError, TypeError) as e:
263
+ if "clip_skip" in call:
264
+ print(f"[clip_skip] disabled for this run due to: {e}")
265
+ call.pop("clip_skip", None)
266
+ return pipe_obj(**call).images[0]
267
+ raise
268
+
269
+
270
  def run_generation(cfg, mode, prompt, negative_prompt, ref_image,
271
  steps, guidance, denoise, ip_scale, width, height, seed):
272
  """Run one generation. MUST be called inside a @spaces.GPU context."""
 
321
  call.pop("width"); call.pop("height")
322
  call["image"] = ref_image.convert("RGB")
323
  call["strength"] = float(denoise)
324
+ return _safe_call(i2i, call)
 
325
 
326
  elif mode == "ip_adapter":
327
  if ref_image is None:
 
338
  embeds = _face_embeds(ref_image).to(DEVICE)
339
  call["ip_adapter_image_embeds"] = [embeds]
340
 
341
+ return _safe_call(pipe, call)