



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






		def __init__(						self      :     Tuple				,		UpperCamelCase__      :     Any				,		UpperCamelCase__      :     Optional[Any]=12				,		UpperCamelCase__      :     Any=7				,		UpperCamelCase__      :     List[Any]=True				,		UpperCamelCase__      :     Any=True				,		UpperCamelCase__      :     List[str]=True				,		UpperCamelCase__      :     List[str]=99				,		UpperCamelCase__      :     Optional[int]=32				,		UpperCamelCase__      :     Tuple=32				,		UpperCamelCase__      :     Any=2				,		UpperCamelCase__      :     Any=4				,		UpperCamelCase__      :     Dict=37				,		UpperCamelCase__      :     List[str]=0.1				,		UpperCamelCase__      :     List[str]=0.1				,		UpperCamelCase__      :     Tuple=5_12				,		UpperCamelCase__      :     Optional[int]=0.02				,		UpperCamelCase__      :     Optional[Any]=0				,		UpperCamelCase__      :     Tuple=None				,		)				->					Tuple:
								'''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 SCREAMING_SNAKE_CASE_			(						self      :     List[str]      )				->					Tuple:
								'''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         =     input_mask.numpy()
														UpperCAmelCase       ,		UpperCAmelCase         =     input_mask.shape
														UpperCAmelCase         =     np.random.randint(1				,		seq_length - 1				,		size=(batch_size,)      )
														for batch_idx, start_index in enumerate(UpperCamelCase__      ):
																				UpperCAmelCase         =     1
																				UpperCAmelCase         =     0

								UpperCAmelCase         =     self.get_config()

								return config, input_ids, tf.convert_to_tensor(UpperCamelCase__      )






		def SCREAMING_SNAKE_CASE_			(						self      :     Dict      )				->					List[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 SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]				,		UpperCamelCase__      :     Union[str, Any]				,		UpperCamelCase__      :     int				,		UpperCamelCase__      :     List[Any]      )				->					Tuple:
								'''simple docstring'''







								UpperCAmelCase         =     TFBlipTextModel(config=UpperCamelCase__      )
								UpperCAmelCase         =     model(UpperCamelCase__				,		attention_mask=UpperCamelCase__				,		training=UpperCamelCase__      )
								UpperCAmelCase         =     model(UpperCamelCase__				,		training=UpperCamelCase__      )
								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 SCREAMING_SNAKE_CASE_			(						self      :     Optional[Any]      )				->					Dict:
								'''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_tf
class  __magic_name__   (							A__,  unittest.TestCase						):
		lowercase      :       Tuple          =(TFBlipTextModel,) if is_tf_available() else ()
		lowercase      :       List[Any]          =False
		lowercase      :       Optional[Any]          =False
		lowercase      :       List[str]          =False






		def SCREAMING_SNAKE_CASE_			(						self      :     Optional[Any]      )				->					List[Any]:
								'''simple docstring'''







								UpperCAmelCase         =     BlipTextModelTester(self      )
								UpperCAmelCase         =     ConfigTester(self				,		config_class=UpperCamelCase__				,		hidden_size=37      )






		def SCREAMING_SNAKE_CASE_			(						self      :     List[Any]      )				->					Optional[Any]:
								'''simple docstring'''







								self.config_tester.run_common_tests()






		def SCREAMING_SNAKE_CASE_			(						self      :     Any      )				->					int:
								'''simple docstring'''







								UpperCAmelCase         =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*UpperCamelCase__      )






		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]      )				->					Dict:
								'''simple docstring'''







								pass






		def SCREAMING_SNAKE_CASE_			(						self      :     Tuple      )				->					Any:
								'''simple docstring'''







								pass






		@unittest.skip(reason="Blip does not use inputs_embeds"      )
		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]      )				->					int:
								'''simple docstring'''







								pass






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







								pass






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







								pass






		@slow
		def SCREAMING_SNAKE_CASE_			(						self      :     Dict      )				->					Optional[int]:
								'''simple docstring'''







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







		def SCREAMING_SNAKE_CASE_			(						self      :     int				,		UpperCamelCase__      :     Dict=True      )				->					Dict:
								'''simple docstring'''







								super().test_pt_tf_model_equivalence(allow_missing_keys=UpperCamelCase__      )








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__lowerCamelCase     :							Any  							=				{
    "configuration_mega": ["MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP", "MegaConfig", "MegaOnnxConfig"],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase     :							Optional[int]  							=				[
		    "MEGA_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "MegaForCausalLM",
		    "MegaForMaskedLM",
		    "MegaForMultipleChoice",
		    "MegaForQuestionAnswering",
		    "MegaForSequenceClassification",
		    "MegaForTokenClassification",
		    "MegaModel",
		    "MegaPreTrainedModel",
		]

if TYPE_CHECKING:
		from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mega import (
				    MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MegaForCausalLM,
				    MegaForMaskedLM,
				    MegaForMultipleChoice,
				    MegaForQuestionAnswering,
				    MegaForSequenceClassification,
				    MegaForTokenClassification,
				    MegaModel,
				    MegaPreTrainedModel,
				)

else:
		import sys

		__lowerCamelCase     :							int  							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



