text
stringlengths
0
5.54k
Returns
StableDiffusionPipelineOutput or tuple
StableDiffusionPipelineOutput if return_dict is True, otherwise a tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of bools denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the safe...
Function invoked when calling the pipeline for generation.
enable_sequential_cpu_offload
<
source
>
(
)
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
torch.device('meta') and loaded to GPU only when their specific submodule has its forward` method called.
Models 🤗 Diffusers provides pretrained models for popular algorithms and modules to create custom diffusion systems. The primary function of models is to denoise an input sample as modeled by the distribution pθ(xt−1∣xt)p_{\theta}(x_{t-1}|x_{t})pθ​(xt−1​∣xt​). All models are built from the base ModelMixin class which...
saving models. config_name (str) — Filename to save a model to when calling save_pretrained(). active_adapters < source > ( ) Gets the current list of active adapters of the model. If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft add_adapter < source > ( adapter_config adapter_name: str = 'default' ) Parameters adapter_config ([~peft.PeftConfig]) —
The configuration of the adapter to add; supported adapters are non-prefix tuning and adaption prompt
methods. adapter_name (str, optional, defaults to "default") —
The name of the adapter to add. If no name is passed, a default name is assigned to the adapter. Adds a new adapter to the current model for training. If no adapter name is passed, a default name is assigned
to the adapter to follow the convention of the PEFT library. If you are not familiar with adapters and PEFT methods, we invite you to read more about them in the PEFT
documentation. disable_adapters < source > ( ) Disable all adapters attached to the model and fallback to inference with the base model only. If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft disable_gradient_checkpointing < source > ( ) Deactivates gradient checkpointing for the current model (may be referred to as activation checkpointing or
checkpoint activations in other frameworks). disable_xformers_memory_efficient_attention < source > ( ) Disable memory efficient attention from xFormers. enable_adapters < source > ( ) Enable adapters that are attached to the model. The model will use self.active_adapters() to retrieve the
list of adapters to enable. If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft enable_gradient_checkpointing < source > ( ) Activates gradient checkpointing for the current model (may be referred to as activation checkpointing or
checkpoint activations in other frameworks). enable_xformers_memory_efficient_attention < source > ( attention_op: Optional = None ) Parameters attention_op (Callable, optional) —
Override the default None operator for use as op argument to the
memory_efficient_attention()
function of xFormers. Enable memory efficient attention from xFormers. When this option is enabled, you should observe lower GPU memory usage and a potential speed up during
inference. Speed up during training is not guaranteed. ⚠️ When memory efficient attention and sliced attention are both enabled, memory efficient attention takes
precedent. Examples: Copied >>> import torch
>>> from diffusers import UNet2DConditionModel
>>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp
>>> model = UNet2DConditionModel.from_pretrained(
... "stabilityai/stable-diffusion-2-1", subfolder="unet", torch_dtype=torch.float16
... )
>>> model = model.to("cuda")
>>> model.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp) from_pretrained < source > ( pretrained_model_name_or_path: Union **kwargs ) Parameters pretrained_model_name_or_path (str or os.PathLike, optional) —
Can be either:
A string, the model id (for example google/ddpm-celebahq-256) of a pretrained model hosted on
the Hub.
A path to a directory (for example ./my_model_directory) containing the model weights saved
with save_pretrained().
cache_dir (Union[str, os.PathLike], optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used. torch_dtype (str or torch.dtype, optional) —
Override the default torch.dtype and load the model with another dtype. If "auto" is passed, the
dtype is automatically derived from the model’s weights. 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 resume downloading the model weights and configuration files. If set to False, any
incompletely downloaded files are deleted. proxies (Dict[str, str], optional) —
A dictionary of proxy servers to use by protocol or endpoint, for example, {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request. output_loading_info (bool, optional, defaults to False) —
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages. local_files_only(bool, optional, defaults to False) —
Whether to only load local model weights and configuration files or not. If set to True, the model
won’t be downloaded from the Hub. token (str or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True, the token generated from
diffusers-cli login (stored in ~/.huggingface) is used. revision (str, optional, defaults to "main") —
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
allowed by Git. from_flax (bool, optional, defaults to False) —
Load the model weights from a Flax checkpoint save file. subfolder (str, optional, defaults to "") —
The subfolder location of a model file within a larger model repository on the Hub or locally. mirror (str, optional) —
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
information. device_map (str or Dict[str, Union[int, str, torch.device]], optional) —
A map that specifies where each submodule should go. It doesn’t need to be defined for each
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
same device.
Set device_map="auto" to have 🤗 Accelerate automatically compute the most optimized device_map. For
more information about each option see designing a device
map. max_memory (Dict, optional) —
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
each GPU and the available CPU RAM if unset. offload_folder (str or os.PathLike, optional) —
The path to offload weights if device_map contains the value "disk". offload_state_dict (bool, optional) —
If True, temporarily offloads the CPU state dict to the hard drive to avoid running out of CPU RAM if
the weight of the CPU state dict + the biggest shard of the checkpoint does not fit. Defaults to True
when there is some disk offload. low_cpu_mem_usage (bool, optional, defaults to True if torch version >= 1.9.0 else False) —
Speed up model loading only loading the pretrained weights and not initializing the weights. This also
tries to not use more than 1x model size in CPU memory (including peak memory) while loading the model.
Only supported for PyTorch >= 1.9.0. If you are using an older version of PyTorch, setting this
argument to True will raise an error. variant (str, optional) —
Load weights from a specified variant filename such as "fp16" or "ema". This is ignored when
loading from_flax. use_safetensors (bool, optional, defaults to None) —
If set to None, the safetensors weights are downloaded if they’re available and if the
safetensors library is installed. If set to True, the model is forcibly loaded from safetensors
weights. If set to False, safetensors weights are not loaded. Instantiate a pretrained PyTorch model from a pretrained model configuration. The model is set in evaluation mode - model.eval() - by default, and dropout modules are deactivated. To