Buckets:

hf-doc-build/doc / diffusers /v0.43.0 /ja /api /models /consistency_decoder_vae.md
mishig's picture
|
download
raw
7.45 kB

Consistency Decoder

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

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

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

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

ConsistencyDecoderVAE[[diffusers.ConsistencyDecoderVAE]]

diffusers.ConsistencyDecoderVAE[[diffusers.ConsistencyDecoderVAE]]

diffusers.ConsistencyDecoderVAE(scaling_factor: float = 0.18215, latent_channels: int = 4, sample_size: int = 32, encoder_act_fn: str = 'silu', encoder_block_out_channels: tuple[int, ...] = (128, 256, 512, 512), encoder_double_z: bool = True, encoder_down_block_types: tuple[str, ...] = ('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[int, ...] = (320, 640, 1024, 1024), decoder_down_block_types: tuple[str, ...] = ('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[str, ...] = ('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[[diffusers.ConsistencyDecoderVAE.decode]]

decode(z: Tensor, generator: typing.Optional[torch.Generator] = None, return_dict: bool = True, num_inference_steps: int = 2)

ソース

パラメータ:

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[[diffusers.ConsistencyDecoderVAE.encode]]

encode(x: Tensor, return_dict: bool = True)

ソース

パラメータ:

x (torch.Tensor) : 画像の入力バッチ。

return_dict (bool、任意、デフォルトはTrue) : プレーンなタプルではなくConsistencyDecoderVAEOutputを返すかどうか。

戻り値:

エンコードされた画像の潜在表現。return_dictがTrueの場合、ConsistencyDecoderVAEOutputが返され、それ以外の場合は通常のtupleが返されます。

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

forward[[diffusers.ConsistencyDecoderVAE.forward]]

forward(sample: Tensor, sample_posterior: bool = False, return_dict: bool = True, generator: typing.Optional[torch.Generator] = None)

ソース

パラメータ:

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[[diffusers.ConsistencyDecoderVAE.set_default_attn_processor]]

set_default_attn_processor()

ソース

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

tiled_encode[[diffusers.ConsistencyDecoderVAE.tiled_encode]]

tiled_encode(x: Tensor, return_dict: bool = True)

ソース

パラメータ:

x (torch.Tensor) : 画像の入力バッチ。

return_dict (bool、任意、デフォルトはTrue) : プレーンなタプルではなくConsistencyDecoderVAEOutputを返すかどうか。

戻り値: ConsistencyDecoderVAEOutput または tuple

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

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

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

Xet Storage Details

Size:
7.45 kB
·
Xet hash:
a7b5b3a0555d034833ee3cb3c16f7a578b0002f089cfb4a1c18de3d78de83194

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.