Diffusers 文档
AutoencoderKLMochi
并获得增强的文档体验
开始使用
AutoencoderKLMochi
Mochi 中使用的具有 KL 损失的 3D 变分自动编码器 (VAE) 模型,在Mochi中介绍,并由清华大学 & 智谱 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
< source >( 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, optional, defaults to 3) — 输入图像中的通道数。
- out_channels (int, optional, defaults to 3) — 输出中的通道数。
- block_out_channels (
Tuple[int]
, optional, defaults to(64,)
) — 块输出通道的元组。 - act_fn (
str
, optional, defaults to"silu"
) — 要使用的激活函数。 - scaling_factor (
float
, optional, defaults to1.15258426
) — 使用训练集的第一批计算的训练潜在空间的组件级标准差。这用于在训练扩散模型时缩放潜在空间以使其具有单位方差。在传递到扩散模型之前,潜在变量使用公式z = z * scaling_factor
进行缩放。解码时,潜在变量使用公式z = 1 / scaling_factor * z
缩放回原始比例。有关更多详细信息,请参阅 High-Resolution Image Synthesis with Latent Diffusion Models 论文的 4.3.2 节和 D.1 节。
具有 KL 损失的 VAE 模型,用于将图像编码为潜在变量,并将潜在表示解码为图像。在 Mochi 1 preview 中使用。
此模型继承自 ModelMixin。查看超类文档以获取为所有模型实现的通用方法(例如下载或保存)。
禁用切片VAE解码。如果之前启用了 enable_slicing
,此方法将恢复为单步计算解码。
禁用平铺VAE解码。如果之前启用了 enable_tiling
,此方法将恢复为单步计算解码。
启用切片VAE解码。启用此选项后,VAE 将输入张量分割成切片,分步计算解码。这有助于节省一些内存并允许更大的批大小。
enable_tiling
< 源代码 >( 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 )
启用平铺VAE解码。启用此选项后,VAE 将输入张量分割成瓦片,分步计算解码和编码。这对于节省大量内存并允许处理更大的图像非常有用。
tiled_decode
< 源代码 >( z: Tensor return_dict: bool = True ) → ~models.vae.DecoderOutput
or tuple
使用平铺解码器解码一批图像。
tiled_encode
< 源代码 >( x: Tensor ) → torch.Tensor
使用平铺编码器编码一批图像。
DecoderOutput
class diffusers.models.autoencoders.vae.DecoderOutput
< 源代码 >( sample: Tensor commit_loss: typing.Optional[torch.FloatTensor] = None )
解码方法的输出。