

from __future__ import annotations

import unittest

import numpy as np

from transformers import LayoutLMConfig, 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.layoutlm.modeling_tf_layoutlm import (
	    TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFLayoutLMForMaskedLM,
	    TFLayoutLMForQuestionAnswering,
	    TFLayoutLMForSequenceClassification,
	    TFLayoutLMForTokenClassification,
	    TFLayoutLMModel,
	)



class    _a						:


					'''simple docstring'''






					def __init__(			self   ,	A__   ,	A__=13   ,	A__=7   ,	A__=True   ,	A__=True   ,	A__=True   ,	A__=True   ,	A__=99   ,	A__=32   ,	A__=2   ,	A__=4   ,	A__=37   ,	A__="gelu"   ,	A__=0.1   ,	A__=0.1   ,	A__=512   ,	A__=16   ,	A__=2   ,	A__=0.0_2   ,	A__=3   ,	A__=4   ,	A__=None   ,	A__=1000   ,	):
						A__							:   Optional[int]					       =		parent
						A__							:   List[Any]					       =		batch_size
						A__							:   Dict					       =		seq_length
						A__							:   Any					       =		is_training
						A__							:   List[str]					       =		use_input_mask
						A__							:   Optional[Any]					       =		use_token_type_ids
						A__							:   Optional[Any]					       =		use_labels
						A__							:   Optional[Any]					       =		vocab_size
						A__							:   str					       =		hidden_size
						A__							:   List[Any]					       =		num_hidden_layers
						A__							:   int					       =		num_attention_heads
						A__							:   Optional[Any]					       =		intermediate_size
						A__							:   Any					       =		hidden_act
						A__							:   Any					       =		hidden_dropout_prob
						A__							:   str					       =		attention_probs_dropout_prob
						A__							:   Any					       =		max_position_embeddings
						A__							:   Dict					       =		type_vocab_size
						A__							:   Dict					       =		type_sequence_label_size
						A__							:   Optional[int]					       =		initializer_range
						A__							:   List[str]					       =		num_labels
						A__							:   Dict					       =		num_choices
						A__							:   Union[str, Any]					       =		scope
						A__							:   Any					       =		range_bbox






					def   __A      (			self      ):
						A__							:   Tuple					       =		ids_tensor([self.batch_size, self.seq_length]   ,	self.vocab_size      )

						# convert bbox to numpy since TF does not support item assignment
						A__							:   Dict					       =		ids_tensor([self.batch_size, self.seq_length, 4]   ,	self.range_bbox      ).numpy()
						# Ensure that bbox is legal
						for i in range(bbox.shape[0]      ):
							for j in range(bbox.shape[1]      ):
								if bbox[i, j, 3] < bbox[i, j, 1]:
									A__							:   Optional[int]					       =		bbox[i, j, 3]
									A__							:   Tuple					       =		bbox[i, j, 1]
									A__							:   List[str]					       =		t
								if bbox[i, j, 2] < bbox[i, j, 0]:
									A__							:   str					       =		bbox[i, j, 2]
									A__							:   Optional[int]					       =		bbox[i, j, 0]
									A__							:   str					       =		t
						A__							:   int					       =		tf.convert_to_tensor(A__      )

						A__							:   str					       =		None
						if self.use_input_mask:
							A__							:   Dict					       =		random_attention_mask([self.batch_size, self.seq_length]      )

						A__							:   int					       =		None
						if self.use_token_type_ids:
							A__							:   Union[str, Any]					       =		ids_tensor([self.batch_size, self.seq_length]   ,	self.type_vocab_size      )

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

						A__							:   Union[str, Any]					       =		LayoutLMConfig(
						    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   ,	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   ,	initializer_range=self.initializer_range   ,	)

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






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   Any					       =		TFLayoutLMModel(config=A__      )

						A__							:   Optional[Any]					       =		model(A__   ,	A__   ,	attention_mask=A__   ,	token_type_ids=A__      )
						A__							:   Union[str, Any]					       =		model(A__   ,	A__   ,	token_type_ids=A__      )
						A__							:   Dict					       =		model(A__   ,	A__      )
						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   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   Optional[Any]					       =		TFLayoutLMForMaskedLM(config=A__      )

						A__							:   str					       =		model(A__   ,	A__   ,	attention_mask=A__   ,	token_type_ids=A__   ,	labels=A__      )
						self.parent.assertEqual(result.logits.shape   ,	(self.batch_size, self.seq_length, self.vocab_size)      )






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   Optional[int]					       =		self.num_labels
						A__							:   Optional[Any]					       =		TFLayoutLMForSequenceClassification(config=A__      )

						A__							:   Optional[int]					       =		model(A__   ,	A__   ,	attention_mask=A__   ,	token_type_ids=A__      )
						self.parent.assertEqual(result.logits.shape   ,	(self.batch_size, self.num_labels)      )






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   Optional[int]					       =		self.num_labels
						A__							:   List[str]					       =		TFLayoutLMForTokenClassification(config=A__      )

						A__							:   Tuple					       =		model(A__   ,	A__   ,	attention_mask=A__   ,	token_type_ids=A__   ,	labels=A__      )
						self.parent.assertEqual(result.logits.shape   ,	(self.batch_size, self.seq_length, self.num_labels)      )






					def   __A      (			self   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__   ,	A__      ):
						A__							:   Optional[Any]					       =		TFLayoutLMForQuestionAnswering(config=A__      )

						A__							:   List[str]					       =		model(A__   ,	A__   ,	attention_mask=A__   ,	token_type_ids=A__      )
						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   __A      (			self      ):
						A__							:   List[str]					       =		self.prepare_config_and_inputs()
						(
						    (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       (
						    A__
						)       ,       
						)							:   Any					       =		config_and_inputs
						A__							:   Any					       =		{
						    """input_ids""": input_ids,
						    """bbox""": bbox,
						    """token_type_ids""": token_type_ids,
						    """attention_mask""": input_mask,
						}
						return config, inputs_dict



@require_tf
class    _a						(__magic_name__		,       __magic_name__		,       unittest.TestCase    ):


					'''simple docstring'''






					UpperCAmelCase__:       Any  							=	(
					    (
					        TFLayoutLMModel,
					        TFLayoutLMForMaskedLM,
					        TFLayoutLMForTokenClassification,
					        TFLayoutLMForSequenceClassification,
					        TFLayoutLMForQuestionAnswering,
					    )
					    if is_tf_available()
					    else ()
					)
					UpperCAmelCase__:       Optional[int]  							=	(
					    {
					        '''feature-extraction''': TFLayoutLMModel,
					        '''fill-mask''': TFLayoutLMForMaskedLM,
					        '''text-classification''': TFLayoutLMForSequenceClassification,
					        '''token-classification''': TFLayoutLMForTokenClassification,
					        '''zero-shot''': TFLayoutLMForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					UpperCAmelCase__:       Optional[Any]  							=	False
					UpperCAmelCase__:       Optional[Any]  							=	True
					UpperCAmelCase__:       Any  							=	10






					def   __A      (			self      ):
						A__							:   List[Any]					       =		TFLayoutLMModelTester(self      )
						A__							:   Union[str, Any]					       =		ConfigTester(self   ,	config_class=A__   ,	hidden_size=37      )






					def   __A      (			self      ):
						self.config_tester.run_common_tests()






					def   __A      (			self      ):
						A__							:   Union[str, Any]					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A__      )






					def   __A      (			self      ):
						A__							:   List[Any]					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*A__      )






					def   __A      (			self      ):
						A__							:   int					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*A__      )






					def   __A      (			self      ):
						A__							:   List[str]					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*A__      )






					def   __A      (			self      ):
						A__							:   str					       =		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*A__      )






					@slow
					def   __A      (			self      ):
						for model_name in TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__							:   Optional[int]					       =		TFLayoutLMModel.from_pretrained(A__      )
							self.assertIsNotNone(A__      )






					@unittest.skip("""Onnx compliancy broke with TF 2.10"""      )
					def   __A      (			self      ):
						pass



