






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







		'''simple docstring'''



		def __init__(							self				,		_UpperCamelCase				,		_UpperCamelCase=1_2				,		_UpperCamelCase=7				,		_UpperCamelCase=True				,		_UpperCamelCase=True				,		_UpperCamelCase=True				,		_UpperCamelCase=9_9				,		_UpperCamelCase=3_2				,		_UpperCamelCase=3_2				,		_UpperCamelCase=2				,		_UpperCamelCase=4				,		_UpperCamelCase=3_7				,		_UpperCamelCase=0.1				,		_UpperCamelCase=0.1				,		_UpperCamelCase=5_1_2				,		_UpperCamelCase=0.02				,		_UpperCamelCase=0				,		_UpperCamelCase=None				,		)	->							List[str]:
							UpperCAmelCase_    :      Optional[Any]            =						parent
							UpperCAmelCase_    :      Any            =						batch_size
							UpperCAmelCase_    :      Optional[int]            =						seq_length
							UpperCAmelCase_    :      Optional[int]            =						is_training
							UpperCAmelCase_    :      Dict            =						use_input_mask
							UpperCAmelCase_    :      Any            =						use_labels
							UpperCAmelCase_    :      str            =						vocab_size
							UpperCAmelCase_    :      str            =						hidden_size
							UpperCAmelCase_    :      List[Any]            =						projection_dim
							UpperCAmelCase_    :      Optional[int]            =						num_hidden_layers
							UpperCAmelCase_    :      int            =						num_attention_heads
							UpperCAmelCase_    :      Union[str, Any]            =						intermediate_size
							UpperCAmelCase_    :      Any            =						dropout
							UpperCAmelCase_    :      int            =						attention_dropout
							UpperCAmelCase_    :      Tuple            =						max_position_embeddings
							UpperCAmelCase_    :      Dict            =						initializer_range
							UpperCAmelCase_    :      Any            =						scope
							UpperCAmelCase_    :      Optional[Any]            =						bos_token_id



		def 					__UpperCAmelCase			(							self   )	->							List[Any]:
							UpperCAmelCase_    :      str            =						ids_tensor([self.batch_size, self.seq_length]				,		self.vocab_size   )

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

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

							UpperCAmelCase_    :      List[str]            =						self.get_config()

							return config, input_ids, tf.convert_to_tensor(_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self   )	->							Dict:
							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				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )	->							int:
							UpperCAmelCase_    :      str            =						TFBlipTextModel(config=_UpperCamelCase   )
							UpperCAmelCase_    :      List[Any]            =						model(_UpperCamelCase				,		attention_mask=_UpperCamelCase				,		training=_UpperCamelCase   )
							UpperCAmelCase_    :      Optional[int]            =						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 					__UpperCAmelCase			(							self   )	->							Any:
							UpperCAmelCase_    :      Tuple            =						self.prepare_config_and_inputs()
							UpperCAmelCase_    :      List[str]            =						config_and_inputs
							UpperCAmelCase_    :      Union[str, Any]            =						{'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict





@require_tf
class   lowerCamelCase      (snake_case_ ,  unittest.TestCase			):







		'''simple docstring'''



		_snake_case    :    List[str]       						=  (TFBlipTextModel,) if is_tf_available() else ()
		_snake_case    :    Dict       						=  False
		_snake_case    :    int       						=  False
		_snake_case    :    Any       						=  False



		def 					__UpperCAmelCase			(							self   )	->							Dict:
							UpperCAmelCase_    :      Optional[int]            =						BlipTextModelTester(self   )
							UpperCAmelCase_    :      List[Any]            =						ConfigTester(self				,		config_class=_UpperCamelCase				,		hidden_size=3_7   )



		def 					__UpperCAmelCase			(							self   )	->							List[str]:
							self.config_tester.run_common_tests()



		def 					__UpperCAmelCase			(							self   )	->							Any:
							UpperCAmelCase_    :      Any            =						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self   )	->							Tuple:
							pass



		def 					__UpperCAmelCase			(							self   )	->							int:
							pass



		@unittest.skip(reason='Blip does not use inputs_embeds'   )
		def 					__UpperCAmelCase			(							self   )	->							List[Any]:
							pass



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



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



		@slow
		def 					__UpperCAmelCase			(							self   )	->							str:





							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCAmelCase_    :      Tuple            =						TFBlipTextModel.from_pretrained(_UpperCamelCase   )
												self.assertIsNotNone(_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase=True   )	->							List[str]:
							super().test_pt_tf_model_equivalence(allow_missing_keys=_UpperCamelCase   )







from typing import TYPE_CHECKING

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


a_    					=       {'configuration_encoder_decoder': ['EncoderDecoderConfig']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   a_    					=       ['EncoderDecoderModel']

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   a_    					=       ['TFEncoderDecoderModel']

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   a_    					=       ['FlaxEncoderDecoderModel']

if TYPE_CHECKING:
   from .configuration_encoder_decoder import EncoderDecoderConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_encoder_decoder import EncoderDecoderModel

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_encoder_decoder import TFEncoderDecoderModel

   try:
      if not is_flax_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_flax_encoder_decoder import FlaxEncoderDecoderModel

else:
   import sys

   a_    					=       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



