text
stringlengths 0
5.54k
|
---|
optional): The dimension of the class_labels input when |
class_embed_type="projection". Required when class_embed_type="projection". |
class_embeddings_concat (bool, optional, defaults to False): Whether to concatenate the time |
embeddings with the class embeddings. |
mid_block_only_cross_attention (bool, optional, defaults to None): |
Whether to use cross attention with the mid block when using the UNetMidBlock2DSimpleCrossAttn. If |
only_cross_attention is given as a single boolean and mid_block_only_cross_attention is None, the |
only_cross_attention value is used as the value for mid_block_only_cross_attention. Default to False |
otherwise. disable_freeu < source > ( ) Disables the FreeU mechanism. enable_freeu < source > ( s1 s2 b1 b2 ) Parameters s1 (float) — |
Scaling factor for stage 1 to attenuate the contributions of the skip features. This is done to |
mitigate the “oversmoothing effect” in the enhanced denoising process. s2 (float) — |
Scaling factor for stage 2 to attenuate the contributions of the skip features. This is done to |
mitigate the “oversmoothing effect” in the enhanced denoising process. b1 (float) — Scaling factor for stage 1 to amplify the contributions of backbone features. b2 (float) — Scaling factor for stage 2 to amplify the contributions of backbone features. Enables the FreeU mechanism from https://arxiv.org/abs/2309.11497. The suffixes after the scaling factors represent the stage blocks where they are being applied. Please refer to the official repository for combinations of values that |
are known to work well for different pipelines such as Stable Diffusion v1, v2, and Stable Diffusion XL. forward < source > ( sample: FloatTensor timestep: Union encoder_hidden_states: Tensor class_labels: Optional = None timestep_cond: Optional = None attention_mask: Optional = None cross_attention_kwargs: Optional = None added_cond_kwargs: Optional = None down_block_additional_residuals: Optional = None mid_block_additional_residual: Optional = None down_intrablock_additional_residuals: Optional = None encoder_attention_mask: Optional = None return_dict: bool = True ) → UNet2DConditionOutput or tuple Parameters sample (torch.FloatTensor) — |
The noisy input tensor with the following shape (batch, channel, height, width). timestep (torch.FloatTensor or float or int) — The number of timesteps to denoise an input. encoder_hidden_states (torch.FloatTensor) — |
The encoder hidden states with shape (batch, sequence_length, feature_dim). class_labels (torch.Tensor, optional, defaults to None) — |
Optional class labels for conditioning. Their embeddings will be summed with the timestep embeddings. |
timestep_cond — (torch.Tensor, optional, defaults to None): |
Conditional embeddings for timestep. If provided, the embeddings will be summed with the samples passed |
through the self.time_embedding layer to obtain the timestep embeddings. attention_mask (torch.Tensor, optional, defaults to None) — |
An attention mask of shape (batch, key_tokens) is applied to encoder_hidden_states. If 1 the mask |
is kept, otherwise if 0 it is discarded. Mask will be converted into a bias, which adds large |
negative values to the attention scores corresponding to “discard” tokens. cross_attention_kwargs (dict, optional) — |
A kwargs dictionary that if specified is passed along to the AttentionProcessor as defined under |
self.processor in |
diffusers.models.attention_processor. |
added_cond_kwargs — (dict, optional): |
A kwargs dictionary containing additional embeddings that if specified are added to the embeddings that |
are passed along to the UNet blocks. |
down_block_additional_residuals — (tuple of torch.Tensor, optional): |
A tuple of tensors that if specified are added to the residuals of down unet blocks. |
mid_block_additional_residual — (torch.Tensor, optional): |
A tensor that if specified is added to the residual of the middle unet block. encoder_attention_mask (torch.Tensor) — |
A cross-attention mask of shape (batch, sequence_length) is applied to encoder_hidden_states. If |
True the mask is kept, otherwise if False it is discarded. Mask will be converted into a bias, |
which adds large negative values to the attention scores corresponding to “discard” tokens. return_dict (bool, optional, defaults to True) — |
Whether or not to return a UNet2DConditionOutput instead of a plain |
tuple. cross_attention_kwargs (dict, optional) — |
A kwargs dictionary that if specified is passed along to the AttnProcessor. |
added_cond_kwargs — (dict, optional): |
A kwargs dictionary containin additional embeddings that if specified are added to the embeddings that |
are passed along to the UNet blocks. down_block_additional_residuals (tuple of torch.Tensor, optional) — |
additional residuals to be added to UNet long skip connections from down blocks to up blocks for |
example from ControlNet side model(s) mid_block_additional_residual (torch.Tensor, optional) — |
additional residual to be added to UNet mid block output, for example from ControlNet side model down_intrablock_additional_residuals (tuple of torch.Tensor, optional) — |
additional residuals to be added within UNet down blocks, for example from T2I-Adapter side model(s) Returns |
UNet2DConditionOutput or tuple |
If return_dict is True, an UNet2DConditionOutput is returned, otherwise |
a tuple is returned where the first element is the sample tensor. |
The UNet2DConditionModel forward method. fuse_qkv_projections < source > ( ) Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query, |
key, value) are fused. For cross-attention modules, key and value projection matrices are fused. This API is 🧪 experimental. set_attention_slice < source > ( slice_size ) Parameters slice_size (str or int or list(int), optional, defaults to "auto") — |
When "auto", input to the attention heads is halved, so attention is computed in two steps. If |
"max", maximum amount of memory is saved by running only one slice at a time. If a number is |
provided, uses as many slices as attention_head_dim // slice_size. In this case, attention_head_dim |
must be a multiple of slice_size. Enable sliced attention computation. When this option is enabled, the attention module splits the input tensor in slices to compute attention in |
several steps. This is useful for saving some memory in exchange for a small decrease in speed. set_attn_processor < source > ( processor: Union _remove_lora = False ) Parameters processor (dict of AttentionProcessor or only AttentionProcessor) — |
The instantiated processor class or a dictionary of processor classes that will be set as the processor |
for all Attention layers. |
If processor is a dict, the key needs to define the path to the corresponding cross attention |
processor. This is strongly recommended when setting trainable attention processors. Sets the attention processor to use to compute attention. set_default_attn_processor < source > ( ) Disables custom attention processors and sets the default attention implementation. unfuse_qkv_projections < source > ( ) Disables the fused QKV projection if enabled. This API is 🧪 experimental. UNet2DConditionOutput class diffusers.models.unet_2d_condition.UNet2DConditionOutput < source > ( sample: FloatTensor = None ) Parameters sample (torch.FloatTensor of shape (batch_size, num_channels, height, width)) — |
The hidden states output conditioned on encoder_hidden_states input. Output of last layer of model. The output of UNet2DConditionModel. FlaxUNet2DConditionModel class diffusers.FlaxUNet2DConditionModel < source > ( sample_size: int = 32 in_channels: int = 4 out_channels: int = 4 down_block_types: Tuple = ('CrossAttnDownBlock2D', 'CrossAttnDownBlock2D', 'CrossAttnDownBlock2D', 'DownBlock2D') up_block_types: Tuple = ('UpBlock2D', 'CrossAttnUpBlock2D', 'CrossAttnUpBlock2D', 'CrossAttnUpBlock2D') only_cross_attention: Union = False block_out_channels: Tuple = (320, 640, 1280, 1280) layers_per_block: int = 2 attention_head_dim: Union = 8 num_attention_heads: Union = None cross_attention_dim: int = 1280 dropout: float = 0.0 use_linear_projection: bool = False dtype: dtype = <class 'jax.numpy.float32'> flip_sin_to_cos: bool = True freq_shift: int = 0 use_memory_efficient_attention: bool = False split_head_dim: bool = False transformer_layers_per_block: Union = 1 addition_embed_type: Optional = None addition_time_embed_dim: Optional = None addition_embed_type_num_heads: int = 64 projection_class_embeddings_input_dim: Optional = None parent: Union = <flax.linen.module._Sentinel object at 0x7fb48fdbfdf0> name: Optional = None ) Parameters sample_size (int, optional) — |
The size of the input sample. in_channels (int, optional, defaults to 4) — |
The number of channels in the input sample. out_channels (int, optional, defaults to 4) — |
The number of channels in the output. down_block_types (Tuple[str], optional, defaults to ("FlaxCrossAttnDownBlock2D", "FlaxCrossAttnDownBlock2D", "FlaxCrossAttnDownBlock2D", "FlaxDownBlock2D")) — |
The tuple of downsample blocks to use. up_block_types (Tuple[str], optional, defaults to ("FlaxUpBlock2D", "FlaxCrossAttnUpBlock2D", "FlaxCrossAttnUpBlock2D", "FlaxCrossAttnUpBlock2D")) — |
The tuple of upsample blocks to use. block_out_channels (Tuple[int], optional, defaults to (320, 640, 1280, 1280)) — |
The tuple of output channels for each block. layers_per_block (int, optional, defaults to 2) — |
The number of layers per block. attention_head_dim (int or Tuple[int], optional, defaults to 8) — |
The dimension of the attention heads. num_attention_heads (int or Tuple[int], optional) — |
The number of attention heads. cross_attention_dim (int, optional, defaults to 768) — |
The dimension of the cross attention features. dropout (float, optional, defaults to 0) — |
Dropout probability for down, up and bottleneck blocks. flip_sin_to_cos (bool, optional, defaults to True) — |
Whether to flip the sin to cos in the time embedding. freq_shift (int, optional, defaults to 0) — The frequency shift to apply to the time embedding. use_memory_efficient_attention (bool, optional, defaults to False) — |
Enable memory efficient attention as described here. split_head_dim (bool, optional, defaults to False) — |
Whether to split the head dimension into a new axis for the self-attention computation. In most cases, |
enabling this flag should speed up the computation for Stable Diffusion 2.x and Stable Diffusion XL. A conditional 2D UNet model that takes a noisy sample, conditional state, and a timestep and returns a sample |
shaped output. This model inherits from FlaxModelMixin. Check the superclass documentation for it’s generic methods |
implemented for all models (such as downloading or saving). This model is also a Flax Linen flax.linen.Module |
subclass. Use it as a regular Flax Linen module and refer to the Flax documentation for all matters related to its |
general usage and behavior. Inherent JAX features such as the following are supported: Just-In-Time (JIT) compilation Automatic Differentiation Vectorization Parallelization FlaxUNet2DConditionOutput class diffusers.models.unet_2d_condition_flax.FlaxUNet2DConditionOutput < source > ( sample: Array ) Parameters sample (jnp.ndarray of shape (batch_size, num_channels, height, width)) — |
The hidden states output conditioned on encoder_hidden_states input. Output of last layer of model. The output of FlaxUNet2DConditionModel. replace < source > ( **updates ) “Returns a new object replacing the specified fields with new values. |
How to use Stable Diffusion in Apple Silicon (M1/M2) |
🤗 Diffusers is compatible with Apple silicon for Stable Diffusion inference, using the PyTorch mps device. These are the steps you need to follow to use your M1 or M2 computer with Stable Diffusion. |
Requirements |
Mac computer with Apple silicon (M1/M2) hardware. |
macOS 12.6 or later (13.0 or later recommended). |
arm64 version of Python. |
PyTorch 1.13. You can install it with pip or conda using the instructions in https://pytorch.org/get-started/locally/. |
Inference Pipeline |
The snippet below demonstrates how to use the mps backend using the familiar to() interface to move the Stable Diffusion pipeline to your M1 or M2 device. |
We recommend to “prime” the pipeline using an additional one-time pass through it. This is a temporary workaround for a weird issue we have detected: the first inference pass produces slightly different results than subsequent ones. You only need to do this pass once, and it’s ok to use just one inference step and discard the result. |
Copied |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.