Diffusers documentation

Tiny AutoEncoder

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

Tiny AutoEncoder

Stable Diffusion용 Tiny AutoEncoder(TAESD)는 Ollin Boer Bohan이 madebyollin/taesd에서 소개했습니다. 이는 Stable Diffusion의 VAE를 아주 작게 증류한 버전으로, StableDiffusionPipeline 또는 StableDiffusionXLPipeline의 latents를 거의 즉시 빠르게 디코딩할 수 있습니다.

Stable Diffusion v-2.1과 함께 사용하려면:

import torch
from diffusers import DiffusionPipeline, AutoencoderTiny

pipe = DiffusionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-1-base", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", dtype=torch.float16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

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", dtype=torch.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", dtype=torch.float16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

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 = 3out_channels: int = 3encoder_block_out_channels: tuple = (64, 64, 64, 64)decoder_block_out_channels: tuple = (64, 64, 64, 64)act_fn: str = 'relu'upsample_fn: str = 'nearest'latent_channels: int = 4upsampling_scaling_factor: int = 2num_encoder_blocks: tuple = (1, 3, 3, 3)num_decoder_blocks: tuple = (3, 3, 3, 1)latent_magnitude: int = 3latent_shift: float = 0.5force_upcast: bool = Falsescaling_factor: float = 1.0shift_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)) — 각 decoder block의 출력 채널 수를 나타내는 정수 튜플입니다. 튜플의 길이는 decoder block의 수와 같아야 합니다.
  • 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) — Latent representation에 적용되는 shift입니다. 이 파라미터는 latent space의 중심을 제어합니다.
  • scaling_factor (float, 선택 사항, 기본값 1.0) — 학습 세트의 첫 번째 배치(first batch)를 사용하여 계산된 학습된 잠재 공간(latent space)의 구성 요소별(component-wise) 표준 편차입니다. 이는 diffusion model을 학습할 때 잠재 공간의 분산을 1로 조정하는 데 사용됩니다. 잠재 변수(latents)는 diffusion model에 전달되기 전에 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) — 활성화하면 SD-XL과 같은 고해상도 이미지 파이프라인에서 VAE가 float32로 실행되도록 강제합니다. VAE는 정밀도가 크게 손실되지 않는 범위 내에서 더 낮은 범위로 미세 조정/학습될 수 있으며, 이 경우 force_upcast를 False로 설정할 수 있습니다(이 fp16 호환 AutoEncoder를 참조).

이미지를 latent으로 인코딩하고 latent 표현을 이미지로 디코딩하는 작은 distilled VAE 모델입니다.

AutoencoderTiny는 TAESD의 원래 구현을 감싸는 래퍼입니다.

이 모델은 ModelMixin에서 상속됩니다. 모든 모델에 대해 구현된 일반적 메서드(다운로드 또는 저장 등)에 대해서는 상위 클래스 문서를 확인하세요.

forward

< >

( sample: Tensorreturn_dict: bool = True ) → DecoderOutput or tuple

매개변수

  • sample (torch.Tensor) — 입력 샘플.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 DecoderOutput를 반환할지 여부.

반환값

DecoderOutput 또는 tuple

return_dict가 True이면 DecoderOutput가 반환되고, 그렇지 않으면 일반 tuple이 반환됩니다.

scale_latents

< >

( x: Tensor )

raw latents -> [0, 1]

unscale_latents

< >

( x: Tensor )

[0, 1] -> 원시 잠재 변수

AutoencoderTinyOutput

클래스 diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput

< >

( latents: Tensor )

매개변수

  • latents (torch.Tensor) — Encoder의 인코딩된 출력입니다.

AutoencoderTiny 인코딩 메서드의 출력.

Update on GitHub