Diffusers documentation

فكّ الترميز المتّسق

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

فكّ الترميز المتّسق

يمكن استخدام فاحص الاتساق (Consistency decoder) لفك ترميز الكمونيات (latents) من شبكة UNet لإزالة الضوضاء في StableDiffusionPipeline. وقد تم تقديم هذا الفاحص في التقرير التقني الخاص بـ DALL-E 3.

يمكن العثور على قاعدة الكود الأصلية في openai/consistencydecoder.

حاليًا، يُدعم الاستدلال (Inference) لتكرارين فقط.

لم يكن بالإمكان المساهمة في خط المعالجة لولا مساعدة madebyollin وmrsteyk من هذه المشكلة.

ConsistencyDecoderVAE

فئة diffusers.ConsistencyDecoderVAE

< >

( scaling_factor: float = 0.18215latent_channels: int = 4sample_size: int = 32encoder_act_fn: str = 'silu'encoder_block_out_channels: tuple[int, ...] = (128, 256, 512, 512)encoder_double_z: bool = Trueencoder_down_block_types: tuple[str, ...] = ('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[int, ...] = (320, 640, 1024, 1024)decoder_down_block_types: tuple[str, ...] = ('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[str, ...] = ('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]
>>> image

decode

< >

( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = Truenum_inference_steps: int = 2 ) → DecoderOutput | tuple[torch.Tensor]

المعاملات

  • z (torch.Tensor) — متجه الكمون المُدخل.
  • generator (torch.Generator | None) — مولّد الأرقام العشوائية. القيمة الافتراضية هي None.
  • return_dict (bool) — ما إذا كان يجب إرجاع المخرجات على شكل قاموس. القيمة الافتراضية هي True.
  • num_inference_steps (int) — عدد خطوات الاستدلال. القيمة الافتراضية هي 2.

يعيد

DecoderOutput | tuple[torch.Tensor]

المخرجات المُفكَّكة.

يفكك الترميز المتجه الكامن المدخل z باستخدام نموذج VAE لفك الترميز المتسق.

encode

< >

( x: Tensorreturn_dict: bool = True )

المعاملات

  • x (torch.Tensor) — دفعة مدخلات من الصور.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ConsistencyDecoderVAEOutput بدلاً من tuple عادي.

ترميز دفعة من الصور إلى كامنات.

forward

< >

( 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 بدلاً من tuple عادي.
  • generator (torch.Generator، اختياري، الافتراضي None) — المولّد المستخدم لأخذ العينات.

يعيد

DecoderOutput أو tuple

If return_dict is True, a DecoderOutput is returned, otherwise a plain tuple is returned.

set_default_attn_processor

< >

( )

يعطّل معالجات الانتباه المخصصة ويضبط تطبيق الانتباه الافتراضي.

tiled_encode

< >

( x: Tensorreturn_dict: bool = True ) → ConsistencyDecoderVAEOutput or tuple

المعاملات

  • x (torch.Tensor) — دفعة مدخلات من الصور.
  • return_dict (bool، اختياري، القيمة الافتراضية True) — ما إذا كان يجب إرجاع ConsistencyDecoderVAEOutput بدلاً من tuple بسيط.

يعيد

ConsistencyDecoderVAEOutput أو tuple

If return_dict is True, a ConsistencyDecoderVAEOutput is returned, otherwise a plain tuple is returned.

ترميز دفعة من الصور باستخدام مُرمِّز مُقسَّم إلى بلاطات.

عند تمكين هذا الخيار، سيقوم VAE بتقسيم المصفوفة المدخلة إلى بلاطات لحساب الترميز في عدة خطوات. وهذا مفيد للحفاظ على ثبات استخدام الذاكرة بغض النظر عن حجم الصورة. النتيجة النهائية للترميز المبطن تختلف عن الترميز غير المبطن لأن كل بلاطة تستخدم مشفراً مختلفاً. لتجنب آثار التبطين، تتداخل البلاطات وتُدمج معاً لتكوين مخرجات سلسة. قد لا تزال ترى تغييرات بحجم البلاطة في المخرجات، لكنها يجب أن تكون أقل وضوحاً بكثير.

Update on GitHub