Diffusers documentation

AutoencoderKLHunyuanImage

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

AutoencoderKLHunyuanImage

[HunyuanImage2.1] 中使用的带有 KL 损失的二维变分自编码器(VAE)模型。

可以使用以下代码片段加载该模型。

from diffusers import AutoencoderKLHunyuanImage

vae = AutoencoderKLHunyuanImage.from_pretrained("hunyuanvideo-community/HunyuanImage-2.1-Diffusers", subfolder="vae", dtype=torch.bfloat16)

AutoencoderKLHunyuanImage

class diffusers.AutoencoderKLHunyuanImage

< >

( in_channels: intout_channels: intlatent_channels: intblock_out_channels: tuplelayers_per_block: intspatial_compression_ratio: intsample_size: intscaling_factor: float = Nonedownsample_match_channel: bool = Trueupsample_match_channel: bool = True )

支持空间分块的 2D 图像 VAE 模型。

该模型继承自 ModelMixin。请查阅其父类文档,了解为所有模型实现的通用方法(例如下载或保存)。

decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

参数

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

返回值

~models.vae.DecoderOutput 或 tuple

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

解码一批图像。

enable_tiling

< >

( tile_sample_min_size: int | None = Nonetile_overlap_factor: float | None = None )

参数

  • tile_sample_min_size (int, 可选) — 样本在空间维度上被分割为多个 tile 所需的最小尺寸。
  • tile_overlap_factor (float, 可选) — 将潜在表示沿空间维度分割为多个块时所需的重叠系数。

启用空间分块 VAE 解码。启用此选项后,VAE 会将输入张量拆分为多个分块,分步执行解码和编码。这有助于节省大量内存,并支持处理更大的图像。

encode

< >

( x: Tensorreturn_dict: bool = True )

参数

  • x (torch.Tensor) — 输入图像批次。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.autoencoder_kl.AutoencoderKLOutput 而不是普通元组。

将一批图像编码为潜在表示。

forward

< >

( 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

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

参数

  • z (torch.Tensor) — 形状为 (B, C, H, W) 的潜在张量。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~models.vae.DecoderOutput 而不是普通元组。

返回值

~models.vae.DecoderOutput 或 tuple

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

使用空间分块策略解码潜在表示。

tiled_encode

< >

( x: Tensor ) → torch.Tensor

参数

  • x (torch.Tensor) — 形状为 (B, C, T, H, W) 的输入张量。

返回值

torch.Tensor

编码图像的潜在表示。

使用空间分块策略对输入进行编码。

DecoderOutput

class diffusers.models.autoencoders.vae.DecoderOutput

< >

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

参数

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

解码方法的输出。

Update on GitHub