Diffusers documentation
Consistency Decoder
Consistency Decoder
Consistency decoder는 StableDiffusionPipeline에서 denoising UNet의 latents를 디코딩하는 데 사용할 수 있습니다. 이 decoder는 DALL-E 3 technical report에서 소개되었습니다.
원본 코드베이스는 openai/consistencydecoder에서 찾을 수 있습니다.
현재 Inference는 2회 반복만 지원됩니다.
이 파이프라인은 이 이슈에서 madebyollin와 mrsteyk의 도움 없이는 기여할 수 없었습니다.
ConsistencyDecoderVAE
클래스 diffusers.ConsistencyDecoderVAE
< source >( scaling_factor: float = 0.18215latent_channels: int = 4sample_size: int = 32encoder_act_fn: str = 'silu'encoder_block_out_channels: tuple = (128, 256, 512, 512)encoder_double_z: bool = Trueencoder_down_block_types: tuple = ('DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D')encoder_in_channels: int = 3encoder_layers_per_block: int = 2encoder_norm_num_groups: int = 32encoder_out_channels: int = 4decoder_add_attention: bool = Falsedecoder_block_out_channels: tuple = (320, 640, 1024, 1024)decoder_down_block_types: tuple = ('ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D')decoder_downsample_padding: int = 1decoder_in_channels: int = 7decoder_layers_per_block: int = 3decoder_norm_eps: float = 1e-05decoder_norm_num_groups: int = 32decoder_num_train_timesteps: int = 1024decoder_out_channels: int = 6decoder_resnet_time_scale_shift: str = 'scale_shift'decoder_time_embedding_type: str = 'learned'decoder_up_block_types: tuple = ('ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D') )
DALL-E 3과 함께 사용되는 일관성 디코더입니다.
예:
>>> import torch
>>> from diffusers import StableDiffusionPipeline, ConsistencyDecoderVAE
>>> vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=torch.float16)
>>> pipe = StableDiffusionPipeline.from_pretrained(
... "stable-diffusion-v1-5/stable-diffusion-v1-5", vae=vae, torch_dtype=torch.float16
... ).to("cuda")
>>> image = pipe("horse", generator=torch.manual_seed(0)).images[0]
>>> imagedecode
< source >( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = Truenum_inference_steps: int = 2 ) → DecoderOutput | tuple[torch.Tensor]
consistency decoder VAE 모델을 사용하여 입력 잠재 벡터 z를 디코딩합니다.
encode
< source >( x: Tensorreturn_dict: bool = True )
이미지 배치(latents)를 인코딩합니다.
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, 선택 사항, 기본값None) — 샘플링에 사용할 Generator입니다.
반환값
DecoderOutput 또는 tuple
return_dict가 True이면 DecoderOutput가 반환되고, 그렇지 않으면 일반 tuple이 반환됩니다.
커스텀 어텐션 프로세서를 비활성화하고 기본 어텐션 구현을 설정합니다.
tiled_encode
< source >( x: Tensorreturn_dict: bool = True ) → ConsistencyDecoderVAEOutput or tuple
타일 인코더를 사용하여 이미지 배치 인코딩
이 옵션이 활성화되면 VAE는 입력 텐서를 타일로 분할하여 여러 단계에 걸쳐 인코딩을 계산합니다. 이는 이미지 크기와 관계없이 메모리 사용량을 일정하게 유지하는 데 유용합니다. 타일 인코딩의 최종 결과는 타일마다 다른 인코더를 사용하기 때문에 타일링되지 않은 인코딩과 다릅니다. 타일링 아티팩트를 방지하기 위해 타일들은 겹쳐지고 블렌딩되어 매끄러운 출력을 형성합니다. 출력에서 여전히 타일 크기의 변화가 보일 수 있지만, 훨씬 덜 눈에 띄어야 합니다.