#
Loaders

There are many weights to train adapter neural networks for diffusion models, such as

- Textual Inversion
- LoRA
- Hypernetworks

Such adapter neural networks often only consist of a fraction of the number of weights compared to the pretrained model and as such are very portable. The Diffusers library offers an easy-to-use API to load such adapter neural networks via the `loaders.py` module.

Note: This module is still highly experimental and prone to future changes.

##
LoaderMixins

###
UNet2DConditionLoadersMixin

###
class diffusers.loaders.UNet2DConditionLoadersMixin

< source >

( )

####
load_attn_procs

< source >

( pretrained_model_name_or_path_or_dict: typing.Union[str, typing.Dict[str, torch.Tensor]] **kwargs )

Parameters

- pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`) — Can be either:
  - A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids should have an organization name, like `google/ddpm-celebahq-256`.
  - A path to a directory containing model weights saved using `~ModelMixin.save_config`, e.g., `./my_model_directory/`.
  - A torch state dict.
- cache_dir (`Union[str, os.PathLike]`, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
- force_download (`bool`, optional, defaults to `False`) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
- resume_download (`bool`, optional, defaults to `False`) — Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.
- proxies (`Dict[str, str]`, optional) — A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
- local_files_only(`bool`, optional, defaults to `False`) — Whether or not to only look at local files (i.e., do not try to download the model).
- use_auth_token (`str` or bool, optional) — The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated when running `diffusers-cli login` (stored in `~/.huggingface`).
- revision (`str`, optional, defaults to `"main"`) — The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git.
- subfolder (`str`, optional, defaults to `""`) — In case the relevant files are located inside a subfolder of the model repo (either remote in huggingface.co or downloaded locally), you can specify the folder name here.
- mirror (`str`, optional) — Mirror source to accelerate downloads in China. If you are from China and have an accessibility problem, you can set this option to resolve it. Note that we do not guarantee the timeliness or safety. Please refer to the mirror site for more information.

Load pretrained attention processor layers into `UNet2DConditionModel`. Attention processor layers have to be defined in cross_attention.py and be a `torch.nn.Module` class.

This function is experimental and might change in the future

It is required to be logged in (`huggingface-cli login`) when you want to use private or gated models.

Activate the special “offline-mode” to use this method in a firewalled environment.

####
save_attn_procs

< source >

( save_directory: typing.Union[str, os.PathLike] is_main_process: bool = True weights_name: str = 'pytorch_lora_weights.bin' save_function: typing.Callable = None )

Parameters

- save_directory (`str` or `os.PathLike`) — Directory to which to save. Will be created if it doesn’t exist.
- is_main_process (`bool`, optional, defaults to `True`) — Whether the process calling this is the main process or not. Useful when in distributed training like TPUs and need to call this function on all processes. In this case, set `is_main_process=True` only on the main process to avoid race conditions.
- save_function (`Callable`) — The function to use to save the state dictionary. Useful on distributed training like TPUs when one need to replace `torch.save` by another method. Can be configured with the environment variable `DIFFUSERS_SAVE_MODE`.

Save an attention procesor to a directory, so that it can be re-loaded using the `[load_attn_procs()](/docs/diffusers/v0.12.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs)` method.