Diffusers documentation

AutoencoderKLMochi

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

AutoencoderKLMochi

Mochi에서 사용된 KL 손실을 적용한 3D 변분 오토인코더(VAE) 모델은 Tsinghua University & ZhipuAI의 Mochi 1 Preview에서 소개되었습니다.

다음 코드 스니펫으로 모델을 로드할 수 있습니다.

from diffusers import AutoencoderKLMochi

vae = AutoencoderKLMochi.from_pretrained("genmo/mochi-1-preview", subfolder="vae", dtype=torch.float32).to("cuda")  # or "mps", "xpu", "cpu"

AutoencoderKLMochi

class diffusers.AutoencoderKLMochi

< >

( in_channels: int = 15out_channels: int = 3encoder_block_out_channels: tuple = (64, 128, 256, 384)decoder_block_out_channels: tuple = (128, 256, 512, 768)latent_channels: int = 12layers_per_block: tuple = (3, 3, 4, 6, 3)act_fn: str = 'silu'temporal_expansions: tuple = (1, 2, 3)spatial_expansions: tuple = (2, 2, 2)add_attention_block: tuple = (False, True, True, True, True)latents_mean: tuple = (-0.06730895953510081, -0.038011381506090416, -0.07477820912866141, -0.05565264470995561, 0.012767231469026969, -0.04703542746246419, 0.043896967884726704, -0.09346305707025976, -0.09918314763016893, -0.008729793427399178, -0.011931556316503654, -0.0321993391887285)latents_std: tuple = (0.9263795028493863, 0.9248894543193766, 0.9393059390890617, 0.959253732819592, 0.8244560132752793, 0.917259975397747, 0.9294154431013696, 1.3720942357788521, 0.881393668867029, 0.9168315692124348, 0.9185249279345552, 0.9274757570805041)scaling_factor: float = 1.0 )

매개변수

  • in_channels (int, 선택 사항, 기본값 3) — 입력 이미지의 채널 수.
  • out_channels (int, 선택 사항, 기본값 3) — 출력의 채널 수.
  • block_out_channels (tuple[int], 선택 사항, 기본값 (64,)) — 블록 출력 채널의 튜플입니다.
  • act_fn (str, 선택 사항, 기본값 "silu") — 사용할 활성화 함수입니다.
  • scaling_factor (float, 선택 사항, 기본값 1.15258426) — 학습 세트의 첫 번째 배치(first batch)를 사용하여 계산된 학습된 잠재 공간(latent space)의 구성 요소별(component-wise) 표준 편차입니다. 이는 diffusion model을 학습할 때 잠재 공간의 분산을 1로 만들기 위해 사용됩니다. 잠재 변수(latents)는 z = z * scaling_factor 공식으로 스케일링된 후 diffusion model에 전달됩니다. 디코딩 시에는 z = 1 / scaling_factor * z 공식을 사용하여 원래의 스케일로 되돌립니다. 자세한 내용은 High-Resolution Image Synthesis with Latent Diffusion Models 논문의 4.3.2절과 D.1절을 참조하세요.

KL 손실을 사용하여 이미지를 잠재 변수로 인코딩하고 잠재 표현을 이미지로 디코딩하는 VAE 모델입니다. Mochi 1 preview에 사용됩니다.

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

decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

매개변수

  • z (torch.Tensor) — 잠재 벡터의 입력 배치.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~models.vae.DecoderOutput를 반환할지 여부.

반환값

~models.vae.DecoderOutput 또는 tuple

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

이미지 배치(decode)를 디코딩합니다.

enable_tiling

< >

( 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 )

매개변수

  • tile_sample_min_height (int, 선택 사항) — 높이 차원에서 샘플이 타일로 분리되려면 필요한 최소 높이입니다.
  • tile_sample_min_width (int, 선택 사항) — 샘플이 너비 차원으로 타일 분리되려면 필요한 최소 너비입니다.
  • tile_sample_stride_height (int, 선택 사항) — 연속된 세로 타일 사이의 최소 겹침 양입니다. 이는 높이 차원에서 타일링 아티팩트가 발생하지 않도록 보장하기 위한 것입니다.
  • tile_sample_stride_width (int, 선택 사항) — 연속된 두 수평 타일 사이의 스트라이드입니다. 이는 너비 차원에서 타일링 아티팩트가 발생하지 않도록 보장하기 위한 것입니다.

타일 VAE 디코딩을 활성화합니다. 이 옵션이 활성화되면 VAE는 입력 텐서를 타일로 분할하여 디코딩 및 인코딩을 여러 단계로 계산합니다. 이는 대량의 메모리를 절약하고 더 큰 이미지를 처리할 수 있도록 하는 데 유용합니다.

encode

< >

( x: Tensorreturn_dict: bool = True )

매개변수

  • x (torch.Tensor) — 이미지 입력 배치.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~models.autoencoder_kl.AutoencoderKLOutput을 반환할지 여부.

이미지 배치(latents)를 인코딩합니다.

forward

< >

( sample: Tensorsample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → ~models.vae.DecoderOutput or tuple

매개변수

  • sample (torch.Tensor) — 입력 샘플.
  • sample_posterior (bool, 선택 사항, 기본값 False) — 후분포에서 샘플링할지 여부.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 DecoderOutput를 반환할지 여부.
  • generator (torch.Generator, 선택 사항) — 샘플링을 결정적으로 만들기 위한 torch.Generator.

반환값

~models.vae.DecoderOutput 또는 tuple

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

tiled_decode

< >

( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple

매개변수

  • z (torch.Tensor) — 잠재 벡터의 입력 배치.
  • return_dict (bool, 선택 사항, 기본값 True) — ~models.vae.DecoderOutput를 반환할지, 아니면 일반 튜플을 반환할지를 결정합니다.

반환값

~models.vae.DecoderOutput 또는 tuple

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

tiled decoder를 사용하여 이미지 배치(decoding)를 디코딩합니다.

tiled_encode

< >

( x: Tensor ) → torch.Tensor

매개변수

  • x (torch.Tensor) — 비디오 입력 배치.

반환값

torch.Tensor

인코딩된 비디오의 잠재 표현(latent representation).

타일 인코더를 사용하여 이미지 배치 인코딩

DecoderOutput

class diffusers.models.autoencoders.vae.DecoderOutput

< >

( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )

매개변수

  • sample (torch.Tensor, shape (batch_size, num_channels, height, width)) — 모델의 마지막 레이어에서 디코딩된 출력 샘플입니다.

디코딩 메서드의 출력.

Update on GitHub