Diffusers documentation

Consistency Decoder

You are viewing v0.27.2 version. A newer version v0.31.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

< >

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

The consistency decoder used with DALL-E 3.

Examples:

>>> import torch
>>> from diffusers import StableDiffusionPipeline, 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

< >

( *args **kwargs )

disable_slicing

< >

( )

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

disable_tiling

< >

( )

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

enable_slicing

< >

( )

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

< >

( 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

< >

( sample: FloatTensor sample_posterior: bool = False return_dict: bool = True generator: Optional = None ) β†’ DecoderOutput or tuple

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.
  • generator (torch.Generator, optional, defaults to None) — Generator to use for sampling.

Returns

DecoderOutput or tuple

If return_dict is True, a DecoderOutput is returned, otherwise a plain tuple is returned.

set_attn_processor

< >

( processor: Union )

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

< >

( )

Disables custom attention processors and sets the default attention implementation.

tiled_encode

< >

( x: FloatTensor return_dict: bool = True ) β†’ ~models.consistency_decoder_vae.ConsistencyDecoderVAEOutput or tuple

Parameters

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

Returns

~models.consistency_decoder_vae.ConsistencyDecoderVAEOutput or tuple

If return_dict is True, a ~models.consistency_decoder_vae.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.