Diffusers documentation

AutoencoderKLAllegro

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

and get access to the augmented documentation experience

to get started

AutoencoderKLAllegro

Allegro 中使用的带 KL 损失的 3D 变分自编码器(VAE)模型,由 RhymesAI 在 Allegro: Open the Black Box of Commercial-Level Video Generation Model 中提出。

可以使用以下代码片段加载该模型。

from diffusers import AutoencoderKLAllegro

vae = AutoencoderKLAllegro.from_pretrained("rhymes-ai/Allegro", subfolder="vae", dtype=torch.float32).to("cuda")  # or "mps", "xpu", "cpu"

AutoencoderKLAllegro

class diffusers.AutoencoderKLAllegro

< >

( in_channels: int = 3out_channels: int = 3down_block_types: tuple[str, ...] = ('AllegroDownBlock3D', 'AllegroDownBlock3D', 'AllegroDownBlock3D', 'AllegroDownBlock3D')up_block_types: tuple[str, ...] = ('AllegroUpBlock3D', 'AllegroUpBlock3D', 'AllegroUpBlock3D', 'AllegroUpBlock3D')block_out_channels: tuple[int, ...] = (128, 256, 512, 512)temporal_downsample_blocks: tuple[bool, ...] = (True, True, False, False)temporal_upsample_blocks: tuple[bool, ...] = (False, True, True, False)latent_channels: int = 4layers_per_block: int = 2act_fn: str = 'silu'norm_num_groups: int = 32temporal_compression_ratio: float = 4sample_size: int = 320scaling_factor: float = 0.13force_upcast: bool = True )

参数

  • in_channels (int,默认为 3) — 输入图像的通道数。
  • out_channels (int, 默认为 3) — 输出中的通道数。
  • down_block_types (tuple[str, ...],默认为 ("AllegroDownBlock3D", "AllegroDownBlock3D", "AllegroDownBlock3D", "AllegroDownBlock3D")) — 字符串元组,指定要使用的下采样块类型。
  • up_block_types (tuple[str, ...],默认为 ("AllegroUpBlock3D", "AllegroUpBlock3D", "AllegroUpBlock3D", "AllegroUpBlock3D")) — 表示要使用的上采样块类型的字符串元组。
  • block_out_channels (tuple[int, ...],默认为 (128, 256, 512, 512)) — 整数元组,表示每个块中的输出通道数。
  • temporal_downsample_blocks (tuple[bool, ...],默认为 (True, True, False, False)) — 布尔值元组,用于指定在哪些块中启用时间下采样。
  • latent_channels (int,默认为 4) — 潜在表示的通道数。
  • layers_per_block (int,默认为 2) — 每个下采样/上采样块中 ResNet、注意力或时间卷积层的数量。
  • act_fn (str,默认为 "silu") — 要使用的激活函数。
  • norm_num_groups (int,默认为 32) — 归一化层中使用的组数。
  • temporal_compression_ratio (int,默认为 4) — 样本时间维度的压缩比例。
  • sample_size (int,默认为 320) — 默认的潜在尺寸。
  • scaling_factor (float,默认为 0.13235) — 使用训练集的第一个批次计算得出的训练后潜在空间的逐分量标准差。在训练扩散模型时,用于将潜在空间缩放至单位方差。在将潜在变量传递给扩散模型之前,使用公式 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) — 如果启用,将强制 VAE 在高分辨率图像流水线(例如 SD-XL)中以 float32 运行。VAE 可以微调/训练至更低的数值范围,而不会损失太多精度,此时可将 force_upcast 设置为 False - 参见:https://huggingface.co/madebyollin/sdxl-vae-fp16-fix

一个用于将视频编码为潜在表示并将潜在表示解码为视频的 VAE 模型,包含 KL 损失。用于 Allegro。

该模型继承自 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 而不是普通的元组。

将一批视频编码为潜在表示。

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,可选) — PyTorch 随机数生成器。

返回值

~models.vae.DecoderOutput 或 tuple

如果 return_dict 为 True,则返回 ~models.vae.DecoderOutput,否则返回普通的 tuple。

AutoencoderKLOutput

类 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(形状为 (batch_size, num_channels, height, width) 的 torch.Tensor)— 模型最后一层解码输出的样本。

解码方法的输出。

Update on GitHub