Diffusers 文件

Tiny AutoEncoder

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

微型自動編碼器

用於 Stable Diffusion (TAESD) 的微型自動編碼器由 Ollin Boer Bohan 在 madebyollin/taesd 中引入。它是 Stable Diffusion 的 VAE 的一個微型精煉版本,可以幾乎即時地解碼 StableDiffusionPipelineStableDiffusionXLPipeline 中的潛在變數。

與 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

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) — 使用訓練集的第一批計算出的訓練潛在空間的元件式標準差。這用於在訓練擴散模型時將潛在空間縮放為單位方差。在傳遞給擴散模型之前,潛在變數會按照公式 z = z * scaling_factor 進行縮放。解碼時,潛在變數會按照公式 z = 1 / scaling_factor * z 縮放回原始比例。有關更多詳細資訊,請參閱 使用潛在擴散模型進行高解析度影像合成 論文的第 4.3.2 和 D.1 節。然而,此自動編碼器未使用此類縮放因子,因此預設值為 1.0。
  • force_upcast (bool, 可選, 預設為 False) — 如果啟用,它將強制 VAE 以 float32 執行,以用於高影像解析度的管道,例如 SD-XL。VAE 可以進行微調/訓練以降低範圍而不會損失太多精度,在這種情況下,force_upcast 可以設定為 False(請參閱此支援 fp16 的 自動編碼器)。

一個微型精煉 VAE 模型,用於將影像編碼為潛在變數並將潛在表示解碼為影像。

AutoencoderTinyTAESD 原始實現的包裝器。

此模型繼承自 ModelMixin。有關為其所有模型實現的通用方法(例如下載或儲存),請查閱超類文件。

停用切片

< >

( )

停用切片 VAE 解碼。如果之前啟用了 enable_slicing,此方法將恢復一步計算解碼。

停用平鋪

< >

( )

停用平鋪 VAE 解碼。如果之前啟用了 enable_tiling,此方法將恢復一步計算解碼。

啟用切片

< >

( )

啟用切片 VAE 解碼。啟用此選項後,VAE 會將輸入張量分片,分步計算解碼。這有助於節省一些記憶體並允許更大的批次大小。

啟用平鋪

< >

( use_tiling: bool = True )

啟用平鋪 VAE 解碼。啟用此選項後,VAE 將把輸入張量分割成瓦片,分多步計算編碼和解碼。這對於節省大量記憶體和處理更大的影像非常有用。

前向

< >

( sample: Tensor return_dict: bool = True )

引數

  • sample (torch.Tensor) — 輸入樣本。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 DecoderOutput 而不是普通元組。

縮放潛在變數

< >

( x: Tensor )

原始潛在變數 -> [0, 1]

取消縮放潛在變數

< >

( x: Tensor )

[0, 1] -> 原始潛在變數

AutoencoderTinyOutput

diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput

< >

( latents: Tensor )

引數

  • latents (torch.Tensor) — Encoder 的編碼輸出。

AutoencoderTiny 編碼方法的輸出。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.