



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

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available

@dataclass
class        UpperCAmelCase_  (       UpperCamelCase_	):

						'''simple docstring'''




						UpperCamelCase__      :			Union[List[PIL.Image.Image], np.ndarray]
						UpperCamelCase__      :			Optional[List[bool]]


if is_transformers_available() and is_torch_available():
			from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline











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_  :

						'''simple docstring'''




						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				,							):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= parent
													__SCREAMING_SNAKE_CASE									= batch_size
													__SCREAMING_SNAKE_CASE									= seq_length
													__SCREAMING_SNAKE_CASE									= is_training
													__SCREAMING_SNAKE_CASE									= use_input_mask
													__SCREAMING_SNAKE_CASE									= use_labels
													__SCREAMING_SNAKE_CASE									= vocab_size
													__SCREAMING_SNAKE_CASE									= hidden_size
													__SCREAMING_SNAKE_CASE									= projection_dim
													__SCREAMING_SNAKE_CASE									= num_hidden_layers
													__SCREAMING_SNAKE_CASE									= num_attention_heads
													__SCREAMING_SNAKE_CASE									= intermediate_size
													__SCREAMING_SNAKE_CASE									= dropout
													__SCREAMING_SNAKE_CASE									= attention_dropout
													__SCREAMING_SNAKE_CASE									= max_position_embeddings
													__SCREAMING_SNAKE_CASE									= initializer_range
													__SCREAMING_SNAKE_CASE									= scope
													__SCREAMING_SNAKE_CASE									= bos_token_id






						def 	_A     (   self		):







													'''simple docstring'''

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

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

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

													__SCREAMING_SNAKE_CASE									= self.get_config()

													return config, input_ids, tf.convert_to_tensor(_A		)






						def 	_A     (   self		):







													'''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 	_A     (   self				,							_A				,							_A				,							_A		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= TFBlipTextModel(config=_A		)
													__SCREAMING_SNAKE_CASE									= model(_A				,							attention_mask=_A				,							training=_A		)
													__SCREAMING_SNAKE_CASE									= 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 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.prepare_config_and_inputs()
													__SCREAMING_SNAKE_CASE							,	__SCREAMING_SNAKE_CASE							,	__SCREAMING_SNAKE_CASE									= config_and_inputs
													__SCREAMING_SNAKE_CASE									= {'input_ids': input_ids, 'attention_mask': input_mask}
													return config, inputs_dict







@require_tf
class        UpperCAmelCase_  (       UpperCamelCase_   ,   unittest.TestCase	):

						'''simple docstring'''




						UpperCamelCase__      :			str      =  (TFBlipTextModel,) if is_tf_available() else ()
						UpperCamelCase__      :			int      =  False
						UpperCamelCase__      :			Optional[Any]      =  False
						UpperCamelCase__      :			Tuple      =  False






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= BlipTextModelTester(self		)
													__SCREAMING_SNAKE_CASE									= ConfigTester(self				,							config_class=_A				,							hidden_size=37		)






						def 	_A     (   self		):







													'''simple docstring'''

													self.config_tester.run_common_tests()






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*_A		)






						def 	_A     (   self		):







													'''simple docstring'''

													pass






						def 	_A     (   self		):







													'''simple docstring'''

													pass






						@unittest.skip(reason='Blip does not use inputs_embeds'		)
						def 	_A     (   self		):







													'''simple docstring'''

													pass






						@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'		)
						def 	_A     (   self		):







													'''simple docstring'''

													pass






						@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'		)
						def 	_A     (   self		):







													'''simple docstring'''

													pass






						@slow
						def 	_A     (   self		):







													'''simple docstring'''

													for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				__SCREAMING_SNAKE_CASE									= TFBlipTextModel.from_pretrained(_A		)
																				self.assertIsNotNone(_A		)






						def 	_A     (   self				,							_A=True		):







													'''simple docstring'''

													super().test_pt_tf_model_equivalence(allow_missing_keys=_A		)






