Buckets:

hf-doc-build/doc / diffusers /v0.43.0 /ar /api /models /consistency_decoder_vae.md
mishig's picture
|
download
raw
7.84 kB

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

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

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

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

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

ConsistencyDecoderVAE[[diffusers.ConsistencyDecoderVAE]]

diffusers.ConsistencyDecoderVAE[[diffusers.ConsistencyDecoderVAE]]

diffusers.ConsistencyDecoderVAE(scaling_factor: float = 0.18215, latent_channels: int = 4, sample_size: int = 32, encoder_act_fn: str = 'silu', encoder_block_out_channels: tuple[int, ...] = (128, 256, 512, 512), encoder_double_z: bool = True, encoder_down_block_types: tuple[str, ...] = ('DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'), encoder_in_channels: int = 3, encoder_layers_per_block: int = 2, encoder_norm_num_groups: int = 32, encoder_out_channels: int = 4, decoder_add_attention: bool = False, decoder_block_out_channels: tuple[int, ...] = (320, 640, 1024, 1024), decoder_down_block_types: tuple[str, ...] = ('ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D'), decoder_downsample_padding: int = 1, decoder_in_channels: int = 7, decoder_layers_per_block: int = 3, decoder_norm_eps: float = 1e-05, decoder_norm_num_groups: int = 32, decoder_num_train_timesteps: int = 1024, decoder_out_channels: int = 6, decoder_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

فك الترميز[[diffusers.ConsistencyDecoderVAE.decode]]

decode(z: Tensor, generator: typing.Optional[torch.Generator] = None, return_dict: bool = True, num_inference_steps: int = 2)

المصدر

المعاملات:

z (torch.Tensor) : متجه الكامنة المُدخل.

generator (torch.Generator | None) : مولّد الأرقام العشوائية. القيمة الافتراضية هي None.

return_dict (bool) : ما إذا كان يجب إرجاع المخرجات على شكل قاموس. القيمة الافتراضية هي True.

num_inference_steps (int) : عدد خطوات الاستدلال. القيمة الافتراضية هي 2.

يعيد: DecoderOutput | tuple[torch.Tensor]

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

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

ترميز[[diffusers.ConsistencyDecoderVAE.encode]]

encode(x: Tensor, return_dict: bool = True)

المصدر

المعاملات:

x (torch.Tensor) : دفعة من الصور المدخلة.

return_dict (bool، اختياري، القيمة الافتراضية True) : ما إذا كان يجب إرجاع ConsistencyDecoderVAEOutput بدلاً من tuple عادي.

يعيد:

تمثيلات الكامنة للصور المُرمّزة. إذا كان return_dict صحيحًا (True)، يُعاد ConsistencyDecoderVAEOutput، وإلا يُعاد tuple عادي.

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

forward[[diffusers.ConsistencyDecoderVAE.forward]]

forward(sample: Tensor, sample_posterior: bool = False, return_dict: bool = True, generator: typing.Optional[torch.Generator] = None)

المصدر

المعاملات:

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[[diffusers.ConsistencyDecoderVAE.set_default_attn_processor]]

set_default_attn_processor()

المصدر

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

tiled_encode[[diffusers.ConsistencyDecoderVAE.tiled_encode]]

tiled_encode(x: Tensor, return_dict: bool = True)

المصدر

المعاملات:

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 بتقسيم المصفوفة المدخلة إلى بلاطات لحساب الترميز في عدة خطوات. وهذا مفيد للحفاظ على ثبات استخدام الذاكرة بغض النظر عن حجم الصورة. النتيجة النهائية للترميز المبطن تختلف عن الترميز غير المبطن لأن كل بلاطة تستخدم مُرمِّزًا مختلفًا. ولتجنب آثار التبطين، تتداخل البلاطات وتُدمج معًا لتكوين مخرجات سلسة. قد لا تزال ترى تغييرات بحجم البلاطة في المخرجات، لكنها يجب أن تكون أقل وضوحًا بكثير.

Xet Storage Details

Size:
7.84 kB
·
Xet hash:
063349a49418547f24d486c237fad03e8f1e20b060012caa7b1e096c2bfe4464

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.