Diffusers documentation

Consistency Decoder

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Consistency Decoder

Consistency decoder は、StableDiffusionPipeline のデノイジング UNet から潜在変数をデコードするために使用できます。このデコーダーは、DALL-E 3 技術レポート で紹介されました。

元のコードベースはopenai/consistencydecoderで確認できます。

現時点では、推論は2回の反復のみサポートされています。

このパイプラインは、このイシューからのmadebyollinとmrsteykの助けがなければ貢献されていませんでした。

ConsistencyDecoderVAE

class diffusers.ConsistencyDecoderVAE

< >

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

DALL-E 3 と併せて使用される consistency decoder。

例:

>>> import torch
>>> from diffusers import StableDiffusionPipeline, ConsistencyDecoderVAE

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

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

decode

< >

( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = Truenum_inference_steps: int = 2 ) → DecoderOutput | tuple[torch.Tensor]

パラメータ

  • z (torch.Tensor) — 入力潜在ベクトル。
  • generator (torch.Generator | None) — 乱数生成器。デフォルトは None です。
  • return_dict (bool) — 出力を辞書として返すかどうか。デフォルトは True です。
  • num_inference_steps (int) — 推論ステップ数。デフォルト値は 2 です。

戻り値

DecoderOutput | tuple[torch.Tensor]

デコードされた出力。

consistency decoder VAE モデルを使用して、入力潜在ベクトル z をデコードします。

encode

< >

( x: Tensorreturn_dict: bool = True )

パラメータ

  • x (torch.Tensor) — 画像の入力バッチ。
  • return_dict (bool、省略可能、デフォルトはTrue) — ConsistencyDecoderVAEOutputを返すかどうか。プレーンなタプルを返す代わりに。

バッチの画像を潜在変数にエンコードします。

forward

< >

( sample: Tensorsample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → DecoderOutput or tuple

パラメータ

  • sample (torch.Tensor) — 入力サンプル。
  • sample_posterior (bool、省略可能、デフォルトはFalse) — 後方分布からサンプリングするかどうか。
  • return_dict (bool、省略可、デフォルトは True) — DecoderOutput を返すか、プレーンなタプルを返すかを指定します。
  • generator (torch.Generator、任意、デフォルトはNone) — サンプリングに使用するジェネレーター。

戻り値

DecoderOutput または tuple

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

set_default_attn_processor

< >

( )

カスタムアテンションプロセッサを無効にし、デフォルトのアテンション実装を設定します。

tiled_encode

< >

( x: Tensorreturn_dict: bool = True ) → ConsistencyDecoderVAEOutput or tuple

パラメータ

  • x (torch.Tensor) — 画像の入力バッチ。
  • return_dict (bool、省略可能、デフォルトは True) — ConsistencyDecoderVAEOutput を返すか、プレーンなタプルを返すかを指定します。

戻り値

ConsistencyDecoderVAEOutput または tuple

return_dictがTrueの場合、ConsistencyDecoderVAEOutputが返され、それ以外の場合は通常のtupleが返されます。

タイル化されたエンコーダーを使用して、画像のバッチをエンコードします。

このオプションを有効にすると、VAE は入力テンソルをタイルに分割し、複数ステップでエンコーディングを計算します。これにより、画像サイズに関係なくメモリ使用量を一定に保つことができます。タイル化されたエンコーディングの結果は、タイル化されていないエンコーディングとは異なります。これは、各タイルが異なるエンコーダーを使用するためです。タイル化によるアーティファクトを回避するために、タイルはオーバーラップし、滑らかな出力を形成するためにブレンドされます。出力にタイルサイズの変化が見られる場合もありますが、以前よりもはるかに目立たなくなります。

Update on GitHub