def 						UpperCamelCase ()					->				Optional[int]:
	# Here we prepare a batch of 2 sequences to test a LayoutLM forward pass on:
	# fmt: off
	A__							:   List[str]					       =		tf.convert_to_tensor([[101,1019,1014,1016,1037,12849,4747,1004,14246,2278,5439,4524,5002,2930,2193,2930,4341,3208,1005,1055,2171,2848,11300,3531,102],[101,4070,4034,7020,1024,3058,1015,1013,2861,1013,6070,19274,2772,6205,27814,16147,16147,4343,2047,10283,10969,14389,1012,2338,102]] )  # noqa: E231
	A__							:   Tuple					       =		tf.convert_to_tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],] )  # noqa: E231
	A__							:   Any					       =		tf.convert_to_tensor([[[0,0,0,0],[423,237,440,251],[427,272,441,287],[419,115,437,129],[961,885,992,912],[256,38,330,58],[256,38,330,58],[336,42,353,57],[360,39,401,56],[360,39,401,56],[411,39,471,59],[479,41,528,59],[533,39,630,60],[67,113,134,131],[141,115,209,132],[68,149,133,166],[141,149,187,164],[195,148,287,165],[195,148,287,165],[195,148,287,165],[295,148,349,165],[441,149,492,166],[497,149,546,164],[64,201,125,218],[1000,1000,1000,1000]],[[0,0,0,0],[662,150,754,166],[665,199,742,211],[519,213,554,228],[519,213,554,228],[134,433,187,454],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[314,469,376,482],[504,684,582,706],[941,825,973,900],[941,825,973,900],[941,825,973,900],[941,825,973,900],[610,749,652,765],[130,659,168,672],[176,657,237,672],[238,657,312,672],[443,653,628,672],[443,653,628,672],[716,301,825,317],[1000,1000,1000,1000]]] )  # noqa: E231
	A__							:   Union[str, Any]					       =		tf.convert_to_tensor([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] )  # noqa: E231
	# these are sequence labels (i.e. at the token level)
	A__							:   Dict					       =		tf.convert_to_tensor([[-100,10,10,10,9,1,-100,7,7,-100,7,7,4,2,5,2,8,8,-100,-100,5,0,3,2,-100],[-100,12,12,12,-100,12,10,-100,-100,-100,-100,10,12,9,-100,-100,-100,10,10,10,9,12,-100,10,-100]] )  # noqa: E231
	# fmt: on

	return input_ids, attention_mask, bbox, token_type_ids, labels



