






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.0_2    ,     _lowerCamelCase=0    ,     _lowerCamelCase=None    ,     ):
         UpperCamelCase_:   Any        =							parent
         UpperCamelCase_:   int        =							batch_size
         UpperCamelCase_:   Any        =							seq_length
         UpperCamelCase_:   Any        =							is_training
         UpperCamelCase_:   Any        =							use_input_mask
         UpperCamelCase_:   Union[str, Any]        =							use_labels
         UpperCamelCase_:   Optional[int]        =							vocab_size
         UpperCamelCase_:   Dict        =							hidden_size
         UpperCamelCase_:   Optional[int]        =							projection_dim
         UpperCamelCase_:   Dict        =							num_hidden_layers
         UpperCamelCase_:   str        =							num_attention_heads
         UpperCamelCase_:   Optional[int]        =							intermediate_size
         UpperCamelCase_:   List[Any]        =							dropout
         UpperCamelCase_:   Dict        =							attention_dropout
         UpperCamelCase_:   Optional[int]        =							max_position_embeddings
         UpperCamelCase_:   Union[str, Any]        =							initializer_range
         UpperCamelCase_:   List[str]        =							scope
         UpperCamelCase_:   Dict        =							bos_token_id





       def      _a       (   self				):
         UpperCamelCase_:   Optional[int]        =							ids_tensor([self.batch_size, self.seq_length]    ,     self.vocab_size				)

         UpperCamelCase_:   Optional[int]        =							None
         if self.use_input_mask:
           UpperCamelCase_:   int        =							random_attention_mask([self.batch_size, self.seq_length]				)

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

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

         return config, input_ids, tf.convert_to_tensor(A_				)





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







@require_tf
class 							_lowerCAmelCase(			_lowercase				,      unittest.TestCase   ):





       """simple docstring"""







       a							:						List[str]										=(TFBlipTextModel,) if is_tf_available() else ()
       a							:						Optional[int]										=False
       a							:						str										=False
       a							:						Optional[int]										=False





       def      _a       (   self				):
         UpperCamelCase_:   int        =							BlipTextModelTester(self				)
         UpperCamelCase_:   Optional[int]        =							ConfigTester(self    ,     config_class=A_    ,     hidden_size=3_7				)





       def      _a       (   self				):
         self.config_tester.run_common_tests()





       def      _a       (   self				):
         UpperCamelCase_:   Tuple        =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*A_				)





       def      _a       (   self				):
         pass





       def      _a       (   self				):
         pass





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





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





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





       @slow
       def      _a       (   self				):
         for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCamelCase_:   Any        =							TFBlipTextModel.from_pretrained(A_				)
           self.assertIsNotNone(A_				)





       def      _a       (   self    ,     _lowerCamelCase=True				):
         super().test_pt_tf_model_equivalence(allow_missing_keys=A_				)

"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_lowercase				 =					logging.get_logger(__name__)

_lowercase				 =					{
    '''google/mobilenet_v1_1.0_224''': '''https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v1_0.75_192''': '''https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json''',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}







class 					lowerCAmelCase_					(   _lowercase     ):



						'''simple docstring'''


						_lowerCamelCase:     Optional[Any]   =     '''mobilenet_v1'''


						def __init__(			self  :   Optional[int]	,A_  :   Optional[int]=3	,A_  :   Any=224	,A_  :   List[Any]=1.0	,A_  :   Union[str, Any]=8	,A_  :   Union[str, Any]="relu6"	,A_  :   Optional[Any]=True	,A_  :   List[str]=0.9_99	,A_  :   int=0.02	,A_  :   int=0.0_01	,**A_  :   Union[str, Any]	,)  -> Dict:
							super().__init__(**A_   )

							if depth_multiplier <= 0:
								raise ValueError('depth_multiplier must be greater than zero.'   )

							A     = num_channels
							A     = image_size
							A     = depth_multiplier
							A     = min_depth
							A     = hidden_act
							A     = tf_padding
							A     = classifier_dropout_prob
							A     = initializer_range
							A     = layer_norm_eps







class 					lowerCAmelCase_					(   _lowercase     ):



						'''simple docstring'''


						_lowerCamelCase:     Optional[int]   =     version.parse('''1.11'''     )


						@property
						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[int]   )  -> Mapping[str, Mapping[int, str]]:
							return OrderedDict([('pixel_values', {0: 'batch'})]   )


						@property
						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[int]   )  -> Mapping[str, Mapping[int, str]]:
							if self.task == "image-classification":
								return OrderedDict([('logits', {0: 'batch'})]   )
							else:
								return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]   )




						@property
						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[int]   )  -> float:
							return 1e-4