"""simple docstring"""

import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionInstructPixaPixPipeline,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()







class      UpperCAmelCase_       (						_lowercase			,							_lowercase			,							_lowercase			,							unittest.TestCase):
							snake_case__        =      StableDiffusionInstructPixaPixPipeline
							snake_case__        =      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''height''', '''width''', '''cross_attention_kwargs'''}
							snake_case__        =      TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
							snake_case__        =      IMAGE_TO_IMAGE_IMAGE_PARAMS
							snake_case__        =      IMAGE_TO_IMAGE_IMAGE_PARAMS






							def       _UpperCamelCase			(		self :      Optional[int]  )       ->       Any:
												torch.manual_seed(0  )
												_UpperCamelCase      						=	UNetaDConditionModel(
												    block_out_channels=(32, 64)     ,						layers_per_block=2     ,						sample_size=32     ,						in_channels=8     ,						out_channels=4     ,						down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')     ,						up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')     ,						cross_attention_dim=32     ,						)
												_UpperCamelCase      						=	PNDMScheduler(skip_prk_steps=__UpperCamelCase  )
												torch.manual_seed(0  )
												_UpperCamelCase      						=	AutoencoderKL(
												    block_out_channels=[32, 64]     ,						in_channels=3     ,						out_channels=3     ,						down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']     ,						up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']     ,						latent_channels=4     ,						)
												torch.manual_seed(0  )
												_UpperCamelCase      						=	CLIPTextConfig(
												    bos_token_id=0     ,						eos_token_id=2     ,						hidden_size=32     ,						intermediate_size=37     ,						layer_norm_eps=1E-05     ,						num_attention_heads=4     ,						num_hidden_layers=5     ,						pad_token_id=1     ,						vocab_size=1000     ,						)
												_UpperCamelCase      						=	CLIPTextModel(__UpperCamelCase  )
												_UpperCamelCase      						=	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''  )

												_UpperCamelCase      						=	{
												    """unet""": unet,
												    """scheduler""": scheduler,
												    """vae""": vae,
												    """text_encoder""": text_encoder,
												    """tokenizer""": tokenizer,
												    """safety_checker""": None,
												    """feature_extractor""": None,
												}
												return components






							def       _UpperCamelCase			(		self :      List[Any]     ,						__UpperCamelCase :      Optional[Any]     ,						__UpperCamelCase :      List[str]=0  )       ->       str:
												_UpperCamelCase      						=	floats_tensor((1, 3, 32, 32)     ,						rng=random.Random(__UpperCamelCase  )  ).to(__UpperCamelCase  )
												_UpperCamelCase      						=	image.cpu().permute(0     ,						2     ,						3     ,						1  )[0]
												_UpperCamelCase      						=	Image.fromarray(np.uinta(__UpperCamelCase  )  ).convert('''RGB'''  )
												if str(__UpperCamelCase  ).startswith('''mps'''  ):
																	_UpperCamelCase      						=	torch.manual_seed(__UpperCamelCase  )
												else:
																	_UpperCamelCase      						=	torch.Generator(device=__UpperCamelCase  ).manual_seed(__UpperCamelCase  )
												_UpperCamelCase      						=	{
												    """prompt""": """A painting of a squirrel eating a burger""",
												    """image""": image,
												    """generator""": generator,
												    """num_inference_steps""": 2,
												    """guidance_scale""": 6.0,
												    """image_guidance_scale""": 1,
												    """output_type""": """numpy""",
												}
												return inputs






							def       _UpperCamelCase			(		self :      int  )       ->       str:
												_UpperCamelCase      						=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
												_UpperCamelCase      						=	self.get_dummy_components()
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline(**__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe.to(__UpperCamelCase  )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase  )

												_UpperCamelCase      						=	self.get_dummy_inputs(__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1]
												assert image.shape == (1, 32, 32, 3)
												_UpperCamelCase      						=	np.array([0.7_5_2_6, 0.3_7_5_0, 0.4_5_4_7, 0.6_1_1_7, 0.5_8_6_6, 0.5_0_1_6, 0.4_3_2_7, 0.5_6_4_2, 0.4_8_1_5]  )

												assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      str  )       ->       Tuple:
												_UpperCamelCase      						=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
												_UpperCamelCase      						=	self.get_dummy_components()
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline(**__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe.to(__UpperCamelCase  )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase  )

												_UpperCamelCase      						=	self.get_dummy_inputs(__UpperCamelCase  )
												_UpperCamelCase      						=	"""french fries"""
												_UpperCamelCase      						=	sd_pipe(**__UpperCamelCase     ,						negative_prompt=__UpperCamelCase  )
												_UpperCamelCase      						=	output.images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1]

												assert image.shape == (1, 32, 32, 3)
												_UpperCamelCase      						=	np.array([0.7_5_1_1, 0.3_6_4_2, 0.4_5_5_3, 0.6_2_3_6, 0.5_7_9_7, 0.5_0_1_3, 0.4_3_4_3, 0.5_6_1_1, 0.4_8_3_1]  )

												assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      List[str]  )       ->       Union[str, Any]:
												_UpperCamelCase      						=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
												_UpperCamelCase      						=	self.get_dummy_components()
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline(**__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe.to(__UpperCamelCase  )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase  )

												_UpperCamelCase      						=	self.get_dummy_inputs(__UpperCamelCase  )
												_UpperCamelCase      						=	[inputs["""prompt"""]] * 2

												_UpperCamelCase      						=	np.array(inputs['''image''']  ).astype(np.floataa  ) / 255.0
												_UpperCamelCase      						=	torch.from_numpy(__UpperCamelCase  ).unsqueeze(0  ).to(__UpperCamelCase  )
												_UpperCamelCase      						=	image / 2 + 0.5
												_UpperCamelCase      						=	image.permute(0     ,						3     ,						1     ,						2  )
												_UpperCamelCase      						=	image.repeat(2     ,						1     ,						1     ,						1  )

												_UpperCamelCase      						=	sd_pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[-1, -3:, -3:, -1]

												assert image.shape == (2, 32, 32, 3)
												_UpperCamelCase      						=	np.array([0.5_8_1_2, 0.5_7_4_8, 0.5_2_2_2, 0.5_9_0_8, 0.5_6_9_5, 0.7_1_7_4, 0.6_8_0_4, 0.5_5_2_3, 0.5_5_7_9]  )

												assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      Optional[Any]  )       ->       Union[str, Any]:
												_UpperCamelCase      						=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
												_UpperCamelCase      						=	self.get_dummy_components()
												_UpperCamelCase      						=	EulerAncestralDiscreteScheduler(
												    beta_start=0.0_0_0_8_5     ,						beta_end=0.0_1_2     ,						beta_schedule='''scaled_linear'''  )
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline(**__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe.to(__UpperCamelCase  )
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase  )

												_UpperCamelCase      						=	self.get_dummy_inputs(__UpperCamelCase  )
												_UpperCamelCase      						=	sd_pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1]

												_UpperCamelCase      						=	[round(__UpperCamelCase     ,						4  ) for x in image_slice.flatten().tolist()]
												print(''','''.join([str(__UpperCamelCase  ) for x in slice]  )  )

												assert image.shape == (1, 32, 32, 3)
												_UpperCamelCase      						=	np.array([0.7_4_1_7, 0.3_8_4_2, 0.4_7_3_2, 0.5_7_7_6, 0.5_8_9_1, 0.5_1_3_9, 0.4_0_5_2, 0.5_6_7_3, 0.4_9_8_6]  )

												assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      List[Any]  )       ->       Optional[Any]:
												super().test_inference_batch_single_identical(expected_max_diff=3E-3  )






							def       _UpperCamelCase			(		self :      str  )       ->       Tuple:
												_UpperCamelCase      						=	self.get_dummy_components()
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline(**__UpperCamelCase  )
												_UpperCamelCase      						=	VaeImageProcessor(do_resize=__UpperCamelCase     ,						do_normalize=__UpperCamelCase  )
												_UpperCamelCase      						=	pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )

												_UpperCamelCase      						=	pipe(**self.get_dummy_inputs_by_type(__UpperCamelCase     ,						input_image_type='''pt'''  )  )[0]

												_UpperCamelCase      						=	components["""vae"""]
												_UpperCamelCase      						=	self.get_dummy_inputs_by_type(__UpperCamelCase     ,						input_image_type='''pt'''  )

												for image_param in self.image_latents_params:
																	if image_param in inputs.keys():
																						_UpperCamelCase      						=	vae.encode(inputs[image_param]  ).latent_dist.mode()

												_UpperCamelCase      						=	pipe(**__UpperCamelCase  )[0]

												_UpperCamelCase      						=	np.abs(out - out_latents_inputs  ).max()
												self.assertLess(__UpperCamelCase     ,						1E-4     ,						'''passing latents as image input generate different result from passing image'''  )







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






							def       _UpperCamelCase			(		self :      Any  )       ->       str:
												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()






							def       _UpperCamelCase			(		self :      Any     ,						__UpperCamelCase :      int=0  )       ->       Union[str, Any]:
												_UpperCamelCase      						=	torch.manual_seed(__UpperCamelCase  )
												_UpperCamelCase      						=	load_image(
												    '''https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_pix2pix/example.jpg'''  )
												_UpperCamelCase      						=	{
												    """prompt""": """turn him into a cyborg""",
												    """image""": image,
												    """generator""": generator,
												    """num_inference_steps""": 3,
												    """guidance_scale""": 7.5,
												    """image_guidance_scale""": 1.0,
												    """output_type""": """numpy""",
												}
												return inputs






							def       _UpperCamelCase			(		self :      Optional[int]  )       ->       Tuple:
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    '''timbrooks/instruct-pix2pix'''     ,						safety_checker=__UpperCamelCase  )
												pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing()

												_UpperCamelCase      						=	self.get_inputs()
												_UpperCamelCase      						=	pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1].flatten()

												assert image.shape == (1, 512, 512, 3)
												_UpperCamelCase      						=	np.array([0.5_9_0_2, 0.6_0_1_5, 0.6_0_2_7, 0.5_9_8_3, 0.6_0_9_2, 0.6_0_6_1, 0.5_7_6_5, 0.5_7_8_5, 0.5_5_5_5]  )

												assert np.abs(expected_slice - image_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      str  )       ->       List[Any]:
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    '''timbrooks/instruct-pix2pix'''     ,						safety_checker=__UpperCamelCase  )
												_UpperCamelCase      						=	LMSDiscreteScheduler.from_config(pipe.scheduler.config  )
												pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing()

												_UpperCamelCase      						=	self.get_inputs()
												_UpperCamelCase      						=	pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1].flatten()

												assert image.shape == (1, 512, 512, 3)
												_UpperCamelCase      						=	np.array([0.6_5_7_8, 0.6_8_1_7, 0.6_9_7_2, 0.6_7_6_1, 0.6_8_5_6, 0.6_9_1_6, 0.6_4_2_8, 0.6_5_1_6, 0.6_3_0_1]  )

												assert np.abs(expected_slice - image_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      str  )       ->       Union[str, Any]:
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    '''timbrooks/instruct-pix2pix'''     ,						safety_checker=__UpperCamelCase  )
												_UpperCamelCase      						=	DDIMScheduler.from_config(pipe.scheduler.config  )
												pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing()

												_UpperCamelCase      						=	self.get_inputs()
												_UpperCamelCase      						=	pipe(**__UpperCamelCase  ).images
												_UpperCamelCase      						=	image[0, -3:, -3:, -1].flatten()

												assert image.shape == (1, 512, 512, 3)
												_UpperCamelCase      						=	np.array([0.3_8_2_8, 0.3_8_3_4, 0.3_8_1_8, 0.3_7_9_2, 0.3_8_6_5, 0.3_7_5_2, 0.3_7_9_2, 0.3_8_4_7, 0.3_7_5_3]  )

												assert np.abs(expected_slice - image_slice  ).max() < 1E-3






							def       _UpperCamelCase			(		self :      List[str]  )       ->       List[str]:
												_UpperCamelCase      						=	0

												def callback_fn(__UpperCamelCase :      Optional[int]     ,						__UpperCamelCase :      List[Any]     ,						__UpperCamelCase :      int  ) -> None:
																	_UpperCamelCase      						=	True
																	nonlocal number_of_steps
																	number_of_steps += 1
																	if step == 1:
																						_UpperCamelCase      						=	latents.detach().cpu().numpy()
																						assert latents.shape == (1, 4, 64, 64)
																						_UpperCamelCase      						=	latents[0, -3:, -3:, -1]
																						_UpperCamelCase      						=	np.array([-0.2_4_6_3, -0.4_6_4_4, -0.9_7_5_6, 1.5_1_7_6, 1.4_4_1_4, 0.7_8_6_6, 0.9_8_9_7, 0.8_5_2_1, 0.7_9_8_3]  )

																						assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 5E-2
																	elif step == 2:
																						_UpperCamelCase      						=	latents.detach().cpu().numpy()
																						assert latents.shape == (1, 4, 64, 64)
																						_UpperCamelCase      						=	latents[0, -3:, -3:, -1]
																						_UpperCamelCase      						=	np.array([-0.2_6_4_4, -0.4_6_2_6, -0.9_6_5_3, 1.5_1_7_6, 1.4_5_5_1, 0.7_6_8_6, 0.9_8_0_5, 0.8_4_5_2, 0.8_1_1_5]  )

																						assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 5E-2

												_UpperCamelCase      						=	False

												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    '''timbrooks/instruct-pix2pix'''     ,						safety_checker=__UpperCamelCase     ,						torch_dtype=torch.floataa  )
												_UpperCamelCase      						=	pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing()

												_UpperCamelCase      						=	self.get_inputs()
												pipe(**__UpperCamelCase     ,						callback=__UpperCamelCase     ,						callback_steps=1  )
												assert callback_fn.has_been_called
												assert number_of_steps == 3






							def       _UpperCamelCase			(		self :      Optional[int]  )       ->       List[Any]:
												torch.cuda.empty_cache()
												torch.cuda.reset_max_memory_allocated()
												torch.cuda.reset_peak_memory_stats()

												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    '''timbrooks/instruct-pix2pix'''     ,						safety_checker=__UpperCamelCase     ,						torch_dtype=torch.floataa  )
												_UpperCamelCase      						=	pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing(1  )
												pipe.enable_sequential_cpu_offload()

												_UpperCamelCase      						=	self.get_inputs()
												_UpperCamelCase      						=	pipe(**__UpperCamelCase  )

												_UpperCamelCase      						=	torch.cuda.max_memory_allocated()
												# make sure that less than 2.2 GB is allocated
												assert mem_bytes < 2.2 * 10**9






							def       _UpperCamelCase			(		self :      List[str]  )       ->       Tuple:
												_UpperCamelCase      						=	self.get_inputs()
												# resize to resolution that is divisible by 8 but not 16 or 32
												_UpperCamelCase      						=	inputs["""image"""].resize((504, 504)  )

												_UpperCamelCase      						=	"""timbrooks/instruct-pix2pix"""
												_UpperCamelCase      						=	StableDiffusionInstructPixaPixPipeline.from_pretrained(
												    __UpperCamelCase     ,						safety_checker=__UpperCamelCase     ,						)
												pipe.to(__UpperCamelCase  )
												pipe.set_progress_bar_config(disable=__UpperCamelCase  )
												pipe.enable_attention_slicing()

												_UpperCamelCase      						=	pipe(**__UpperCamelCase  )
												_UpperCamelCase      						=	output.images[0]

												_UpperCamelCase      						=	image[255:258, 383:386, -1]

												assert image.shape == (504, 504, 3)
												_UpperCamelCase      						=	np.array([0.2_7_2_6, 0.2_5_2_9, 0.2_6_6_4, 0.2_6_5_5, 0.2_6_4_1, 0.2_6_4_2, 0.2_5_9_1, 0.2_6_4_9, 0.2_5_9_0]  )

												assert np.abs(image_slice.flatten() - expected_slice  ).max() < 5E-3





'''simple docstring'''




from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

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


if is_tf_available():
							import tensorflow as tf

							from transformers import TFBlipTextModel
							from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST

class 			UpperCamelCase_ :





	def __init__(  self		,		A		,		A=12		,		A=7		,		A=True		,		A=True		,		A=True		,		A=99		,		A=32		,		A=32		,		A=2		,		A=4		,		A=37		,		A=0.1		,		A=0.1		,		A=512		,		A=0.0_2		,		A=0		,		A=None		,		)			->			Any:
								UpperCAmelCase     :		Optional[Any]							     =		parent
								UpperCAmelCase     :		str							     =		batch_size
								UpperCAmelCase     :		Union[str, Any]							     =		seq_length
								UpperCAmelCase     :		Optional[Any]							     =		is_training
								UpperCAmelCase     :		int							     =		use_input_mask
								UpperCAmelCase     :		List[Any]							     =		use_labels
								UpperCAmelCase     :		Dict							     =		vocab_size
								UpperCAmelCase     :		str							     =		hidden_size
								UpperCAmelCase     :		List[Any]							     =		projection_dim
								UpperCAmelCase     :		Tuple							     =		num_hidden_layers
								UpperCAmelCase     :		Dict							     =		num_attention_heads
								UpperCAmelCase     :		Optional[Any]							     =		intermediate_size
								UpperCAmelCase     :		Any							     =		dropout
								UpperCAmelCase     :		List[Any]							     =		attention_dropout
								UpperCAmelCase     :		Optional[Any]							     =		max_position_embeddings
								UpperCAmelCase     :		Tuple							     =		initializer_range
								UpperCAmelCase     :		Optional[Any]							     =		scope
								UpperCAmelCase     :		Union[str, Any]							     =		bos_token_id





	def  _lowercase(  self    )			->			Tuple:
								UpperCAmelCase     :		Optional[int]							     =		ids_tensor([self.batch_size, self.seq_length]		,		self.vocab_size    )

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

								if input_mask is not None:
															UpperCAmelCase     :		Tuple							     =		input_mask.numpy()
															UpperCAmelCase     ,     UpperCAmelCase     :		int							     =		input_mask.shape
															UpperCAmelCase     :		Optional[int]							     =		np.random.randint(1		,		seq_length - 1		,		size=(batch_size,)    )
															for batch_idx, start_index in enumerate(A    ):
																						UpperCAmelCase     :		Tuple							     =		1
																						UpperCAmelCase     :		Optional[Any]							     =		0

								UpperCAmelCase     :		int							     =		self.get_config()

								return config, input_ids, tf.convert_to_tensor(A    )





	def  _lowercase(  self    )			->			int:
								return BlipTextConfig(
								    vocab_size=self.vocab_size		,		hidden_size=self.hidden_size		,		projection_dim=self.projection_dim		,		num_hidden_layers=self.num_hidden_layers		,		num_attention_heads=self.num_attention_heads		,		intermediate_size=self.intermediate_size		,		dropout=self.dropout		,		attention_dropout=self.attention_dropout		,		max_position_embeddings=self.max_position_embeddings		,		initializer_range=self.initializer_range		,		bos_token_id=self.bos_token_id		,		)





	def  _lowercase(  self		,		A		,		A		,		A    )			->			Union[str, Any]:
								UpperCAmelCase     :		int							     =		TFBlipTextModel(config=A    )
								UpperCAmelCase     :		Union[str, Any]							     =		model(A		,		attention_mask=A		,		training=A    )
								UpperCAmelCase     :		int							     =		model(A		,		training=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  _lowercase(  self    )			->			Optional[int]:
								UpperCAmelCase     :		Dict							     =		self.prepare_config_and_inputs()
								UpperCAmelCase     ,     UpperCAmelCase     ,     UpperCAmelCase     :		Any							     =		config_and_inputs
								UpperCAmelCase     :		Optional[Any]							     =		{"""input_ids""": input_ids, """attention_mask""": input_mask}
								return config, inputs_dict




@require_tf
class 			UpperCamelCase_ (							__magic_name__      ,     unittest.TestCase			):
	lowercase          = (TFBlipTextModel,) if is_tf_available() else ()
	lowercase          = False
	lowercase          = False
	lowercase          = False





	def  _lowercase(  self    )			->			int:
								UpperCAmelCase     :		Union[str, Any]							     =		BlipTextModelTester(self    )
								UpperCAmelCase     :		List[str]							     =		ConfigTester(self		,		config_class=A		,		hidden_size=37    )





	def  _lowercase(  self    )			->			Tuple:
								self.config_tester.run_common_tests()





	def  _lowercase(  self    )			->			List[Any]:
								UpperCAmelCase     :		List[Any]							     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*A    )





	def  _lowercase(  self    )			->			List[str]:
								pass





	def  _lowercase(  self    )			->			Optional[int]:
								pass





	@unittest.skip(reason="""Blip does not use inputs_embeds"""    )
	def  _lowercase(  self    )			->			Union[str, Any]:
								pass





	@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""    )
	def  _lowercase(  self    )			->			Optional[int]:
								pass





	@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""    )
	def  _lowercase(  self    )			->			Dict:
								pass





	@slow
	def  _lowercase(  self    )			->			Dict:
								for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCAmelCase     :		Any							     =		TFBlipTextModel.from_pretrained(A    )
															self.assertIsNotNone(A    )






	def  _lowercase(  self		,		A=True    )			->			str:
								super().test_pt_tf_model_equivalence(allow_missing_keys=A    )