@require_tf
class    _a						(unittest.TestCase    ):


					'''simple docstring'''






					@slow
					def   __A      (			self      ):
						A__							:   Dict					       =		TFLayoutLMModel.from_pretrained("""microsoft/layoutlm-base-uncased"""      )

						A__       ,       A__       ,       A__       ,       A__       ,       A__							:   Union[str, Any]					       =		prepare_layoutlm_batch_inputs()

						# forward pass
						A__							:   Optional[int]					       =		model(input_ids=A__   ,	bbox=A__   ,	attention_mask=A__   ,	token_type_ids=A__      )

						# test the sequence output on [0, :3, :3]
						A__							:   Any					       =		tf.convert_to_tensor(
						    [[0.1_7_8_5, -0.1_9_4_7, -0.0_4_2_5], [-0.3_2_5_4, -0.2_8_0_7, 0.2_5_5_3], [-0.5_3_9_1, -0.3_3_2_2, 0.3_3_6_4]]   ,	)

						self.assertTrue(np.allclose(outputs.last_hidden_state[0, :3, :3]   ,	A__   ,	atol=1e-3      )      )

						# test the pooled output on [1, :3]
						A__							:   Tuple					       =		tf.convert_to_tensor([-0.6_5_8_0, -0.0_2_1_4, 0.8_5_5_2]      )

						self.assertTrue(np.allclose(outputs.pooler_output[1, :3]   ,	A__   ,	atol=1e-3      )      )






					@slow
					def   __A      (			self      ):
						# initialize model with randomly initialized sequence classification head
						A__							:   List[Any]					       =		TFLayoutLMForSequenceClassification.from_pretrained("""microsoft/layoutlm-base-uncased"""   ,	num_labels=2      )

						A__       ,       A__       ,       A__       ,       A__       ,       A__							:   Tuple					       =		prepare_layoutlm_batch_inputs()

						# forward pass
						A__							:   Optional[int]					       =		model(
						    input_ids=A__   ,	bbox=A__   ,	attention_mask=A__   ,	token_type_ids=A__   ,	labels=tf.convert_to_tensor([1, 1]      )   ,	)

						# test whether we get a loss as a scalar
						A__							:   int					       =		outputs.loss
						A__							:   Optional[Any]					       =		(2,)
						self.assertEqual(loss.shape   ,	A__      )

						# test the shape of the logits
						A__							:   str					       =		outputs.logits
						A__							:   Optional[int]					       =		(2, 2)
						self.assertEqual(logits.shape   ,	A__      )






					@slow
					def   __A      (			self      ):
						# initialize model with randomly initialized token classification head
						A__							:   List[Any]					       =		TFLayoutLMForTokenClassification.from_pretrained("""microsoft/layoutlm-base-uncased"""   ,	num_labels=13      )

						A__       ,       A__       ,       A__       ,       A__       ,       A__							:   List[Any]					       =		prepare_layoutlm_batch_inputs()

						# forward pass
						A__							:   Tuple					       =		model(
						    input_ids=A__   ,	bbox=A__   ,	attention_mask=A__   ,	token_type_ids=A__   ,	labels=A__      )

						# test the shape of the logits
						A__							:   Union[str, Any]					       =		outputs.logits
						A__							:   Union[str, Any]					       =		tf.convert_to_tensor((2, 25, 13)      )
						self.assertEqual(logits.shape   ,	A__      )






					@slow
					def   __A      (			self      ):
						# initialize model with randomly initialized token classification head
						A__							:   Optional[Any]					       =		TFLayoutLMForQuestionAnswering.from_pretrained("""microsoft/layoutlm-base-uncased"""      )

						A__       ,       A__       ,       A__       ,       A__       ,       A__							:   Union[str, Any]					       =		prepare_layoutlm_batch_inputs()

						# forward pass
						A__							:   List[Any]					       =		model(input_ids=A__   ,	bbox=A__   ,	attention_mask=A__   ,	token_type_ids=A__      )

						# test the shape of the logits
						A__							:   List[str]					       =		tf.convert_to_tensor((2, 25)      )
						self.assertEqual(outputs.start_logits.shape   ,	A__      )
						self.assertEqual(outputs.end_logits.shape   ,	A__      )






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    _a						(__magic_name__		,       unittest.TestCase    ):


					'''simple docstring'''






					UpperCAmelCase__:       Any  							=	KandinskyVaaImgaImgPipeline
					UpperCAmelCase__:       Optional[Any]  							=	['''image_embeds''', '''negative_image_embeds''', '''image''']
					UpperCAmelCase__:       str  							=	[
					    '''image_embeds''',
					    '''negative_image_embeds''',
					    '''image''',
					]
					UpperCAmelCase__:       int  							=	[
					    '''generator''',
					    '''height''',
					    '''width''',
					    '''strength''',
					    '''guidance_scale''',
					    '''num_inference_steps''',
					    '''return_dict''',
					    '''guidance_scale''',
					    '''num_images_per_prompt''',
					    '''output_type''',
					    '''return_dict''',
					]
					UpperCAmelCase__:       Union[str, Any]  							=	False






					@property
					def   __A      (			self      ):
						return 32






					@property
					def   __A      (			self      ):
						return 32






					@property
					def   __A      (			self      ):
						return self.time_input_dim






					@property
					def   __A      (			self      ):
						return self.time_input_dim * 4






					@property
					def   __A      (			self      ):
						return 100






					@property
					def   __A      (			self      ):
						torch.manual_seed(0      )

						A__							:   Dict					       =		{
						    """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,
						}

						A__							:   List[str]					       =		UNetaDConditionModel(**A__      )
						return model






					@property
					def   __A      (			self      ):
						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   __A      (			self      ):
						torch.manual_seed(0      )
						A__							:   Tuple					       =		VQModel(**self.dummy_movq_kwargs      )
						return model






					def   __A      (			self      ):
						A__							:   Optional[int]					       =		self.dummy_unet
						A__							:   Dict					       =		self.dummy_movq

						A__							:   List[Any]					       =		{
						    """num_train_timesteps""": 1000,
						    """beta_schedule""": """linear""",
						    """beta_start""": 0.0_0_0_8_5,
						    """beta_end""": 0.0_1_2,
						    """clip_sample""": False,
						    """set_alpha_to_one""": False,
						    """steps_offset""": 0,
						    """prediction_type""": """epsilon""",
						    """thresholding""": False,
						}

						A__							:   List[str]					       =		DDIMScheduler(**A__      )

						A__							:   List[str]					       =		{
						    """unet""": unet,
						    """scheduler""": scheduler,
						    """movq""": movq,
						}

						return components






					def   __A      (			self   ,	A__   ,	A__=0      ):
						A__							:   List[str]					       =		floats_tensor((1, self.text_embedder_hidden_size)   ,	rng=random.Random(A__      )      ).to(A__      )
						A__							:   Any					       =		floats_tensor((1, self.text_embedder_hidden_size)   ,	rng=random.Random(seed + 1      )      ).to(
						    A__      )
						# create init_image
						A__							:   Dict					       =		floats_tensor((1, 3, 64, 64)   ,	rng=random.Random(A__      )      ).to(A__      )
						A__							:   Optional[int]					       =		image.cpu().permute(0   ,	2   ,	3   ,	1      )[0]
						A__							:   Dict					       =		Image.fromarray(np.uinta(A__      )      ).convert("""RGB"""      ).resize((256, 256)      )

						if str(A__      ).startswith("""mps"""      ):
							A__							:   Any					       =		torch.manual_seed(A__      )
						else:
							A__							:   List[Any]					       =		torch.Generator(device=A__      ).manual_seed(A__      )
						A__							:   Optional[int]					       =		{
						    """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   __A      (			self      ):
						A__							:   str					       =		"""cpu"""

						A__							:   Any					       =		self.get_dummy_components()

						A__							:   Union[str, Any]					       =		self.pipeline_class(**A__      )
						A__							:   List[str]					       =		pipe.to(A__      )

						pipe.set_progress_bar_config(disable=A__      )

						A__							:   Dict					       =		pipe(**self.get_dummy_inputs(A__      )      )
						A__							:   Any					       =		output.images

						A__							:   List[str]					       =		pipe(
						    **self.get_dummy_inputs(A__      )   ,	return_dict=A__   ,	)[0]

						A__							:   Optional[int]					       =		image[0, -3:, -3:, -1]
						A__							:   str					       =		image_from_tuple[0, -3:, -3:, -1]

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

						A__							:   str					       =		np.array(
						    [0.6_1_9_9_7_7_8, 0.6_3_9_8_4_4_0_6, 0.4_6_1_4_5_7_8_5, 0.6_2_9_4_4_9_8_4, 0.5_6_2_2_2_1_5, 0.4_7_3_0_6_1_3_2, 0.4_7_4_4_1_4_5_6, 0.4_6_0_7_6_0_6, 0.4_8_7_1_9_2_6_3]      )
						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    _a						(unittest.TestCase    ):


					'''simple docstring'''






					def   __A      (			self      ):
						# clean up the VRAM after each test
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()






					def   __A      (			self      ):
						A__							:   Optional[int]					       =		load_numpy(
						    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
						    """/kandinskyv22/kandinskyv22_img2img_frog.npy"""      )

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

						A__							:   int					       =		KandinskyVaaPriorPipeline.from_pretrained(
						    """kandinsky-community/kandinsky-2-2-prior"""   ,	torch_dtype=torch.floataa      )
						pipe_prior.to(A__      )

						A__							:   List[Any]					       =		KandinskyVaaImgaImgPipeline.from_pretrained(
						    """kandinsky-community/kandinsky-2-2-decoder"""   ,	torch_dtype=torch.floataa      )
						A__							:   List[str]					       =		pipeline.to(A__      )

						pipeline.set_progress_bar_config(disable=A__      )

						A__							:   Tuple					       =		torch.Generator(device="""cpu"""      ).manual_seed(0      )
						A__       ,       A__							:   Optional[Any]					       =		pipe_prior(
						    A__   ,	generator=A__   ,	num_inference_steps=5   ,	negative_prompt=""""""   ,	).to_tuple()

						A__							:   str					       =		pipeline(
						    image=A__   ,	image_embeds=A__   ,	negative_image_embeds=A__   ,	generator=A__   ,	num_inference_steps=100   ,	height=768   ,	width=768   ,	strength=0.2   ,	output_type="""np"""   ,	)

						A__							:   Optional[int]					       =		output.images[0]

						assert image.shape == (768, 768, 3)

						assert_mean_pixel_difference(A__   ,	A__      )



