Diffusers documentation
Consistency Decoder
Consistency Decoder
Consistency decoder は、StableDiffusionPipeline のデノイジング UNet から潜在変数をデコードするために使用できます。このデコーダーは、DALL-E 3 技術レポート で紹介されました。
元のコードベースはopenai/consistencydecoderで確認できます。
現時点では、推論は2回の反復のみサポートされています。
このパイプラインは、このイシューからのmadebyollinとmrsteykの助けがなければ貢献されていませんでした。
ConsistencyDecoderVAE
class diffusers.ConsistencyDecoderVAE
< source >( 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]
>>> imagedecode
< source >( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = Truenum_inference_steps: int = 2 ) → DecoderOutput | tuple[torch.Tensor]
consistency decoder VAE モデルを使用して、入力潜在ベクトル z をデコードします。
encode
< source >( x: Tensorreturn_dict: bool = True )
バッチの画像を潜在変数にエンコードします。
forward
< source >( 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.
カスタムアテンションプロセッサを無効にし、デフォルトのアテンション実装を設定します。
tiled_encode
< source >( x: Tensorreturn_dict: bool = True ) → ConsistencyDecoderVAEOutput or tuple
タイル化されたエンコーダーを使用して、画像のバッチをエンコードします。
このオプションを有効にすると、VAE は入力テンソルをタイルに分割し、複数ステップでエンコーディングを計算します。これにより、画像サイズに関係なくメモリ使用量を一定に保つことができます。タイル化されたエンコーディングの結果は、タイル化されていないエンコーディングとは異なります。これは、各タイルが異なるエンコーダーを使用するためです。タイル化によるアーティファクトを回避するために、タイルはオーバーラップし、滑らかな出力を形成するためにブレンドされます。出力にタイルサイズの変化が見られる場合もありますが、以前よりもはるかに目立たなくなります。