


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 	snake_case_       :
     def __init__(				self       :str      ,__snake_case       :str      ,__snake_case       :Dict=12      ,__snake_case       :str=7      ,__snake_case       :List[str]=True      ,__snake_case       :Any=True      ,__snake_case       :Any=True      ,__snake_case       :Dict=99      ,__snake_case       :Any=32      ,__snake_case       :Any=32      ,__snake_case       :List[str]=2      ,__snake_case       :Dict=4      ,__snake_case       :str=37      ,__snake_case       :List[str]=0.1      ,__snake_case       :List[str]=0.1      ,__snake_case       :Dict=5_12      ,__snake_case       :List[str]=0.02      ,__snake_case       :Any=0      ,__snake_case       :Optional[int]=None      ,) ->   Optional[Any]:
            a__					=					parent
            a__					=					batch_size
            a__					=					seq_length
            a__					=					is_training
            a__					=					use_input_mask
            a__					=					use_labels
            a__					=					vocab_size
            a__					=					hidden_size
            a__					=					projection_dim
            a__					=					num_hidden_layers
            a__					=					num_attention_heads
            a__					=					intermediate_size
            a__					=					dropout
            a__					=					attention_dropout
            a__					=					max_position_embeddings
            a__					=					initializer_range
            a__					=					scope
            a__					=					bos_token_id
     def 			lowerCamelCase__(				self       :Any				) ->   Optional[Any]:
            a__					=					ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size				)

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

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

            a__					=					self.get_config()

            return config, input_ids, tf.convert_to_tensor(__lowerCamelCase				)
     def 			lowerCamelCase__(				self       :Optional[Any]				) ->   int:
            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 			lowerCamelCase__(				self       :List[str]      ,__snake_case       :Optional[int]      ,__snake_case       :Dict      ,__snake_case       :str				) ->   List[str]:
            a__					=					TFBlipTextModel(config=__lowerCamelCase				)
            a__					=					model(__lowerCamelCase      ,attention_mask=__lowerCamelCase      ,training=__lowerCamelCase				)
            a__					=					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 			lowerCamelCase__(				self       :Any				) ->   int:
            a__					=					self.prepare_config_and_inputs()
            a__					=					config_and_inputs
            a__					=					{'''input_ids''': input_ids, '''attention_mask''': input_mask}
            return config, inputs_dict







@require_tf
class 	snake_case_       (lowerCamelCase__     ,						unittest.TestCase				):
     UpperCAmelCase__ :   Tuple   				=      (TFBlipTextModel,) if is_tf_available() else ()
     UpperCAmelCase__ :   int   				=      False
     UpperCAmelCase__ :   Tuple   				=      False
     UpperCAmelCase__ :   Optional[Any]   				=      False
     def 			lowerCamelCase__(				self       :List[str]				) ->   List[str]:
            a__					=					BlipTextModelTester(self				)
            a__					=					ConfigTester(self      ,config_class=__lowerCamelCase      ,hidden_size=37				)
     def 			lowerCamelCase__(				self       :Optional[Any]				) ->   List[Any]:
            self.config_tester.run_common_tests()
     def 			lowerCamelCase__(				self       :List[Any]				) ->   Optional[Any]:
            a__					=					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*__lowerCamelCase				)
     def 			lowerCamelCase__(				self       :Dict				) ->   int:
            pass
     def 			lowerCamelCase__(				self       :str				) ->   int:
            pass
     @unittest.skip(reason='Blip does not use inputs_embeds'				)
     def 			lowerCamelCase__(				self       :Dict				) ->   List[Any]:
            pass
     @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'				)
     def 			lowerCamelCase__(				self       :Tuple				) ->   Any:
            pass
     @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'				)
     def 			lowerCamelCase__(				self       :Any				) ->   Tuple:
            pass
     @slow
     def 			lowerCamelCase__(				self       :Optional[int]				) ->   Dict:






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



     def 			lowerCamelCase__(				self       :Optional[int]      ,__snake_case       :Union[str, Any]=True				) ->   Any:
            super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCamelCase				)








from typing import List

from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case							:	Tuple					      =				logging.get_logger(__name__)

snake_case							:	List[Any]					      =				{
    '''snap-research/efficientformer-l1-300''': (
        '''https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json'''
    ),
}







class 	snake_case_       (lowerCamelCase_				):
					UpperCAmelCase__ :   int   				=      '''efficientformer'''
					def __init__(				self       :List[str]      ,__snake_case       :List[int] = [3, 2, 6, 4]      ,__snake_case       :List[int] = [48, 96, 2_24, 4_48]      ,__snake_case       :List[bool] = [True, True, True, True]      ,__snake_case       :int = 4_48      ,__snake_case       :int = 32      ,__snake_case       :int = 4      ,__snake_case       :int = 7      ,__snake_case       :int = 5      ,__snake_case       :int = 8      ,__snake_case       :int = 4      ,__snake_case       :float = 0.0      ,__snake_case       :int = 16      ,__snake_case       :int = 3      ,__snake_case       :int = 3      ,__snake_case       :int = 3      ,__snake_case       :int = 2      ,__snake_case       :int = 1      ,__snake_case       :float = 0.0      ,__snake_case       :int = 1      ,__snake_case       :bool = True      ,__snake_case       :bool = True      ,__snake_case       :float = 1E-5      ,__snake_case       :str = "gelu"      ,__snake_case       :float = 0.02      ,__snake_case       :float = 1E-12      ,__snake_case       :int = 2_24      ,__snake_case       :float = 1E-05      ,**__snake_case       :Dict      ,) ->   None:
												super().__init__(**__snake_case				)

												a__					=					hidden_act
												a__					=					hidden_dropout_prob
												a__					=					hidden_sizes
												a__					=					num_hidden_layers
												a__					=					num_attention_heads
												a__					=					initializer_range
												a__					=					layer_norm_eps
												a__					=					patch_size
												a__					=					num_channels
												a__					=					depths
												a__					=					mlp_expansion_ratio
												a__					=					downsamples
												a__					=					dim
												a__					=					key_dim
												a__					=					attention_ratio
												a__					=					resolution
												a__					=					pool_size
												a__					=					downsample_patch_size
												a__					=					downsample_stride
												a__					=					downsample_pad
												a__					=					drop_path_rate
												a__					=					num_metaad_blocks
												a__					=					distillation
												a__					=					use_layer_scale
												a__					=					layer_scale_init_value
												a__					=					image_size
												a__					=					batch_norm_eps




