





"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import CTRLConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.ctrl.modeling_tf_ctrl import (
       TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFCTRLForSequenceClassification,
       TFCTRLLMHeadModel,
       TFCTRLModel,
   )



class    lowercase_ (   __lowerCAmelCase							):

       def __init__(	self      ,    __SCREAMING_SNAKE_CASE      ,    ):






        '''simple docstring'''

        snake_case__										= parent
        snake_case__										= 13
        snake_case__										= 7
        snake_case__										= True
        snake_case__										= True
        snake_case__										= True
        snake_case__										= True
        snake_case__										= True
        snake_case__										= 99
        snake_case__										= 32
        snake_case__										= 2
        snake_case__										= 4
        snake_case__										= 37
        snake_case__										= "gelu"
        snake_case__										= 0.1
        snake_case__										= 0.1
        snake_case__										= 512
        snake_case__										= 16
        snake_case__										= 2
        snake_case__										= 0.02
        snake_case__										= 3
        snake_case__										= 4
        snake_case__										= None
        snake_case__										= self.vocab_size - 1

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size   )

        snake_case__										= None
        if self.use_input_mask:
         snake_case__										= random_attention_mask([self.batch_size, self.seq_length]   )

        snake_case__										= None
        if self.use_token_type_ids:
         snake_case__										= ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size   )

        snake_case__										= None
        if self.use_mc_token_ids:
         snake_case__										= ids_tensor([self.batch_size, self.num_choices]      ,    self.seq_length   )

        snake_case__										= None
        snake_case__										= None
        snake_case__										= None
        if self.use_labels:
         snake_case__										= ids_tensor([self.batch_size]      ,    self.type_sequence_label_size   )
         snake_case__										= ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels   )
         snake_case__										= ids_tensor([self.batch_size]      ,    self.num_choices   )

        snake_case__										= CTRLConfig(
            vocab_size=self.vocab_size      ,    n_embd=self.hidden_size      ,    n_layer=self.num_hidden_layers      ,    n_head=self.num_attention_heads      ,    n_positions=self.max_position_embeddings      ,    pad_token_id=self.pad_token_id      ,    )

        snake_case__										= ids_tensor([self.num_hidden_layers, self.num_attention_heads]      ,    2   )

        return (
            config,
            input_ids,
            input_mask,
            head_mask,
            token_type_ids,
            mc_token_ids,
            sequence_labels,
            token_labels,
            choice_labels,
        )

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    *__SCREAMING_SNAKE_CASE   ):






        '''simple docstring'''

        snake_case__										= TFCTRLModel(config=__SCREAMING_SNAKE_CASE   )
        snake_case__										= {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        snake_case__										= model(__SCREAMING_SNAKE_CASE   )

        snake_case__										= [input_ids, None, input_mask]  # None is the input for 'past'
        snake_case__										= model(__SCREAMING_SNAKE_CASE   )

        snake_case__										= model(__SCREAMING_SNAKE_CASE   )

        self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size)   )

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    *__SCREAMING_SNAKE_CASE   ):






        '''simple docstring'''

        snake_case__										= TFCTRLLMHeadModel(config=__SCREAMING_SNAKE_CASE   )
        snake_case__										= {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
        snake_case__										= model(__SCREAMING_SNAKE_CASE   )
        self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size)   )

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    *__SCREAMING_SNAKE_CASE   ):






        '''simple docstring'''

        snake_case__										= self.num_labels
        snake_case__										= ids_tensor([self.batch_size]      ,    self.type_sequence_label_size   )
        snake_case__										= {
            "input_ids": input_ids,
            "token_type_ids": token_type_ids,
            "labels": sequence_labels,
        }
        snake_case__										= TFCTRLForSequenceClassification(__SCREAMING_SNAKE_CASE   )
        snake_case__										= model(__SCREAMING_SNAKE_CASE   )
        self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels)   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.prepare_config_and_inputs()

        (
            (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      (
            snake_case__
        )							,      
        )										= config_and_inputs

        snake_case__										= {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict



@require_tf
class    lowercase_ (   __lowerCAmelCase ,__lowerCAmelCase ,unittest.TestCase							):
       snake_case__ :							List[Any] 							=   (TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
       snake_case__ :							Union[str, Any] 							=   (TFCTRLLMHeadModel,) if is_tf_available() else ()
       snake_case__ :							Optional[Any] 							=   (
           {
               """feature-extraction""": TFCTRLModel,
               """text-classification""": TFCTRLForSequenceClassification,
               """text-generation""": TFCTRLLMHeadModel,
               """zero-shot""": TFCTRLForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       snake_case__ :							Optional[Any] 							=   False
       snake_case__ :							Optional[int] 							=   False

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   ):






        '''simple docstring'''

        if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
         # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
         # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
         # config could not be created.
         return True

        return False

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= TFCTRLModelTester(self   )
        snake_case__										= ConfigTester(self      ,    config_class=__SCREAMING_SNAKE_CASE      ,    n_embd=37   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        self.config_tester.run_common_tests()

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_model(*__SCREAMING_SNAKE_CASE   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_lm_head(*__SCREAMING_SNAKE_CASE   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_for_sequence_classification(*__SCREAMING_SNAKE_CASE   )

       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__							,      snake_case__										= self.model_tester.prepare_config_and_inputs_for_common()
        snake_case__										= [TFCTRLLMHeadModel]
        snake_case__										= [TFCTRLForSequenceClassification]

        for model_class in self.all_model_classes:
         snake_case__										= model_class(__SCREAMING_SNAKE_CASE   )
         model.build()  # may be needed for the get_bias() call below
         assert isinstance(model.get_input_embeddings()      ,    tf.keras.layers.Layer   )

         if model_class in list_lm_models:
          snake_case__										= model.get_output_embeddings()
          assert isinstance(__SCREAMING_SNAKE_CASE      ,    tf.keras.layers.Layer   )
          snake_case__										= model.get_bias()
          assert isinstance(__SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   )
          for k, v in name.items():
           assert isinstance(__SCREAMING_SNAKE_CASE      ,    tf.Variable   )
         elif model_class in list_other_models_with_output_ebd:
          snake_case__										= model.get_output_embeddings()
          assert isinstance(__SCREAMING_SNAKE_CASE      ,    tf.keras.layers.Layer   )
          snake_case__										= model.get_bias()
          assert name is None
         else:
          snake_case__										= model.get_output_embeddings()
          assert x is None
          snake_case__										= model.get_bias()
          assert name is None

       @slow
       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         snake_case__										= TFCTRLModel.from_pretrained(__SCREAMING_SNAKE_CASE   )
         self.assertIsNotNone(__SCREAMING_SNAKE_CASE   )



@require_tf
class    lowercase_ (   unittest.TestCase							):

       @slow
       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        snake_case__										= TFCTRLLMHeadModel.from_pretrained("ctrl"   )
        snake_case__										= tf.convert_to_tensor([[1_1859, 0, 1611, 8]]      ,    dtype=tf.intaa   )  # Legal the president is
        snake_case__										= [
            1_1859,
            0,
            1611,
            8,
            5,
            150,
            2_6449,
            2,
            19,
            348,
            469,
            3,
            2595,
            48,
            2_0740,
            24_6533,
            24_6533,
            19,
            30,
            5,
        ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

        snake_case__										= model.generate(__SCREAMING_SNAKE_CASE      ,    do_sample=__SCREAMING_SNAKE_CASE   )
        self.assertListEqual(output_ids[0].numpy().tolist()      ,    __SCREAMING_SNAKE_CASE   )








"""simple docstring"""


import types
from typing import List, Optional, Tuple, Union

import torch
from transformers import CLIPTextModelWithProjection, CLIPTokenizer
from transformers.models.clip.modeling_clip import CLIPTextModelOutput

from diffusers.models import PriorTransformer
from diffusers.pipelines import DiffusionPipeline, StableDiffusionImageVariationPipeline
from diffusers.schedulers import UnCLIPScheduler
from diffusers.utils import logging, randn_tensor


a__    :   Optional[int]    						= logging.get_logger(__name__)  # pylint: disable=invalid-name





def 							a__	(     self		,   _UpperCAmelCase		,   _UpperCAmelCase		,   _UpperCAmelCase		,   _UpperCAmelCase		)			->     List[str]:

 '''simple docstring'''






 snake_case__										= image.to(device=_UpperCAmelCase		)
 snake_case__										= image  # take image as image_embeddings
 snake_case__										= image_embeddings.unsqueeze(1		)

 # duplicate image embeddings for each generation per prompt, using mps friendly method
 snake_case__							,      snake_case__							,      snake_case__										= image_embeddings.shape
 snake_case__										= image_embeddings.repeat(1		,   _UpperCAmelCase		,   1		)
 snake_case__										= image_embeddings.view(bs_embed * num_images_per_prompt		,   _UpperCAmelCase		,   -1		)

 if do_classifier_free_guidance:
  snake_case__										= torch.zeros_like(_UpperCAmelCase		)

  # For classifier free guidance, we need to do two forward passes.
  # Here we concatenate the unconditional and text embeddings into a single batch
  # to avoid doing two forward passes
  snake_case__										= torch.cat([uncond_embeddings, image_embeddings]		)

 return image_embeddings



class    lowercase_ (   __lowerCAmelCase							):

       def __init__(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE = None      ,    ):






        '''simple docstring'''

        super().__init__()

        snake_case__										= {"image_encoder": None} if decoder_pipe_kwargs is None else decoder_pipe_kwargs

        snake_case__										= decoder_pipe_kwargs.get("torch_dtype"      ,    __SCREAMING_SNAKE_CASE   ) or prior.dtype

        snake_case__										= StableDiffusionImageVariationPipeline.from_pretrained(
            "lambdalabs/sd-image-variations-diffusers"      ,    **__SCREAMING_SNAKE_CASE   )

        # replace `_encode_image` method
        snake_case__										= types.MethodType(_encode_image      ,    self.decoder_pipe   )

        self.register_modules(
            prior=__SCREAMING_SNAKE_CASE      ,    tokenizer=__SCREAMING_SNAKE_CASE      ,    text_encoder=__SCREAMING_SNAKE_CASE      ,    prior_scheduler=__SCREAMING_SNAKE_CASE      ,    )

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    ):






        '''simple docstring'''

        if text_model_output is None:
         snake_case__										= len(__SCREAMING_SNAKE_CASE   ) if isinstance(__SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   ) else 1
         # get prompt text embeddings
         snake_case__										= self.tokenizer(
             __SCREAMING_SNAKE_CASE      ,    padding="max_length"      ,    max_length=self.tokenizer.model_max_length      ,    return_tensors="pt"      ,    )
         snake_case__										= text_inputs.input_ids
         snake_case__										= text_inputs.attention_mask.bool().to(__SCREAMING_SNAKE_CASE   )

         if text_input_ids.shape[-1] > self.tokenizer.model_max_length:
          snake_case__										= self.tokenizer.batch_decode(text_input_ids[:, self.tokenizer.model_max_length :]   )
          logger.warning(
              "The following part of your input was truncated because CLIP can only handle sequences up to"
              F" {self.tokenizer.model_max_length} tokens: {removed_text}"   )
          snake_case__										= text_input_ids[:, : self.tokenizer.model_max_length]

         snake_case__										= self.text_encoder(text_input_ids.to(__SCREAMING_SNAKE_CASE   )   )

         snake_case__										= text_encoder_output.text_embeds
         snake_case__										= text_encoder_output.last_hidden_state

        else:
         snake_case__										= text_model_output[0].shape[0]
         snake_case__							,      snake_case__										= text_model_output[0], text_model_output[1]
         snake_case__										= text_attention_mask

        snake_case__										= text_embeddings.repeat_interleave(__SCREAMING_SNAKE_CASE      ,    dim=0   )
        snake_case__										= text_encoder_hidden_states.repeat_interleave(__SCREAMING_SNAKE_CASE      ,    dim=0   )
        snake_case__										= text_mask.repeat_interleave(__SCREAMING_SNAKE_CASE      ,    dim=0   )

        if do_classifier_free_guidance:
         snake_case__										= [""] * batch_size

         snake_case__										= self.tokenizer(
             __SCREAMING_SNAKE_CASE      ,    padding="max_length"      ,    max_length=self.tokenizer.model_max_length      ,    truncation=__SCREAMING_SNAKE_CASE      ,    return_tensors="pt"      ,    )
         snake_case__										= uncond_input.attention_mask.bool().to(__SCREAMING_SNAKE_CASE   )
         snake_case__										= self.text_encoder(uncond_input.input_ids.to(__SCREAMING_SNAKE_CASE   )   )

         snake_case__										= uncond_embeddings_text_encoder_output.text_embeds
         snake_case__										= uncond_embeddings_text_encoder_output.last_hidden_state

         # duplicate unconditional embeddings for each generation per prompt, using mps friendly method

         snake_case__										= uncond_embeddings.shape[1]
         snake_case__										= uncond_embeddings.repeat(1      ,    __SCREAMING_SNAKE_CASE   )
         snake_case__										= uncond_embeddings.view(batch_size * num_images_per_prompt      ,    __SCREAMING_SNAKE_CASE   )

         snake_case__										= uncond_text_encoder_hidden_states.shape[1]
         snake_case__										= uncond_text_encoder_hidden_states.repeat(1      ,    __SCREAMING_SNAKE_CASE      ,    1   )
         snake_case__										= uncond_text_encoder_hidden_states.view(
             batch_size * num_images_per_prompt      ,    __SCREAMING_SNAKE_CASE      ,    -1   )
         snake_case__										= uncond_text_mask.repeat_interleave(__SCREAMING_SNAKE_CASE      ,    dim=0   )

         # done duplicates

         # For classifier free guidance, we need to do two forward passes.
         # Here we concatenate the unconditional and text embeddings into a single batch
         # to avoid doing two forward passes
         snake_case__										= torch.cat([uncond_embeddings, text_embeddings]   )
         snake_case__										= torch.cat([uncond_text_encoder_hidden_states, text_encoder_hidden_states]   )

         snake_case__										= torch.cat([uncond_text_mask, text_mask]   )

        return text_embeddings, text_encoder_hidden_states, text_mask

       @property
       def 						_SCREAMING_SNAKE_CASE(	self   ):






        '''simple docstring'''

        if self.device != torch.device("meta"   ) or not hasattr(self.prior      ,    "_hf_hook"   ):
         return self.device
        for module in self.prior.modules():
         if (
             hasattr(__SCREAMING_SNAKE_CASE      ,    "_hf_hook"   )
             and hasattr(module._hf_hook      ,    "execution_device"   )
             and module._hf_hook.execution_device is not None
         ):
          return torch.device(module._hf_hook.execution_device   )
        return self.device

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   ):






        '''simple docstring'''

        if latents is None:
         snake_case__										= randn_tensor(__SCREAMING_SNAKE_CASE      ,    generator=__SCREAMING_SNAKE_CASE      ,    device=__SCREAMING_SNAKE_CASE      ,    dtype=__SCREAMING_SNAKE_CASE   )
        else:
         if latents.shape != shape:
          raise ValueError(F"Unexpected latents shape, got {latents.shape}, expected {shape}"   )
         snake_case__										= latents.to(__SCREAMING_SNAKE_CASE   )

        snake_case__										= latents * scheduler.init_noise_sigma
        return latents

       def 						_SCREAMING_SNAKE_CASE(	self      ,    __SCREAMING_SNAKE_CASE = None   ):






        '''simple docstring'''

        self.decoder_pipe.to(__SCREAMING_SNAKE_CASE   )
        super().to(__SCREAMING_SNAKE_CASE   )

       @torch.no_grad()
       def __call__(	self      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = 1      ,    __SCREAMING_SNAKE_CASE = 25      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = None      ,    __SCREAMING_SNAKE_CASE = 4.0      ,    __SCREAMING_SNAKE_CASE = 8.0      ,    __SCREAMING_SNAKE_CASE = 50      ,    __SCREAMING_SNAKE_CASE = 1      ,    __SCREAMING_SNAKE_CASE = 0.0      ,    __SCREAMING_SNAKE_CASE = "pil"      ,    __SCREAMING_SNAKE_CASE = True      ,    ):






        '''simple docstring'''

        if prompt is not None:
         if isinstance(__SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   ):
          snake_case__										= 1
         elif isinstance(__SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   ):
          snake_case__										= len(__SCREAMING_SNAKE_CASE   )
         else:
          raise ValueError(F"`prompt` has to be of type `str` or `list` but is {type(__SCREAMING_SNAKE_CASE   )}"   )
        else:
         snake_case__										= text_model_output[0].shape[0]

        snake_case__										= self._execution_device

        snake_case__										= batch_size * num_images_per_prompt

        snake_case__										= prior_guidance_scale > 1.0 or decoder_guidance_scale > 1.0

        snake_case__							,      snake_case__							,      snake_case__										= self._encode_prompt(
            __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE   )

        # prior

        self.prior_scheduler.set_timesteps(__SCREAMING_SNAKE_CASE      ,    device=__SCREAMING_SNAKE_CASE   )
        snake_case__										= self.prior_scheduler.timesteps

        snake_case__										= self.prior.config.embedding_dim

        snake_case__										= self.prepare_latents(
            (batch_size, embedding_dim)      ,    text_embeddings.dtype      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    __SCREAMING_SNAKE_CASE      ,    self.prior_scheduler      ,    )

        for i, t in enumerate(self.progress_bar(__SCREAMING_SNAKE_CASE   )   ):
         # expand the latents if we are doing classifier free guidance
         snake_case__										= torch.cat([prior_latents] * 2   ) if do_classifier_free_guidance else prior_latents

         snake_case__										= self.prior(
             __SCREAMING_SNAKE_CASE      ,    timestep=__SCREAMING_SNAKE_CASE      ,    proj_embedding=__SCREAMING_SNAKE_CASE      ,    encoder_hidden_states=__SCREAMING_SNAKE_CASE      ,    attention_mask=__SCREAMING_SNAKE_CASE      ,    ).predicted_image_embedding

         if do_classifier_free_guidance:
          snake_case__							,      snake_case__										= predicted_image_embedding.chunk(2   )
          snake_case__										= predicted_image_embedding_uncond + prior_guidance_scale * (
              predicted_image_embedding_text - predicted_image_embedding_uncond
          )

         if i + 1 == prior_timesteps_tensor.shape[0]:
          snake_case__										= None
         else:
          snake_case__										= prior_timesteps_tensor[i + 1]

         snake_case__										= self.prior_scheduler.step(
             __SCREAMING_SNAKE_CASE      ,    timestep=__SCREAMING_SNAKE_CASE      ,    sample=__SCREAMING_SNAKE_CASE      ,    generator=__SCREAMING_SNAKE_CASE      ,    prev_timestep=__SCREAMING_SNAKE_CASE      ,    ).prev_sample

        snake_case__										= self.prior.post_process_latents(__SCREAMING_SNAKE_CASE   )

        snake_case__										= prior_latents

        snake_case__										= self.decoder_pipe(
            image=__SCREAMING_SNAKE_CASE      ,    height=__SCREAMING_SNAKE_CASE      ,    width=__SCREAMING_SNAKE_CASE      ,    num_inference_steps=__SCREAMING_SNAKE_CASE      ,    guidance_scale=__SCREAMING_SNAKE_CASE      ,    generator=__SCREAMING_SNAKE_CASE      ,    output_type=__SCREAMING_SNAKE_CASE      ,    return_dict=__SCREAMING_SNAKE_CASE      ,    num_images_per_prompt=__SCREAMING_SNAKE_CASE      ,    eta=__SCREAMING_SNAKE_CASE      ,    )
        return output

