Diffusers documentation
AutoencoderKLMochi
AutoencoderKLMochi
Mochi 中使用的带 KL 损失的 3D 变分自编码器(VAE)模型,由清华大学 & ZhipuAI 在 Mochi 1 Preview 中提出。
可以使用以下代码片段加载该模型。
from diffusers import AutoencoderKLMochi
vae = AutoencoderKLMochi.from_pretrained("genmo/mochi-1-preview", subfolder="vae", dtype=torch.float32).to("cuda") # or "mps", "xpu", "cpu"AutoencoderKLMochi
class diffusers.AutoencoderKLMochi
< source >( in_channels: int = 15out_channels: int = 3encoder_block_out_channels: tuple = (64, 128, 256, 384)decoder_block_out_channels: tuple = (128, 256, 512, 768)latent_channels: int = 12layers_per_block: tuple = (3, 3, 4, 6, 3)act_fn: str = 'silu'temporal_expansions: tuple = (1, 2, 3)spatial_expansions: tuple = (2, 2, 2)add_attention_block: tuple = (False, True, True, True, True)latents_mean: tuple = (-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: tuple = (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将潜在变量缩放回原始尺度。更多详细信息,请参阅 High-Resolution Image Synthesis with Latent Diffusion Models 论文的 4.3.2 节和 D.1 节。
一个带有 KL 损失的 VAE 模型,用于将图像编码为潜在表示,并将潜在表示解码为图像。用于 Mochi 1 preview。
该模型继承自 ModelMixin。请查阅其父类文档,了解为所有模型实现的通用方法(例如下载或保存)。
decode
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
解码一批图像。
enable_tiling
< source >( tile_sample_min_height: int | None = Nonetile_sample_min_width: int | None = Nonetile_sample_stride_height: float | None = Nonetile_sample_stride_width: float | None = None )
启用分块 VAE 解码。启用此选项后,VAE 会将输入张量拆分为多个分块,分步执行解码和编码。这有助于节省大量内存,并支持处理更大的图像。
encode
< source >( x: Tensorreturn_dict: bool = True )
将一批图像编码为潜在表示。
forward
< source >( 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,可选) — 用于使采样过程确定性的torch.Generator。
返回值
~models.vae.DecoderOutput 或 tuple
如果 return_dict 为 True,则返回 ~models.vae.DecoderOutput,否则返回普通的 tuple。
tiled_decode
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
使用分块解码器解码一批图像。
tiled_encode
< source >( x: Tensor ) → torch.Tensor
使用分块编码器对一批图像进行编码。
DecoderOutput
class diffusers.models.autoencoders.vae.DecoderOutput
< source >( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )
解码方法的输出。