Diffusers documentation

AutoencoderKLCogVideoX

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

AutoencoderKLCogVideoX

The 3D variational autoencoder (VAE) model with KL loss used in CogVideoX was introduced in CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer by Tsinghua University & ZhipuAI.

モデルは、以下のコードスニペットで読み込むことができます。

from diffusers import AutoencoderKLCogVideoX

vae = AutoencoderKLCogVideoX.from_pretrained("THUDM/CogVideoX-2b", subfolder="vae", dtype=torch.float16).to("cuda")  # or "mps", "xpu", "cpu"

AutoencoderKLCogVideoX

class diffusers.AutoencoderKLCogVideoX

< >

( in_channels: int = 3out_channels: int = 3down_block_types: tuple[str] = ('CogVideoXDownBlock3D', 'CogVideoXDownBlock3D', 'CogVideoXDownBlock3D', 'CogVideoXDownBlock3D')up_block_types: tuple[str] = ('CogVideoXUpBlock3D', 'CogVideoXUpBlock3D', 'CogVideoXUpBlock3D', 'CogVideoXUpBlock3D')block_out_channels: tuple[int] = (128, 256, 256, 512)latent_channels: int = 16layers_per_block: int = 3act_fn: str = 'silu'norm_eps: float = 1e-06norm_num_groups: int = 32temporal_compression_ratio: float = 4sample_height: int = 480sample_width: int = 720scaling_factor: float = 1.15258426shift_factor: float | None = Nonelatents_mean: tuple[float] | None = Nonelatents_std: tuple[float] | None = Noneforce_upcast: float = Trueuse_quant_conv: bool = Falseuse_post_quant_conv: bool = Falseinvert_scale_latents: bool = False )

パラメータ

  • in_channels (int, 任意、デフォルトは 3) — 入力画像のチャネル数。
  • out_channels (int, 任意, デフォルトは 3) — 出力のチャネル数。
  • down_block_types (tuple[str]、任意、デフォルトは("DownEncoderBlock2D",)) — ダウンサンプルブロックのタイプのタプルです。
  • up_block_types (tuple[str]、任意、デフォルトは("UpDecoderBlock2D",)) — アップサンプリングブロックのタイプのタプルです。
  • block_out_channels (tuple[int]、任意、デフォルトは (64,)) — ブロックの出力チャネルのタプル。
  • act_fn (str、任意、デフォルトは "silu") — 使用する活性化関数。
  • sample_size (int、任意、デフォルトは 32) — サンプルの入力サイズ。
  • scaling_factor (float, 任意、デフォルト値は 1.15258426) — 学習済み潜在空間の要素ごとの標準偏差です。これは、学習セットの最初のバッチを使用して計算されます。拡散モデルの学習時に、潜在空間を分散 1 にスケーリングするために使用されます。潜在変数は、拡散モデルに渡される前に、式 z = z * scaling_factor によってスケーリングされます。デコード時には、式 z = 1 / scaling_factor * z によって、潜在変数は元のスケールに戻されます。詳細については、High-Resolution Image Synthesis with Latent Diffusion Models 論文のセクション 4.3.2 と D.1 を参照してください。
  • force_upcast (bool、任意、デフォルトは True) — 有効にすると、SD-XL などの高解像度画像向けパイプラインにおいて、VAE を float32 で実行するよう強制します。VAE を低精度の範囲でファインチューニング / 学習し、精度の低下を抑えることが可能な場合、force_upcast を False に設定できます。参考: https://huggingface.co/madebyollin/sdxl-vae-fp16-fix

KL損失を用いて画像を潜在変数にエンコードし、潜在表現を画像にデコードするためのVAEモデル。CogVideoXで使用されます。

このモデルは ModelMixin を継承しています。すべてのモデルに実装されている汎用的なメソッド(ダウンロードや保存など)については、スーパークラスのドキュメントを参照してください。

decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

