r""" Loads a LoRA adapter into the underlying model. Parameters: pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`): Can be either: - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrai
(
self, pretrained_model_name_or_path_or_dict, prefix="transformer", hotswap: bool = False, **kwargs
)
| 78 | return _func_optionally_disable_offloading(_pipeline=_pipeline) |
| 79 | |
| 80 | def load_lora_adapter( |
| 81 | self, pretrained_model_name_or_path_or_dict, prefix="transformer", hotswap: bool = False, **kwargs |
| 82 | ): |
| 83 | r""" |
| 84 | Loads a LoRA adapter into the underlying model. |
| 85 | |
| 86 | Parameters: |
| 87 | pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`): |
| 88 | Can be either: |
| 89 | |
| 90 | - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on |
| 91 | the Hub. |
| 92 | - A path to a *directory* (for example `./my_model_directory`) containing the model weights saved |
| 93 | with [`ModelMixin.save_pretrained`]. |
| 94 | - A [torch state |
| 95 | dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict). |
| 96 | |
| 97 | prefix (`str`, *optional*): Prefix to filter the state dict. |
| 98 | |
| 99 | cache_dir (`str | os.PathLike`, *optional*): |
| 100 | Path to a directory where a downloaded pretrained model configuration is cached if the standard cache |
| 101 | is not used. |
| 102 | force_download (`bool`, *optional*, defaults to `False`): |
| 103 | Whether or not to force the (re-)download of the model weights and configuration files, overriding the |
| 104 | cached versions if they exist. |
| 105 | proxies (`dict[str, str]`, *optional*): |
| 106 | A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128', |
| 107 | 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request. |
| 108 | local_files_only (`bool`, *optional*, defaults to `False`): |
| 109 | Whether to only load local model weights and configuration files or not. If set to `True`, the model |
| 110 | won't be downloaded from the Hub. |
| 111 | token (`str` or *bool*, *optional*): |
| 112 | The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from |
| 113 | `diffusers-cli login` (stored in `~/.huggingface`) is used. |
| 114 | revision (`str`, *optional*, defaults to `"main"`): |
| 115 | The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier |
| 116 | allowed by Git. |
| 117 | subfolder (`str`, *optional*, defaults to `""`): |
| 118 | The subfolder location of a model file within a larger model repository on the Hub or locally. |
| 119 | network_alphas (`dict[str, float]`): |
| 120 | The value of the network alpha used for stable learning and preventing underflow. This value has the |
| 121 | same meaning as the `--network_alpha` option in the kohya-ss trainer script. Refer to [this |
| 122 | link](https://github.com/darkstorm2150/sd-scripts/blob/main/docs/train_network_README-en.md#execute-learning). |
| 123 | low_cpu_mem_usage (`bool`, *optional*): |
| 124 | Speed up model loading by only loading the pretrained LoRA weights and not initializing the random |
| 125 | weights. |
| 126 | hotswap : (`bool`, *optional*) |
| 127 | Defaults to `False`. Whether to substitute an existing (LoRA) adapter with the newly loaded adapter |
| 128 | in-place. This means that, instead of loading an additional adapter, this will take the existing |
| 129 | adapter weights and replace them with the weights of the new adapter. This can be faster and more |
| 130 | memory efficient. However, the main advantage of hotswapping is that when the model is compiled with |
| 131 | torch.compile, loading the new adapter does not require recompilation of the model. When using |
| 132 | hotswapping, the passed `adapter_name` should be the name of an already loaded adapter. |
| 133 | |
| 134 | If the new adapter and the old adapter have different ranks and/or LoRA alphas (i.e. scaling), you need |
| 135 | to call an additional method before loading the adapter: |
| 136 | |
| 137 | ```py |