
import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

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


if is_torch_available():
					import torch

					from transformers import BlipTextModel
					from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST


class 							lowercase   :



		def __init__(					self							, A_							, A_=12							, A_=7							, A_=True							, A_=True							, A_=True							, A_=99							, A_=32							, A_=32							, A_=5							, A_=4							, A_=37							, A_=0.1							, A_=0.1							, A_=512							, A_=0.02							, A_=0							, A_=None							, )    ->   Dict:
				"""simple docstring"""
				UpperCamelCase            =	parent
				UpperCamelCase            =	batch_size
				UpperCamelCase            =	seq_length
				UpperCamelCase            =	is_training
				UpperCamelCase            =	use_input_mask
				UpperCamelCase            =	use_labels
				UpperCamelCase            =	vocab_size
				UpperCamelCase            =	hidden_size
				UpperCamelCase            =	projection_dim
				UpperCamelCase            =	num_hidden_layers
				UpperCamelCase            =	num_attention_heads
				UpperCamelCase            =	intermediate_size
				UpperCamelCase            =	dropout
				UpperCamelCase            =	attention_dropout
				UpperCamelCase            =	max_position_embeddings
				UpperCamelCase            =	initializer_range
				UpperCamelCase            =	scope
				UpperCamelCase            =	bos_token_id



		def __UpperCamelCase					(					self			)    ->   List[str]:
				"""simple docstring"""
				UpperCamelCase            =	ids_tensor([self.batch_size, self.seq_length]							, self.vocab_size			)

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

				if input_mask is not None:
						UpperCamelCase      ,    UpperCamelCase            =	input_mask.shape
						UpperCamelCase            =	np.random.randint(1							, seq_length - 1							, size=(batch_size,)			)
						for batch_idx, start_index in enumerate(A_			):
								UpperCamelCase            =	1
								UpperCamelCase            =	0

				UpperCamelCase            =	self.get_config()

				return config, input_ids, input_mask



		def __UpperCamelCase					(					self			)    ->   Optional[Any]:
				"""simple docstring"""
				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 __UpperCamelCase					(					self							, A_							, A_							, A_			)    ->   Dict:
				"""simple docstring"""
				UpperCamelCase            =	BlipTextModel(config=A_			)
				model.to(A_			)
				model.eval()
				with torch.no_grad():
						UpperCamelCase            =	model(A_							, attention_mask=A_			)
						UpperCamelCase            =	model(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 __UpperCamelCase					(					self			)    ->   Tuple:
				"""simple docstring"""
				UpperCamelCase            =	self.prepare_config_and_inputs()
				UpperCamelCase      ,    UpperCamelCase      ,    UpperCamelCase            =	config_and_inputs
				UpperCamelCase            =	{'input_ids': input_ids, 'attention_mask': input_mask}
				return config, inputs_dict






@require_torch
class 							lowercase   (						_SCREAMING_SNAKE_CASE    ,  unittest.TestCase  ):
		__lowercase			:			Any      	=							(BlipTextModel,) if is_torch_available() else ()
		__lowercase			:			List[str]      	=							False
		__lowercase			:			Dict      	=							False
		__lowercase			:			Union[str, Any]      	=							False



		def __UpperCamelCase					(					self			)    ->   Tuple:
				"""simple docstring"""
				UpperCamelCase            =	BlipTextModelTester(self			)
				UpperCamelCase            =	ConfigTester(self							, config_class=A_							, hidden_size=37			)



		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				self.config_tester.run_common_tests()



		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				UpperCamelCase            =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*A_			)



		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				pass



		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				pass



		@unittest.skip(reason='Blip does not use inputs_embeds'			)
		def __UpperCamelCase					(					self			)    ->   Any:
				"""simple docstring"""
				pass



		@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'			)
		def __UpperCamelCase					(					self			)    ->   List[str]:
				"""simple docstring"""
				pass



		@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'			)
		def __UpperCamelCase					(					self			)    ->   str:
				"""simple docstring"""
				pass



		@slow
		def __UpperCamelCase					(					self			)    ->   Optional[int]:
				"""simple docstring"""
				for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						UpperCamelCase            =	BlipTextModel.from_pretrained(A_			)
						self.assertIsNotNone(A_			)



		def __UpperCamelCase					(					self			)    ->   str:
				"""simple docstring"""
				super().test_pt_tf_model_equivalence(allow_missing_keys=A_			)


from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, is_invisible_watermark_available, is_torch_available, is_transformers_available


@dataclass
class 							lowercase   (						_SCREAMING_SNAKE_CASE  ):
		__lowercase			:			Union[List[PIL.Image.Image], np.ndarray]


if is_transformers_available() and is_torch_available() and is_invisible_watermark_available():
					from .pipeline_stable_diffusion_xl import StableDiffusionXLPipeline
					from .pipeline_stable_diffusion_xl_imgaimg import StableDiffusionXLImgaImgPipeline