パラメータ

  • z (torch.Tensor) — 潜在ベクトルの入力バッチ。
  • return_dict (bool、省略可、デフォルトはTrue) — ~models.vae.DecoderOutputを返すか、プレーンなタプルを返すかを指定します。

戻り値

~models.vae.DecoderOutput または tuple

return_dict が True の場合、~models.vae.DecoderOutput が返され、それ以外の場合は通常の tuple が返されます。

画像のバッチをデコードします。

encode

< >

( x: Tensorreturn_dict: bool = True )

パラメータ

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

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

enable_tiling

< >

( tile_sample_min_height: int | None = Nonetile_sample_min_width: int | None = Nonetile_overlap_factor_height: float | None = Nonetile_overlap_factor_width: float | None = None )

パラメータ

  • tile_sample_min_height (int, 任意) — サンプルを高さ方向にタイル分割するために必要な最小高さ。
  • tile_sample_min_width (int, 任意) — 幅方向にサンプルをタイルに分割するために必要な最小幅です。
  • tile_overlap_factor_height (int, 省略可) — 連続する2つの縦方向のタイル間の最小オーバーラップ量です。これにより、高さ方向にタイルリングアーティファクトが発生しないことを保証します。0以上1以下の値を指定する必要があります。値を大きくすると、処理されるタイル数が増えるため、デコーディング処理が遅くなる可能性があります。
  • tile_overlap_factor_width (int, 任意) — 2つの連続する水平タイル間の最小の重複量です。これにより、幅方向にタイルリングアーティファクトが発生しないことを保証します。0以上1以下の値である必要があります。より高い値を設定すると、処理されるタイル数が増え、デコーディングプロセスが遅くなる可能性があります。

タイル化VAEデコーディングを有効にします。このオプションを有効にすると、VAEは入力テンソルをタイルに分割し、デコーディングとエンコーディングを複数ステップで計算します。これにより、大量のメモリを節約し、より大きな画像の処理を可能にします。

forward

< >

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

パラメータ

  • sample (torch.Tensor) — 入力サンプル。
  • sample_posterior (bool、省略可能、デフォルトはFalse) — 後方分布からサンプリングするかどうか。
  • return_dict (bool、省略可、デフォルトは True) — DecoderOutput を返すか、プレーンなタプルを返すかを指定します。
  • generator (torch.Generator、省略可) — サンプリングを決定論的に行うためのtorch.Generator。

戻り値

~models.vae.DecoderOutput または tuple

return_dict が True の場合、~models.vae.DecoderOutput が返され、それ以外の場合は通常の tuple が返されます。

tiled_decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

パラメータ

  • z (torch.Tensor) — 潜在ベクトルの入力バッチ。
  • return_dict (bool、省略可、デフォルトはTrue) — ~models.vae.DecoderOutputを返すか、プレーンなタプルを返すかを指定します。

戻り値

~models.vae.DecoderOutput または tuple

return_dict が True の場合、~models.vae.DecoderOutput が返され、それ以外の場合は通常の tuple が返されます。

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

tiled_encode

< >

( x: Tensor ) → torch.Tensor

パラメータ

  • x (torch.Tensor) — 入力バッチの動画。

戻り値

torch.Tensor

エンコードされた動画の潜在表現。

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

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

AutoencoderKLOutput

class diffusers.models.modeling_outputs.AutoencoderKLOutput

< >

( latent_dist: DiagonalGaussianDistribution )

パラメータ

  • latent_dist (DiagonalGaussianDistribution) — Encoder のエンコード出力を、DiagonalGaussianDistribution の平均と logvar として表したものです。 DiagonalGaussianDistribution を使用すると、この分布から潜在変数をサンプリングできます。

AutoencoderKLのエンコードメソッドの出力。

DecoderOutput

class diffusers.models.autoencoders.vae.DecoderOutput

< >

( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )

パラメータ

  • sample (torch.Tensor、形状 (batch_size, num_channels, height, width)) — モデルの最終層からのデコード済み出力サンプルです。

デコードメソッドの出力。

Update on GitHub