Diffusers 文档

AutoencoderKLMochi

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

AutoencoderKLMochi

Mochi 中使用的带有 KL 损失的 3D 变分自动编码器 (VAE) 模型由清华大学和智谱AI在 Mochi 1 Preview 中引入。

该模型可以通过以下代码片段加载。

from diffusers import AutoencoderKLMochi

vae = AutoencoderKLMochi.from_pretrained("genmo/mochi-1-preview", subfolder="vae", torch_dtype=torch.float32).to("cuda")

AutoencoderKLMochi

class diffusers.AutoencoderKLMochi

< >

( in_channels: int = 15 out_channels: int = 3 encoder_block_out_channels: typing.Tuple[int] = (64, 128, 256, 384) decoder_block_out_channels: typing.Tuple[int] = (128, 256, 512, 768) latent_channels: int = 12 layers_per_block: typing.Tuple[int, ...] = (3, 3, 4, 6, 3) act_fn: str = 'silu' temporal_expansions: typing.Tuple[int, ...] = (1, 2, 3) spatial_expansions: typing.Tuple[int, ...] = (2, 2, 2) add_attention_block: typing.Tuple[bool, ...] = (False, True, True, True, True) latents_mean: typing.Tuple[float, ...] = (-0.06730895953510081, -0.038011381506090416, -0.07477820912866141, -0.05565264470995561, 0.012767231469026969, -0.04703542746246419, 0.043896967884726704, -0.09346305707025976, -0.09918314763016893, -0.008729793427399178, -0.011931556316503654, -0.0321993391887285) latents_std: typing.Tuple[float, ...] = (0.9263795028493863, 0.9248894543193766, 0.9393059390890617, 0.959253732819592, 0.8244560132752793, 0.917259975397747, 0.9294154431013696, 1.3720942357788521, 0.881393668867029, 0.9168315692124348, 0.9185249279345552, 0.9274757570805041) scaling_factor: float = 1.0 )

参数

  • in_channels (int, 可选, 默认为 3) — 输入图像中的通道数。
  • out_channels (int, 可选, 默认为 3) — 输出通道数。
  • block_out_channels (Tuple[int], 可选, 默认为 (64,)) — 块输出通道的元组。
  • act_fn (str, 可选, 默认为 "silu") — 要使用的激活函数。
  • scaling_factor (float, 可选, 默认为 1.15258426) — 使用训练集第一批计算的训练潜在空间的组件标准差。这用于在训练扩散模型时将潜在空间缩放到单位方差。潜在空间在传递给扩散模型之前,通过公式 z = z * scaling_factor 进行缩放。解码时,潜在空间通过公式 z = 1 / scaling_factor * z 缩放回原始比例。有关更多详细信息,请参阅 《使用潜在扩散模型进行高分辨率图像合成》 论文的 4.3.2 节和 D.1 节。

用于将图像编码为潜在空间并将潜在表示解码为图像的带有 KL 损失的 VAE 模型。用于 Mochi 1 preview

此模型继承自 ModelMixin。有关所有模型实现的通用方法(如下载或保存),请参阅超类文档。

包装器

< >

( *args **kwargs )

禁用切片

< >

( )

禁用切片 VAE 解码。如果之前启用了 enable_slicing,此方法将恢复一步计算解码。

禁用分块

< >

( )

禁用平铺 VAE 解码。如果之前启用了 enable_tiling,此方法将恢复一步计算解码。

启用切片

< >

( )

启用切片 VAE 解码。启用此选项后,VAE 会将输入张量分片,分步计算解码。这有助于节省一些内存并允许更大的批次大小。

启用分块

< >

( tile_sample_min_height: typing.Optional[int] = None tile_sample_min_width: typing.Optional[int] = None tile_sample_stride_height: typing.Optional[float] = None tile_sample_stride_width: typing.Optional[float] = None )

参数

  • tile_sample_min_height (int, 可选) — 样本沿高度维度分离为块所需的最小高度。
  • tile_sample_min_width (int, 可选) — 样本沿宽度维度分离为块所需的最小宽度。
  • tile_sample_stride_height (int, 可选) — 两个连续垂直块之间的最小重叠量。这是为了确保在高度维度上不产生分块伪影。
  • tile_sample_stride_width (int, 可选) — 两个连续水平块之间的步幅。这是为了确保在宽度维度上不产生分块伪影。

启用平铺 VAE 解码。启用此选项后,VAE 将把输入张量分割成瓦片,分多步计算编码和解码。这对于节省大量内存和处理更大的图像非常有用。

分块解码

< >

( z: Tensor return_dict: bool = True ) ~models.vae.DecoderOutputtuple

参数

  • z (torch.Tensor) — 潜在向量的输入批次。
  • return_dict (bool, 可选, 默认为 True) — 是否返回 ~models.vae.DecoderOutput 而不是普通的元组。

返回

~models.vae.DecoderOutputtuple

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

使用分块解码器解码一批图像。

分块编码

< >

( x: Tensor ) torch.Tensor

参数

  • x (torch.Tensor) — 输入视频批次。

返回

torch.Tensor

编码视频的潜在表示。

使用分块编码器编码一批图像。

DecoderOutput

class diffusers.models.autoencoders.vae.DecoderOutput

< >

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

参数

  • sample (torch.Tensor, 形状为 (batch_size, num_channels, height, width)) — 模型最后一层的解码输出样本。

解码方法的输出。

< > 在 GitHub 上更新