
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		:





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





     def 		UpperCAmelCase(self				:   Optional[Any]       )						->						Union[str, Any]:
         snake_case								= ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size       )

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

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

         snake_case								= self.get_config()

         return config, input_ids, tf.convert_to_tensor(_A       )





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







@require_tf
class 					lowerCamelCase		(  A_							,			unittest.TestCase  ):
     UpperCAmelCase__    :							str									=		(TFBlipTextModel,) if is_tf_available() else ()
     UpperCAmelCase__    :							List[str]									=		False
     UpperCAmelCase__    :							Optional[int]									=		False
     UpperCAmelCase__    :							int									=		False





     def 		UpperCAmelCase(self				:   Tuple       )						->						List[Any]:
         snake_case								= BlipTextModelTester(self       )
         snake_case								= ConfigTester(self    ,   config_class=_A    ,   hidden_size=3_7       )





     def 		UpperCAmelCase(self				:   Tuple       )						->						Any:
         self.config_tester.run_common_tests()





     def 		UpperCAmelCase(self				:   Optional[int]       )						->						Tuple:
         snake_case								= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_A       )





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





     def 		UpperCAmelCase(self				:   str       )						->						Optional[Any]:
         pass





     @unittest.skip(reason="Blip does not use inputs_embeds"       )
     def 		UpperCAmelCase(self				:   int       )						->						Optional[Any]:
         pass





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





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





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





     def 		UpperCAmelCase(self				:   Optional[Any]    ,   _A				:   str=True       )						->						List[str]:
         super().test_pt_tf_model_equivalence(allow_missing_keys=_A       )



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_A   =			{
    "configuration_lilt": ["LILT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LiltConfig"],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A   =			[
       "LILT_PRETRAINED_MODEL_ARCHIVE_LIST",
       "LiltForQuestionAnswering",
       "LiltForSequenceClassification",
       "LiltForTokenClassification",
       "LiltModel",
       "LiltPreTrainedModel",
   ]

if TYPE_CHECKING:
   from .configuration_lilt import LILT_PRETRAINED_CONFIG_ARCHIVE_MAP, LiltConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_lilt import (
          LILT_PRETRAINED_MODEL_ARCHIVE_LIST,
          LiltForQuestionAnswering,
          LiltForSequenceClassification,
          LiltForTokenClassification,
          LiltModel,
          LiltPreTrainedModel,
      )

else:
   import sys

   _A   =			_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

