





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCamelCase__      ={
    'configuration_lilt': ['LILT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LiltConfig'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__      =[
           '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

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







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    ,						__lowerCamelCase    ,						__lowerCamelCase=1_2    ,						__lowerCamelCase=7    ,						__lowerCamelCase=True    ,						__lowerCamelCase=True    ,						__lowerCamelCase=True    ,						__lowerCamelCase=9_9    ,						__lowerCamelCase=3_2    ,						__lowerCamelCase=3_2    ,						__lowerCamelCase=2    ,						__lowerCamelCase=4    ,						__lowerCamelCase=3_7    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=5_1_2    ,						__lowerCamelCase=0.02    ,						__lowerCamelCase=0    ,						__lowerCamelCase=None    ,						)			->     Any:
            _SCREAMING_SNAKE_CASE       :	int						    =							parent
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							batch_size
            _SCREAMING_SNAKE_CASE       :	str						    =							seq_length
            _SCREAMING_SNAKE_CASE       :	str						    =							is_training
            _SCREAMING_SNAKE_CASE       :	str						    =							use_input_mask
            _SCREAMING_SNAKE_CASE       :	int						    =							use_labels
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							vocab_size
            _SCREAMING_SNAKE_CASE       :	Dict						    =							hidden_size
            _SCREAMING_SNAKE_CASE       :	int						    =							projection_dim
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							num_hidden_layers
            _SCREAMING_SNAKE_CASE       :	int						    =							num_attention_heads
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							intermediate_size
            _SCREAMING_SNAKE_CASE       :	int						    =							dropout
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							attention_dropout
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							max_position_embeddings
            _SCREAMING_SNAKE_CASE       :	Dict						    =							initializer_range
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							scope
            _SCREAMING_SNAKE_CASE       :	Any						    =							bos_token_id




       def     UpperCamelCase_			(      self							)			->     Optional[Any]:
            _SCREAMING_SNAKE_CASE       :	Any						    =							ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size							)

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

            if input_mask is not None:
                 _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							input_mask.numpy()
                 _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							input_mask.shape
                 _SCREAMING_SNAKE_CASE       :	str						    =							np.random.randint(1    ,						seq_length - 1    ,						size=(batch_size,)							)
                 for batch_idx, start_index in enumerate(__lowerCamelCase							):
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							1
                      _SCREAMING_SNAKE_CASE       :	List[str]						    =							0

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.get_config()

            return config, input_ids, tf.convert_to_tensor(__lowerCamelCase							)




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





@require_tf
class 			lowerCAmelCase__( __lowercase  ,     unittest.TestCase    ):






       '''simple docstring'''


       __snake_case 			=    (TFBlipTextModel,) if is_tf_available() else ()
       __snake_case 			=    False
       __snake_case 			=    False
       __snake_case 			=    False




       def     UpperCamelCase_			(      self							)			->     Any:
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							BlipTextModelTester(self							)
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							ConfigTester(self    ,						config_class=__lowerCamelCase    ,						hidden_size=3_7							)




       def     UpperCamelCase_			(      self							)			->     Union[str, Any]:
            self.config_tester.run_common_tests()




       def     UpperCamelCase_			(      self							)			->     int:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*__lowerCamelCase							)




       def     UpperCamelCase_			(      self							)			->     int:
            pass




       def     UpperCamelCase_			(      self							)			->     Tuple:
            pass




       @unittest.skip(reason="Blip does not use inputs_embeds"							)
       def     UpperCamelCase_			(      self							)			->     Dict:
            pass




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




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




       @slow
       def     UpperCamelCase_			(      self							)			->     int:
            for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							TFBlipTextModel.from_pretrained(__lowerCamelCase							)
                 self.assertIsNotNone(__lowerCamelCase							)







       def     UpperCamelCase_			(      self    ,						__lowerCamelCase=True							)			->     int:
            super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCamelCase							)