Diffusers documentation
AutoencoderKLQwenImage21
AutoencoderKLQwenImage21
Qwen-Image 2.1 所使用的 64 通道变分自编码器。它在空间维度上进行 16 倍压缩,其逐通道的 latents_mean / latents_std 是配置的一部分,而非单一的缩放因子。
import torch
from diffusers import AutoencoderKLQwenImage21
vae = AutoencoderKLQwenImage21.from_pretrained("Qwen/Qwen-Image-2.1", subfolder="vae", dtype=torch.bfloat16)AutoencoderKLQwenImage21
类 diffusers.AutoencoderKLQwenImage21
< source >( base_dim: int = 96decoder_base_dim: int | None = 144z_dim: int = 64dim_mult: list = [1, 2, 4, 8, 8]num_res_blocks: int = 2attn_scales: list = []temperal_downsample: list = [False, True, True, True]dropout: float = 0.0latents_mean: list = [0.5126, 0.7721, -0.0631, 1.3506, -0.7855, -2.1025, -0.3458, 1.3722, 1.8873, -1.7177, -0.651, 0.2732, 0.7562, -0.6163, -1.0277, 3.8363, 2.021, 0.0472, 0.932, 2.0087, 2.4954, -0.1391, -1.4249, 1.8464, -0.5236, 1.2826, 3.7046, -1.3035, 2.7286, -1.4518, -1.9036, -1.9955, -0.0342, -1.0265, -0.7636, 3.0555, 0.0746, -3.0751, -0.1076, 1.7376, -1.0914, -1.9435, -0.2784, -1.368, 0.4809, -0.4433, 0.3764, 0.5729, -2.0595, 1.096, -1.326, -2.0211, -5.0179, 0.5275, 4.0162, 1.8505, 0.3026, 1.9373, 1.4937, 0.2632, 0.5547, -1.7121, -0.1562, 0.0304]latents_std: list = [3.2001, 3.2936, 3.4321, 3.0091, 3.1061, 4.0379, 4.0705, 3.791, 3.0785, 3.65, 3.9308, 3.0904, 2.8778, 3.7675, 3.732, 5.0756, 3.2864, 4.0397, 3.1317, 4.0443, 2.9249, 3.9454, 3.0988, 4.2489, 3.4896, 3.8513, 3.9323, 3.4719, 3.7498, 4.283, 3.5694, 4.2467, 3.9037, 3.2947, 5.077, 3.5075, 3.27, 3.4767, 2.8063, 5.1125, 3.5327, 4.7833, 3.1286, 4.1819, 3.8527, 3.8312, 3.5605, 4.3875, 3.9624, 4.0168, 3.5643, 4.055, 5.5614, 4.2963, 4.408, 3.4959, 3.8747, 3.7608, 3.5735, 3.149, 3.7662, 3.6746, 3.4563, 3.8161]is_residual: bool = Truein_channels: int = 4out_channels: int = 4patch_size: int | None = Nonescale_factor_temporal: int | None = 8scale_factor_spatial: int | None = 16 )
一个用于将视频编码为潜在表示并将潜在表示解码为视频的 VAE 模型,采用 KL 损失。 在 [Qwen Image 2] 中引入。
该模型继承自 ModelMixin。请查阅其父类文档,了解为所有模型实现的通用方法(例如下载或保存)。
decode
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
解码一批图像。
encode
< source >( x: Tensorreturn_dict: bool = True )
将一批图像编码为潜在表示。
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 会将输入张量拆分为多个分块,分步执行解码和编码。这有助于节省大量内存,并支持处理更大的图像。
forward
< source >( sample: Tensorsample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → DecoderOutput or tuple
参数
- sample (
torch.Tensor) — 输入样本。 - sample_posterior (
bool,可选,默认为False) — 是否从后验分布中采样,而不是取其众数。 - return_dict (
bool,可选,默认为True) — 是否返回DecoderOutput而不是普通元组。 - generator (
torch.Generator,可选) — 当sample_posterior为True时使用的生成器。
返回值
DecoderOutput 或 tuple
如果 return_dict 为 True,则返回 DecoderOutput,否则返回普通的 tuple。
tiled_decode
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
使用分块解码器解码一批图像。
tiled_encode
< source >( x: Tensor ) → torch.Tensor
使用分块编码器对一批图像进行编码。
AutoencoderKLOutput
类 diffusers.models.modeling_outputs.AutoencoderKLOutput
< source >( latent_dist: DiagonalGaussianDistribution )
AutoencoderKL 编码方法的输出。
DecoderOutput
class diffusers.models.autoencoders.vae.DecoderOutput
< source >( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )
解码方法的输出。