MCPcopy
hub / github.com/huggingface/diffusers / wrapper

Function wrapper

src/diffusers/utils/peft_utils.py:293–320  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

291 def decorator(forward_fn):
292 @functools.wraps(forward_fn)
293 def wrapper(self, *args, **kwargs):
294 from . import USE_PEFT_BACKEND
295
296 lora_scale = 1.0
297 attention_kwargs = kwargs.get(kwargs_name)
298
299 if attention_kwargs is not None:
300 attention_kwargs = attention_kwargs.copy()
301 kwargs[kwargs_name] = attention_kwargs
302 lora_scale = attention_kwargs.pop("scale", 1.0)
303
304 if not USE_PEFT_BACKEND and lora_scale != 1.0:
305 logger.warning(
306 f"Passing `scale` via `{kwargs_name}` when not using the PEFT backend is ineffective."
307 )
308
309 # Apply LoRA scaling if using PEFT backend
310 if USE_PEFT_BACKEND:
311 scale_lora_layers(self, lora_scale)
312
313 try:
314 # Execute the forward pass
315 result = forward_fn(self, *args, **kwargs)
316 return result
317 finally:
318 # Always unscale, even if forward pass raises an exception
319 if USE_PEFT_BACKEND:
320 unscale_lora_layers(self, lora_scale)
321
322 return wrapper
323

Callers

nothing calls this directly

Calls 4

scale_lora_layersFunction · 0.85
unscale_lora_layersFunction · 0.85
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…