r""" Set the attention processor to use. Args: processor (`AttnProcessor`): The attention processor to use. _remove_lora (`bool`, *optional*, defaults to `False`): Set to `True` to remove LoRA layers from the model.
(self, processor: "AttnProcessor", _remove_lora: bool = False)
| 358 | self.set_processor(processor) |
| 359 | |
| 360 | def set_processor(self, processor: "AttnProcessor", _remove_lora: bool = False) -> None: |
| 361 | r""" |
| 362 | Set the attention processor to use. |
| 363 | |
| 364 | Args: |
| 365 | processor (`AttnProcessor`): |
| 366 | The attention processor to use. |
| 367 | _remove_lora (`bool`, *optional*, defaults to `False`): |
| 368 | Set to `True` to remove LoRA layers from the model. |
| 369 | """ |
| 370 | if not USE_PEFT_BACKEND and hasattr(self, "processor") and _remove_lora and self.to_q.lora_layer is not None: |
| 371 | deprecate( |
| 372 | "set_processor to offload LoRA", |
| 373 | "0.26.0", |
| 374 | "In detail, removing LoRA layers via calling `set_default_attn_processor` is deprecated. Please make sure to call `pipe.unload_lora_weights()` instead.", |
| 375 | ) |
| 376 | # TODO(Patrick, Sayak) - this can be deprecated once PEFT LoRA integration is complete |
| 377 | # We need to remove all LoRA layers |
| 378 | # Don't forget to remove ALL `_remove_lora` from the codebase |
| 379 | for module in self.modules(): |
| 380 | if hasattr(module, "set_lora_layer"): |
| 381 | module.set_lora_layer(None) |
| 382 | |
| 383 | # if current processor is in `self._modules` and if passed `processor` is not, we need to |
| 384 | # pop `processor` from `self._modules` |
| 385 | if ( |
| 386 | hasattr(self, "processor") |
| 387 | and isinstance(self.processor, torch.nn.Module) |
| 388 | and not isinstance(processor, torch.nn.Module) |
| 389 | ): |
| 390 | logger.info(f"You are removing possibly trained weights of {self.processor} with {processor}") |
| 391 | self._modules.pop("processor") |
| 392 | |
| 393 | self.processor = processor |
| 394 | |
| 395 | def get_processor(self, return_deprecated_lora: bool = False) -> "AttentionProcessor": |
| 396 | r""" |
no outgoing calls
no test coverage detected