Diffusers 文档
AutoencoderKLAllegro
并获得增强的文档体验
开始使用
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", torch_dtype=torch.float32).to("cuda")
AutoencoderKLAllegro
class diffusers.AutoencoderKLAllegro
< 来源 >( in_channels: int = 3 out_channels: int = 3 down_block_types: typing.Tuple[str, ...] = ('AllegroDownBlock3D', 'AllegroDownBlock3D', 'AllegroDownBlock3D', 'AllegroDownBlock3D') up_block_types: typing.Tuple[str, ...] = ('AllegroUpBlock3D', 'AllegroUpBlock3D', 'AllegroUpBlock3D', 'AllegroUpBlock3D') block_out_channels: typing.Tuple[int, ...] = (128, 256, 512, 512) temporal_downsample_blocks: typing.Tuple[bool, ...] = (True, True, False, False) temporal_upsample_blocks: typing.Tuple[bool, ...] = (False, True, True, False) latent_channels: int = 4 layers_per_block: int = 2 act_fn: str = 'silu' norm_num_groups: int = 32 temporal_compression_ratio: float = 4 sample_size: int = 320 scaling_factor: float = 0.13 force_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 或 attention 或时间卷积层的数量。 - 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
缩放回原始比例。有关更多详细信息,请参阅 高分辨率图像合成与潜在扩散模型 论文的 4.3.2 节和 D.1 节。 - force_upcast (
bool
, 默认为True
) — 如果启用,它将强制 VAE 以 float32 运行,以实现高图像分辨率流水线,例如 SD-XL。VAE 可以进行微调/训练以降低范围,而不会损失太多精度,在这种情况下,force_upcast
可以设置为False
- 请参阅:https://huggingface.co/madebyollin/sdxl-vae-fp16-fix
一个带有 KL 损失的 VAE 模型,用于将视频编码为潜在空间并将潜在表示解码为视频。在 Allegro 中使用。
此模型继承自 ModelMixin。有关所有模型实现的通用方法(如下载或保存),请参阅超类文档。
禁用切片 VAE 解码。如果之前启用了 enable_slicing
,此方法将恢复一步计算解码。
禁用平铺 VAE 解码。如果之前启用了 enable_tiling
,此方法将恢复一步计算解码。
启用切片 VAE 解码。启用此选项后,VAE 会将输入张量分片,分步计算解码。这有助于节省一些内存并允许更大的批次大小。
启用平铺 VAE 解码。启用此选项后,VAE 将把输入张量分割成瓦片,分多步计算编码和解码。这对于节省大量内存和处理更大的图像非常有用。
forward
< 来源 >( sample: Tensor sample_posterior: bool = False return_dict: bool = True generator: typing.Optional[torch._C.Generator] = None )
AutoencoderKLOutput
class diffusers.models.modeling_outputs.AutoencoderKLOutput
< 来源 >( latent_dist: DiagonalGaussianDistribution )
AutoencoderKL 编码方法的输出。
DecoderOutput
class diffusers.models.autoencoders.vae.DecoderOutput
< 来源 >( sample: Tensor commit_loss: typing.Optional[torch.FloatTensor] = None )
解码方法的输出。