Diffusers 文档
微型自动编码器
并获得增强的文档体验
开始
微型自动编码器
微型自动编码器 (TAESD) 由 Ollin Boer Bohan 在 madebyollin/taesd 中引入,用于 Stable Diffusion。 它是 Stable Diffusion VAE 的微型精馏版本,可以几乎立即快速解码 StableDiffusionPipeline 或 StableDiffusionXLPipeline 中的潜在表示。
用于 Stable Diffusion v-2.1
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
image
用于 Stable Diffusion XL 1.0
import torch
from diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25).images[0]
image
AutoencoderTiny
class diffusers.AutoencoderTiny
< 源代码 >( in_channels: int = 3 out_channels: int = 3 encoder_block_out_channels: typing.Tuple[int, ...] = (64, 64, 64, 64) decoder_block_out_channels: typing.Tuple[int, ...] = (64, 64, 64, 64) act_fn: str = 'relu' upsample_fn: str = 'nearest' latent_channels: int = 4 upsampling_scaling_factor: int = 2 num_encoder_blocks: typing.Tuple[int, ...] = (1, 3, 3, 3) num_decoder_blocks: typing.Tuple[int, ...] = (3, 3, 3, 1) latent_magnitude: int = 3 latent_shift: float = 0.5 force_upcast: bool = False scaling_factor: float = 1.0 shift_factor: float = 0.0 )
参数
- in_channels (
int
, 可选的, 默认为 3) — 输入图像中的通道数。 - out_channels (
int
, 可选的, 默认为 3) — 输出中的通道数。 - encoder_block_out_channels (
Tuple[int]
, 可选的, 默认为(64, 64, 64, 64)
) — 表示每个编码器块的输出通道数的整数元组。元组的长度应等于编码器块的数量。 - decoder_block_out_channels (
Tuple[int]
, 可选的, 默认为(64, 64, 64, 64)
) — 表示每个解码器块的输出通道数的整数元组。元组的长度应等于解码器块的数量。 - act_fn (
str
, 可选的, 默认为"relu"
) — 在整个模型中使用的激活函数。 - latent_channels (
int
, 可选的, 默认为 4) — 潜在表示中的通道数。潜在空间充当输入图像的压缩表示。 - upsampling_scaling_factor (
int
, 可选的, 默认为 2) — 解码器中上采样的缩放因子。它决定了上采样过程中输出图像的大小。 - num_encoder_blocks (
Tuple[int]
, 可选的, 默认为(1, 3, 3, 3)
) — 表示编码过程中每个阶段的编码器块数量的整数元组。元组的长度应等于编码器中阶段的数量。每个阶段具有不同数量的编码器块。 - num_decoder_blocks (
Tuple[int]
,可选的,默认为(3, 3, 3, 1)
) — 整数元组,表示解码过程中每个阶段的解码器模块数量。元组的长度应等于解码器中的阶段数。每个阶段具有不同数量的解码器模块。 - latent_magnitude (
float
,可选的,默认为 3.0) — 潜在表示的幅度。此参数缩放潜在表示值,以控制信息保留的程度。 - latent_shift (float, 可选的,默认为 0.5) — 应用于潜在表示的偏移。此参数控制潜在空间的中心。
- scaling_factor (
float
,可选的,默认为 1.0) — 使用训练集的第一批数据计算出的训练后潜在空间的component-wise标准差。这用于在训练扩散模型时缩放潜在空间以使其具有单位方差。潜在变量在传递到扩散模型之前,会使用公式z = z * scaling_factor
进行缩放。解码时,潜在变量会使用公式z = 1 / scaling_factor * z
缩放回原始尺度。有关更多详细信息,请参阅 High-Resolution Image Synthesis with Latent Diffusion Models 论文的 4.3.2 和 D.1 节。然而,对于此 Autoencoder,未使用此类缩放因子,因此默认值为 1.0。 - force_upcast (
bool
,*可选的*,默认为False
) — 如果启用,它将强制 VAE 在 float32 中运行,以用于高图像分辨率管道,例如 SD-XL。VAE 可以被微调/训练到较低的范围而不会损失太多精度,在这种情况下,force_upcast
可以设置为False
(参见这个 fp16 友好的 AutoEncoder)。
一个微小的 distilled VAE 模型,用于将图像编码为潜在变量,并将潜在表示解码为图像。
AutoencoderTiny 是对 TAESD
原始实现的封装。
此模型继承自 ModelMixin。请查阅超类文档,了解其为所有模型实现的通用方法(例如下载或保存)。
禁用 sliced VAE 解码。如果之前启用了 enable_slicing
,此方法将恢复为一步计算解码。
禁用 tiled VAE 解码。如果之前启用了 enable_tiling
,此方法将恢复为一步计算解码。
启用 sliced VAE 解码。启用此选项后,VAE 将输入张量拆分为切片,以分步计算解码。这有助于节省一些内存并允许更大的批量大小。
启用 tiled VAE 解码。启用此选项后,VAE 会将输入张量拆分为图块,以分步计算解码和编码。这对于节省大量内存并允许处理更大的图像非常有用。
raw latents -> [0, 1]
[0, 1] -> raw latents
AutoencoderTinyOutput
class diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput
< source >( latents: Tensor )
AutoencoderTiny 编码方法的输出。