(self, *args, **kwargs)
| 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…