#
Consistency Decoder

Consistency decoder can be used to decode the latents from the denoising UNet in the StableDiffusionPipeline. This decoder was introduced in the DALL-E 3 technical report.

The original codebase can be found at openai/consistencydecoder.

Inference is only supported for 2 iterations as of now.

The pipeline could not have been contributed without the help of madebyollin and mrsteyk from this issue.

##
ConsistencyDecoderVAE

###
class diffusers.ConsistencyDecoderVAE

< source >

( scaling_factor = 0.18215 latent_channels = 4 encoder_act_fn = 'silu' encoder_block_out_channels = (128, 256, 512, 512) encoder_double_z = True encoder_down_block_types = ('DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D') encoder_in_channels = 3 encoder_layers_per_block = 2 encoder_norm_num_groups = 32 encoder_out_channels = 4 decoder_add_attention = False decoder_block_out_channels = (320, 640, 1024, 1024) decoder_down_block_types = ('ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D') decoder_downsample_padding = 1 decoder_in_channels = 7 decoder_layers_per_block = 3 decoder_norm_eps = 1e-05 decoder_norm_num_groups = 32 decoder_num_train_timesteps = 1024 decoder_out_channels = 6 decoder_resnet_time_scale_shift = 'scale_shift' decoder_time_embedding_type = 'learned' decoder_up_block_types = ('ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D') )

The consistency decoder used with DALL-E 3.

Examples:

    >>> import torch
    >>> from diffusers import DiffusionPipeline, ConsistencyDecoderVAE

    >>> vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=torch.float16)
    >>> pipe = StableDiffusionPipeline.from_pretrained(
    ...     "runwayml/stable-diffusion-v1-5", vae=vae, torch_dtype=torch.float16
    ... ).to("cuda")

    >>> pipe("horse", generator=torch.manual_seed(0)).images

####
wrapper

< source >

( *args **kwargs )

####
disable_slicing

< source >

( )

Disable sliced VAE decoding. If `enable_slicing` was previously enabled, this method will go back to computing decoding in one step.

####
disable_tiling

< source >

( )

Disable tiled VAE decoding. If `enable_tiling` was previously enabled, this method will go back to computing decoding in one step.

####
enable_slicing

< source >

( )

Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.

####
enable_tiling

< source >

( use_tiling: bool = True )

Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow processing larger images.

####
forward

< source >

( sample: FloatTensor sample_posterior: bool = False return_dict: bool = True generator: typing.Optional[torch._C.Generator] = None )

Parameters

- sample (`torch.FloatTensor`) — Input sample.
- sample_posterior (`bool`, optional, defaults to `False`) — Whether to sample from the posterior.
- return_dict (`bool`, optional, defaults to `True`) — Whether or not to return a `DecoderOutput` instead of a plain tuple.

####
set_attn_processor

< source >

( processor: typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor, typing.Dict[str, typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor]]] _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.

####
tiled_encode

< source >

( x: FloatTensor return_dict: bool = True ) →
`ConsistencyDecoderVAEOutput` or `tuple`

Parameters

- x (`torch.FloatTensor`) — Input batch of images.
- return_dict (`bool`, optional, defaults to `True`) — Whether or not to return a `ConsistencyDecoderVAEOutput` instead of a plain tuple.

Returns

`ConsistencyDecoderVAEOutput` or `tuple`

If return_dict is True, a `ConsistencyDecoderVAEOutput` is returned, otherwise a plain `tuple` is returned.

Encode a batch of images using a tiled encoder.

When this option is enabled, the VAE will split the input tensor into tiles to compute encoding in several steps. This is useful to keep memory use constant regardless of image size. The end result of tiled encoding is different from non-tiled encoding because each tile uses a different encoder. To avoid tiling artifacts, the tiles overlap and are blended together to form a smooth output. You may still see tile-sized changes in the output, but they should be much less noticeable.