






'''simple docstring'''
import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      MegatronBertForCausalLM,
      MegatronBertForMaskedLM,
      MegatronBertForMultipleChoice,
      MegatronBertForNextSentencePrediction,
      MegatronBertForPreTraining,
      MegatronBertForQuestionAnswering,
      MegatronBertForSequenceClassification,
      MegatronBertForTokenClassification,
      MegatronBertModel,
  )






class      __SCREAMING_SNAKE_CASE      :




 def __init__(      self	:							str					,      __lowercase	:							str					,      __lowercase	:							Dict=13					,      __lowercase	:							Dict=7					,      __lowercase	:							Any=True					,      __lowercase	:							Any=True					,      __lowercase	:							Optional[int]=True					,      __lowercase	:							Any=True					,      __lowercase	:							Dict=99					,      __lowercase	:							int=64					,      __lowercase	:							Dict=32					,      __lowercase	:							int=5					,      __lowercase	:							Union[str, Any]=4					,      __lowercase	:							Optional[int]=37					,      __lowercase	:							List[Any]="gelu"					,      __lowercase	:							Any=0.1					,      __lowercase	:							Dict=0.1					,      __lowercase	:							Union[str, Any]=5_12					,      __lowercase	:							List[str]=16					,      __lowercase	:							str=2					,      __lowercase	:							Optional[int]=0.02					,      __lowercase	:							Optional[int]=3					,      __lowercase	:							Optional[int]=4					,      __lowercase	:							Dict=None					,      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=parent
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=batch_size
       SCREAMING_SNAKE_CASE__     :				str									=seq_length
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=is_training
       SCREAMING_SNAKE_CASE__     :				Tuple									=use_input_mask
       SCREAMING_SNAKE_CASE__     :				int									=use_token_type_ids
       SCREAMING_SNAKE_CASE__     :				List[Any]									=use_labels
       SCREAMING_SNAKE_CASE__     :				List[Any]									=vocab_size
       SCREAMING_SNAKE_CASE__     :				Any									=hidden_size
       SCREAMING_SNAKE_CASE__     :				Tuple									=embedding_size
       SCREAMING_SNAKE_CASE__     :				List[Any]									=num_hidden_layers
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=num_attention_heads
       SCREAMING_SNAKE_CASE__     :				List[str]									=intermediate_size
       SCREAMING_SNAKE_CASE__     :				List[str]									=hidden_act
       SCREAMING_SNAKE_CASE__     :				Dict									=hidden_dropout_prob
       SCREAMING_SNAKE_CASE__     :				List[Any]									=attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE__     :				Tuple									=max_position_embeddings
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=type_vocab_size
       SCREAMING_SNAKE_CASE__     :				List[str]									=type_sequence_label_size
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=initializer_range
       SCREAMING_SNAKE_CASE__     :				Any									=num_labels
       SCREAMING_SNAKE_CASE__     :				Any									=num_choices
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=scope




 def      __magic_name__	(      self	:							Any      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				List[str]									=ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size      )

       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=None
       if self.use_input_mask:
             SCREAMING_SNAKE_CASE__     :				Optional[Any]									=random_attention_mask([self.batch_size, self.seq_length]      )

       SCREAMING_SNAKE_CASE__     :				Dict									=None
       if self.use_token_type_ids:
             SCREAMING_SNAKE_CASE__     :				Optional[int]									=ids_tensor([self.batch_size, self.seq_length]					,      self.type_vocab_size      )

       SCREAMING_SNAKE_CASE__     :				Dict									=None
       SCREAMING_SNAKE_CASE__     :				Tuple									=None
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=None
       if self.use_labels:
             SCREAMING_SNAKE_CASE__     :				str									=ids_tensor([self.batch_size]					,      self.type_sequence_label_size      )
             SCREAMING_SNAKE_CASE__     :				str									=ids_tensor([self.batch_size, self.seq_length]					,      self.num_labels      )
             SCREAMING_SNAKE_CASE__     :				int									=ids_tensor([self.batch_size]					,      self.num_choices      )

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.get_config()

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




 def      __magic_name__	(      self	:							str      )	->						str:
       return MegatronBertConfig(
           vocab_size=self.vocab_size					,      hidden_size=self.hidden_size					,      num_hidden_layers=self.num_hidden_layers					,      num_attention_heads=self.num_attention_heads					,      intermediate_size=self.intermediate_size					,      embedding_size=self.embedding_size					,      hidden_act=self.hidden_act					,      hidden_dropout_prob=self.hidden_dropout_prob					,      attention_probs_dropout_prob=self.attention_probs_dropout_prob					,      max_position_embeddings=self.max_position_embeddings					,      type_vocab_size=self.type_vocab_size					,      is_decoder=__snake_case					,      initializer_range=self.initializer_range					,      )




 def      __magic_name__	(      self	:							int					,      __lowercase	:							List[str]					,      __lowercase	:							int					,      __lowercase	:							Tuple					,      __lowercase	:							int					,      __lowercase	:							Optional[int]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Optional[int]      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Dict									=MegatronBertModel(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				Tuple									=model(__snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case      )
       SCREAMING_SNAKE_CASE__     :				str									=model(__snake_case					,      token_type_ids=__snake_case      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=model(__snake_case      )

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




 def      __magic_name__	(      self	:							int					,      __lowercase	:							Optional[int]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							str					,      __lowercase	:							Any					,      __lowercase	:							int					,      __lowercase	:							Dict					,      __lowercase	:							Union[str, Any]      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Dict									=MegatronBertForMaskedLM(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				List[Any]									=model(__snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.seq_length, self.vocab_size)      )




 def      __magic_name__	(      self	:							Tuple					,      __lowercase	:							int					,      __lowercase	:							str					,      __lowercase	:							Any					,      __lowercase	:							List[str]					,      __lowercase	:							str					,      __lowercase	:							Any					,      __lowercase	:							List[Any]      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Any									=MegatronBertForCausalLM(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				str									=model(__snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.seq_length, self.vocab_size)      )




 def      __magic_name__	(      self	:							str					,      __lowercase	:							Optional[int]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Optional[int]					,      __lowercase	:							str					,      __lowercase	:							Optional[int]					,      __lowercase	:							List[str]					,      __lowercase	:							str      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				Dict									=MegatronBertForNextSentencePrediction(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				int									=model(
           __snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case					,      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, 2)      )




 def      __magic_name__	(      self	:							List[str]					,      __lowercase	:							str					,      __lowercase	:							int					,      __lowercase	:							Tuple					,      __lowercase	:							Dict					,      __lowercase	:							List[str]					,      __lowercase	:							Optional[int]					,      __lowercase	:							Optional[int]      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Dict									=MegatronBertForPreTraining(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=model(
           __snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case					,      next_sentence_label=__snake_case					,      )
       self.parent.assertEqual(result.prediction_logits.shape					,      (self.batch_size, self.seq_length, self.vocab_size)      )
       self.parent.assertEqual(result.seq_relationship_logits.shape					,      (self.batch_size, 2)      )




 def      __magic_name__	(      self	:							Optional[int]					,      __lowercase	:							List[str]					,      __lowercase	:							List[str]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Tuple					,      __lowercase	:							List[Any]					,      __lowercase	:							Optional[int]      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				Dict									=MegatronBertForQuestionAnswering(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				Tuple									=model(
           __snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      start_positions=__snake_case					,      end_positions=__snake_case					,      )
       self.parent.assertEqual(result.start_logits.shape					,      (self.batch_size, self.seq_length)      )
       self.parent.assertEqual(result.end_logits.shape					,      (self.batch_size, self.seq_length)      )




 def      __magic_name__	(      self	:							Dict					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							str					,      __lowercase	:							Any					,      __lowercase	:							int					,      __lowercase	:							int					,      __lowercase	:							Tuple					,      __lowercase	:							Tuple      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				int									=self.num_labels
       SCREAMING_SNAKE_CASE__     :				List[str]									=MegatronBertForSequenceClassification(__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				List[str]									=model(__snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_labels)      )




 def      __magic_name__	(      self	:							List[str]					,      __lowercase	:							Optional[int]					,      __lowercase	:							str					,      __lowercase	:							int					,      __lowercase	:							Dict					,      __lowercase	:							Tuple					,      __lowercase	:							List[Any]					,      __lowercase	:							Dict      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.num_labels
       SCREAMING_SNAKE_CASE__     :				int									=MegatronBertForTokenClassification(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				Any									=model(__snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.seq_length, self.num_labels)      )




 def      __magic_name__	(      self	:							Optional[Any]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							List[str]					,      __lowercase	:							Dict					,      __lowercase	:							Union[str, Any]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Tuple					,      __lowercase	:							Union[str, Any]      )	->						Dict:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.num_choices
       SCREAMING_SNAKE_CASE__     :				Tuple									=MegatronBertForMultipleChoice(config=__snake_case      )
       model.to(__snake_case      )
       model.eval()
       SCREAMING_SNAKE_CASE__     :				List[Any]									=input_ids.unsqueeze(1      ).expand(-1					,      self.num_choices					,      -1      ).contiguous()
       SCREAMING_SNAKE_CASE__     :				List[Any]									=token_type_ids.unsqueeze(1      ).expand(-1					,      self.num_choices					,      -1      ).contiguous()
       SCREAMING_SNAKE_CASE__     :				List[str]									=input_mask.unsqueeze(1      ).expand(-1					,      self.num_choices					,      -1      ).contiguous()
       SCREAMING_SNAKE_CASE__     :				Dict									=model(
           __snake_case					,      attention_mask=__snake_case					,      token_type_ids=__snake_case					,      labels=__snake_case					,      )
       self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_choices)      )




 def      __magic_name__	(      self	:							Dict      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				List[str]									=self.prepare_config_and_inputs()
       (
           SCREAMING_SNAKE_CASE__    
       )     :				Optional[Any]									=config_and_inputs
       SCREAMING_SNAKE_CASE__     :				List[Any]									={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_torch
class      __SCREAMING_SNAKE_CASE      (			__SCREAMING_SNAKE_CASE	,				__SCREAMING_SNAKE_CASE	,				unittest.TestCase				):
 snake_case_  							=							(
     (
         MegatronBertModel,
         MegatronBertForMaskedLM,
         MegatronBertForCausalLM,
         MegatronBertForMultipleChoice,
         MegatronBertForNextSentencePrediction,
         MegatronBertForPreTraining,
         MegatronBertForQuestionAnswering,
         MegatronBertForSequenceClassification,
         MegatronBertForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 snake_case_  							=							(
     {
         """feature-extraction""": MegatronBertModel,
         """fill-mask""": MegatronBertForMaskedLM,
         """question-answering""": MegatronBertForQuestionAnswering,
         """text-classification""": MegatronBertForSequenceClassification,
         """text-generation""": MegatronBertForCausalLM,
         """token-classification""": MegatronBertForTokenClassification,
         """zero-shot""": MegatronBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 snake_case_  							=							True
 # test_resize_embeddings = False
 snake_case_  							=							False




 def      __magic_name__	(      self	:							Any					,      __lowercase	:							Optional[Any]					,      __lowercase	:							str					,      __lowercase	:							List[Any]=False      )	->						Any:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=super()._prepare_for_class(__snake_case					,      __snake_case					,      return_labels=__snake_case      )

       if return_labels:
             if model_class in get_values(__snake_case      ):
                   SCREAMING_SNAKE_CASE__     :				int									=torch.zeros(
                       (self.model_tester.batch_size, self.model_tester.seq_length)					,      dtype=torch.long					,      device=__snake_case      )
                   SCREAMING_SNAKE_CASE__     :				str									=torch.zeros(
                       self.model_tester.batch_size					,      dtype=torch.long					,      device=__snake_case      )
       return inputs_dict




 def      __magic_name__	(      self	:							Optional[Any]      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				List[Any]									=MegatronBertModelTester(self      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=ConfigTester(self					,      config_class=__snake_case					,      hidden_size=37      )




 def      __magic_name__	(      self	:							Dict      )	->						str:
       self.config_tester.run_common_tests()




 def      __magic_name__	(      self	:							Any      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				int									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_model(*__snake_case      )




 def      __magic_name__	(      self	:							List[str]      )	->						str:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_masked_lm(*__snake_case      )




 def      __magic_name__	(      self	:							Any      )	->						str:
       SCREAMING_SNAKE_CASE__     :				Dict									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*__snake_case      )




 def      __magic_name__	(      self	:							int      )	->						List[str]:
       SCREAMING_SNAKE_CASE__     :				List[Any]									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*__snake_case      )




 def      __magic_name__	(      self	:							List[Any]      )	->						str:
       SCREAMING_SNAKE_CASE__     :				Tuple									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_pretraining(*__snake_case      )




 def      __magic_name__	(      self	:							Union[str, Any]      )	->						List[Any]:
       SCREAMING_SNAKE_CASE__     :				Dict									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_question_answering(*__snake_case      )




 def      __magic_name__	(      self	:							int      )	->						Optional[Any]:
       SCREAMING_SNAKE_CASE__     :				Dict									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*__snake_case      )




 def      __magic_name__	(      self	:							Optional[int]      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				List[Any]									=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_megatron_bert_for_token_classification(*__snake_case      )





def  _a(  UpperCamelCase__				:						Optional[Any]							):




      '''simple docstring'''






      return torch.tensor(
          a_,	dtype=torch.long,	device=a_,	)


lowerCAmelCase_					= 1E-4







@require_torch
@require_sentencepiece
@require_tokenizers
class      __SCREAMING_SNAKE_CASE      (			unittest.TestCase				):




 @slow
 @unittest.skip('''Model is not available.'''      )
 def      __magic_name__	(      self	:							Union[str, Any]      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									='''nvidia/megatron-bert-uncased-345m'''
       if "MYDIR" in os.environ:
             SCREAMING_SNAKE_CASE__     :				Any									=os.path.join(os.environ['''MYDIR''']					,      __snake_case      )
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=MegatronBertModel.from_pretrained(__snake_case      )
       model.to(__snake_case      )
       model.half()
       SCREAMING_SNAKE_CASE__     :				List[str]									=_long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]      )
       with torch.no_grad():
             SCREAMING_SNAKE_CASE__     :				Any									=model(__snake_case      )[0]
       SCREAMING_SNAKE_CASE__     :				Tuple									=torch.Size((1, 9, 10_24)      )
       self.assertEqual(output.shape					,      __snake_case      )

       SCREAMING_SNAKE_CASE__     :				str									=[-0.6040, -0.2517, -0.1025, 0.3420, -0.6758, -0.0017, -0.1089, -0.1990, 0.5728]
       for ii in range(3      ):
             for jj in range(3      ):
                   SCREAMING_SNAKE_CASE__     :				int									=output[0, ii, jj]
                   SCREAMING_SNAKE_CASE__     :				str									=expected[3 * ii + jj]
                   SCREAMING_SNAKE_CASE__     :				Union[str, Any]									='''ii={} jj={} a={} b={}'''.format(__snake_case					,      __snake_case					,      __snake_case					,      __snake_case      )
                   self.assertTrue(math.isclose(__snake_case					,      __snake_case					,      rel_tol=__snake_case					,      abs_tol=__snake_case      )					,      msg=__snake_case      )







'''simple docstring'''
import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image

from diffusers import (
    DDIMScheduler,
    KandinskyVaaImgaImgPipeline,
    KandinskyVaaPriorPipeline,
    UNetaDConditionModel,
    VQModel,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase	,				unittest.TestCase				):
 snake_case_  							=							KandinskyVaaImgaImgPipeline
 snake_case_  							=							["""image_embeds""", """negative_image_embeds""", """image"""]
 snake_case_  							=							[
     """image_embeds""",
     """negative_image_embeds""",
     """image""",
 ]
 snake_case_  							=							[
     """generator""",
     """height""",
     """width""",
     """strength""",
     """guidance_scale""",
     """num_inference_steps""",
     """return_dict""",
     """guidance_scale""",
     """num_images_per_prompt""",
     """output_type""",
     """return_dict""",
 ]
 snake_case_  							=							False




 @property
 def      __magic_name__	(      self	:							List[str]      )	->						Tuple:
       return 32




 @property
 def      __magic_name__	(      self	:							List[str]      )	->						str:
       return 32




 @property
 def      __magic_name__	(      self	:							Any      )	->						Optional[int]:
       return self.time_input_dim




 @property
 def      __magic_name__	(      self	:							List[Any]      )	->						int:
       return self.time_input_dim * 4




 @property
 def      __magic_name__	(      self	:							Tuple      )	->						Optional[int]:
       return 1_00




 @property
 def      __magic_name__	(      self	:							Union[str, Any]      )	->						Tuple:
       torch.manual_seed(0      )

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									={
           '''in_channels''': 4,
           # Out channels is double in channels because predicts mean and variance
           '''out_channels''': 8,
           '''addition_embed_type''': '''image''',
           '''down_block_types''': ('''ResnetDownsampleBlock2D''', '''SimpleCrossAttnDownBlock2D'''),
           '''up_block_types''': ('''SimpleCrossAttnUpBlock2D''', '''ResnetUpsampleBlock2D'''),
           '''mid_block_type''': '''UNetMidBlock2DSimpleCrossAttn''',
           '''block_out_channels''': (self.block_out_channels_a, self.block_out_channels_a * 2),
           '''layers_per_block''': 1,
           '''encoder_hid_dim''': self.text_embedder_hidden_size,
           '''encoder_hid_dim_type''': '''image_proj''',
           '''cross_attention_dim''': self.cross_attention_dim,
           '''attention_head_dim''': 4,
           '''resnet_time_scale_shift''': '''scale_shift''',
           '''class_embed_type''': None,
       }

       SCREAMING_SNAKE_CASE__     :				Optional[int]									=UNetaDConditionModel(**__lowercase      )
       return model




 @property
 def      __magic_name__	(      self	:							Dict      )	->						Any:
       return {
           "block_out_channels": [32, 64],
           "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
           "in_channels": 3,
           "latent_channels": 4,
           "layers_per_block": 1,
           "norm_num_groups": 8,
           "norm_type": "spatial",
           "num_vq_embeddings": 12,
           "out_channels": 3,
           "up_block_types": [
               "AttnUpDecoderBlock2D",
               "UpDecoderBlock2D",
           ],
           "vq_embed_dim": 4,
       }




 @property
 def      __magic_name__	(      self	:							Tuple      )	->						Optional[Any]:
       torch.manual_seed(0      )
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=VQModel(**self.dummy_movq_kwargs      )
       return model




 def      __magic_name__	(      self	:							str      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				List[str]									=self.dummy_unet
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=self.dummy_movq

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									={
           '''num_train_timesteps''': 10_00,
           '''beta_schedule''': '''linear''',
           '''beta_start''': 0.00085,
           '''beta_end''': 0.012,
           '''clip_sample''': False,
           '''set_alpha_to_one''': False,
           '''steps_offset''': 0,
           '''prediction_type''': '''epsilon''',
           '''thresholding''': False,
       }

       SCREAMING_SNAKE_CASE__     :				str									=DDIMScheduler(**__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Any									={
           '''unet''': unet,
           '''scheduler''': scheduler,
           '''movq''': movq,
       }

       return components




 def      __magic_name__	(      self	:							str					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Any=0      )	->						int:
       SCREAMING_SNAKE_CASE__     :				Optional[int]									=floats_tensor((1, self.text_embedder_hidden_size)					,      rng=random.Random(__lowercase      )      ).to(__lowercase      )
       SCREAMING_SNAKE_CASE__     :				Any									=floats_tensor((1, self.text_embedder_hidden_size)					,      rng=random.Random(seed + 1      )      ).to(
           __lowercase      )
       # create init_image
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=floats_tensor((1, 3, 64, 64)					,      rng=random.Random(__lowercase      )      ).to(__lowercase      )
       SCREAMING_SNAKE_CASE__     :				Dict									=image.cpu().permute(0					,      2					,      3					,      1      )[0]
       SCREAMING_SNAKE_CASE__     :				Any									=Image.fromarray(np.uinta(__lowercase      )      ).convert('''RGB'''      ).resize((2_56, 2_56)      )

       if str(__lowercase      ).startswith('''mps'''      ):
             SCREAMING_SNAKE_CASE__     :				Dict									=torch.manual_seed(__lowercase      )
       else:
             SCREAMING_SNAKE_CASE__     :				Tuple									=torch.Generator(device=__lowercase      ).manual_seed(__lowercase      )
       SCREAMING_SNAKE_CASE__     :				str									={
           '''image''': init_image,
           '''image_embeds''': image_embeds,
           '''negative_image_embeds''': negative_image_embeds,
           '''generator''': generator,
           '''height''': 64,
           '''width''': 64,
           '''num_inference_steps''': 10,
           '''guidance_scale''': 7.0,
           '''strength''': 0.2,
           '''output_type''': '''np''',
       }
       return inputs




 def      __magic_name__	(      self	:							int      )	->						Union[str, Any]:
       SCREAMING_SNAKE_CASE__     :				List[Any]									='''cpu'''

       SCREAMING_SNAKE_CASE__     :				Tuple									=self.get_dummy_components()

       SCREAMING_SNAKE_CASE__     :				Dict									=self.pipeline_class(**__lowercase      )
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=pipe.to(__lowercase      )

       pipe.set_progress_bar_config(disable=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Dict									=pipe(**self.get_dummy_inputs(__lowercase      )      )
       SCREAMING_SNAKE_CASE__     :				Tuple									=output.images

       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=pipe(
           **self.get_dummy_inputs(__lowercase      )					,      return_dict=__lowercase					,      )[0]

       SCREAMING_SNAKE_CASE__     :				List[Any]									=image[0, -3:, -3:, -1]
       SCREAMING_SNAKE_CASE__     :				List[str]									=image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 64, 64, 3)

       SCREAMING_SNAKE_CASE__     :				Tuple									=np.array(
           [0.6199778, 0.63984406, 0.46145785, 0.62944984, 0.5622215, 0.47306132, 0.47441456, 0.4607606, 0.48719263]      )
       assert (
           np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-2
       ), F" expected_slice {expected_slice}, but got {image_slice.flatten()}"
       assert (
           np.abs(image_from_tuple_slice.flatten() - expected_slice      ).max() < 1e-2
       ), F" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"






@slow
@require_torch_gpu
class      __SCREAMING_SNAKE_CASE      (			unittest.TestCase				):




 def      __magic_name__	(      self	:							int      )	->						Any:
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()




 def      __magic_name__	(      self	:							Union[str, Any]      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				str									=load_numpy(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
           '''/kandinskyv22/kandinskyv22_img2img_frog.npy'''      )

       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main''' '''/kandinsky/cat.png'''      )
       SCREAMING_SNAKE_CASE__     :				List[Any]									='''A red cartoon frog, 4k'''

       SCREAMING_SNAKE_CASE__     :				Optional[int]									=KandinskyVaaPriorPipeline.from_pretrained(
           '''kandinsky-community/kandinsky-2-2-prior'''					,      torch_dtype=torch.floataa      )
       pipe_prior.to(__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Any									=KandinskyVaaImgaImgPipeline.from_pretrained(
           '''kandinsky-community/kandinsky-2-2-decoder'''					,      torch_dtype=torch.floataa      )
       SCREAMING_SNAKE_CASE__     :				Dict									=pipeline.to(__lowercase      )

       pipeline.set_progress_bar_config(disable=__lowercase      )

       SCREAMING_SNAKE_CASE__     :				Tuple									=torch.Generator(device='''cpu'''      ).manual_seed(0      )
       SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				List[str]									=pipe_prior(
           __lowercase					,      generator=__lowercase					,      num_inference_steps=5					,      negative_prompt=''''''					,      ).to_tuple()

       SCREAMING_SNAKE_CASE__     :				List[Any]									=pipeline(
           image=__lowercase					,      image_embeds=__lowercase					,      negative_image_embeds=__lowercase					,      generator=__lowercase					,      num_inference_steps=1_00					,      height=7_68					,      width=7_68					,      strength=0.2					,      output_type='''np'''					,      )

       SCREAMING_SNAKE_CASE__     :				int									=output.images[0]

       assert image.shape == (7_68, 7_68, 3)

       assert_mean_pixel_difference(__lowercase					,      __lowercase      )