Diffusers 文档
AutoencoderKLAllegro
并获取增强的文档体验
开始使用
AutoencoderKLAllegro
在 Allegro 中使用的带有 KL 损失的 3D 变分自动编码器 (VAE) 模型,由 RhymesAI 在 Allegro: Open the Black Box of Commercial-Level Video Generation Model 中介绍。
该模型可以使用以下代码片段加载。
from diffusers import AutoencoderKLAllegro
vae = AutoencoderKLCogVideoX.from_pretrained("rhymes-ai/Allegro", subfolder="vae", torch_dtype=torch.float32).to("cuda")
AutoencoderKLAllegro
class diffusers.AutoencoderKLAllegro
< source >( 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
缩放回原始尺度。 有关更多详细信息,请参阅 High-Resolution Image Synthesis with Latent Diffusion Models 论文的 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
< source >( sample: Tensor sample_posterior: bool = False return_dict: bool = True generator: typing.Optional[torch._C.Generator] = None )
AutoencoderKLOutput
class diffusers.models.modeling_outputs.AutoencoderKLOutput
< source >( latent_dist: DiagonalGaussianDistribution )
AutoencoderKL 编码方法的输出。
DecoderOutput
class diffusers.models.autoencoders.vae.DecoderOutput
< source >( sample: Tensor commit_loss: typing.Optional[torch.FloatTensor] = None )
解码方法的输出。