





import copy
import os
from typing import Union

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


lowerCAmelCase							:       Any					 =	logging.get_logger(__name__)

lowerCAmelCase							:       Tuple					 =	{
    """BridgeTower/bridgetower-base""": """https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json""",
    """BridgeTower/bridgetower-base-itm-mlm""": (
        """https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json"""
    ),
}





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     '''bridgetower_vision_model'''






				def __init__(  self			, _lowerCAmelCase=768			, _lowerCAmelCase=12			, _lowerCAmelCase=3			, _lowerCAmelCase=16			, _lowerCAmelCase=288			, _lowerCAmelCase=1			, _lowerCAmelCase=1e-05			, _lowerCAmelCase=False			, _lowerCAmelCase=True			, _lowerCAmelCase=False			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										super().__init__(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   hidden_size
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   num_hidden_layers
										__SCREAMING_SNAKE_CASE:				List[Any]           =   num_channels
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   patch_size
										__SCREAMING_SNAKE_CASE:				List[Any]           =   image_size
										__SCREAMING_SNAKE_CASE:				int           =   initializer_factor
										__SCREAMING_SNAKE_CASE:				str           =   layer_norm_eps
										__SCREAMING_SNAKE_CASE:				Dict           =   stop_gradient
										__SCREAMING_SNAKE_CASE:				Dict           =   share_layernorm
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   remove_last_layer






				@classmethod
				def 			snake_case_    (  cls			, _lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE:				Dict           =   cls.get_config_dict(_lowerCAmelCase			, **_lowerCAmelCase					)

										if config_dict.get('''model_type'''					) == "bridgetower":
																__SCREAMING_SNAKE_CASE:				Any           =   config_dict['''text_config''']

										if "model_type" in config_dict and hasattr(cls			, '''model_type'''					) and config_dict["model_type"] != cls.model_type:
																logger.warning(
																    f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
																    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""					)

										return cls.from_dict(_lowerCAmelCase			, **_lowerCAmelCase					)





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   str		      =     '''bridgetower_text_model'''






				def __init__(  self			, _lowerCAmelCase=50265			, _lowerCAmelCase=768			, _lowerCAmelCase=12			, _lowerCAmelCase=12			, _lowerCAmelCase=1			, _lowerCAmelCase=3072			, _lowerCAmelCase="gelu"			, _lowerCAmelCase=0.1			, _lowerCAmelCase=0.1			, _lowerCAmelCase=514			, _lowerCAmelCase=1			, _lowerCAmelCase=1e-05			, _lowerCAmelCase=1			, _lowerCAmelCase=0			, _lowerCAmelCase=2			, _lowerCAmelCase="absolute"			, _lowerCAmelCase=True			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										super().__init__(**_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Dict           =   vocab_size
										__SCREAMING_SNAKE_CASE:				Tuple           =   hidden_size
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   num_hidden_layers
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   num_attention_heads
										__SCREAMING_SNAKE_CASE:				Any           =   hidden_act
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   initializer_factor
										__SCREAMING_SNAKE_CASE:				Any           =   intermediate_size
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   hidden_dropout_prob
										__SCREAMING_SNAKE_CASE:				Tuple           =   attention_probs_dropout_prob
										__SCREAMING_SNAKE_CASE:				Dict           =   max_position_embeddings
										__SCREAMING_SNAKE_CASE:				List[Any]           =   type_vocab_size
										__SCREAMING_SNAKE_CASE:				Any           =   layer_norm_eps
										__SCREAMING_SNAKE_CASE:				str           =   position_embedding_type
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   use_cache
										__SCREAMING_SNAKE_CASE:				List[str]           =   pad_token_id
										__SCREAMING_SNAKE_CASE:				List[str]           =   bos_token_id
										__SCREAMING_SNAKE_CASE:				List[Any]           =   eos_token_id






				@classmethod
				def 			snake_case_    (  cls			, _lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE:				List[str]           =   cls.get_config_dict(_lowerCAmelCase			, **_lowerCAmelCase					)

										if config_dict.get('''model_type'''					) == "bridgetower":
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   config_dict['''text_config''']

										if "model_type" in config_dict and hasattr(cls			, '''model_type'''					) and config_dict["model_type"] != cls.model_type:
																logger.warning(
																    f"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
																    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""					)

										return cls.from_dict(_lowerCAmelCase			, **_lowerCAmelCase					)





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   str		      =     '''bridgetower'''






				def __init__(  self			, _lowerCAmelCase=True			, _lowerCAmelCase="gelu"			, _lowerCAmelCase=768			, _lowerCAmelCase=1			, _lowerCAmelCase=1e-05			, _lowerCAmelCase=False			, _lowerCAmelCase="add"			, _lowerCAmelCase=12			, _lowerCAmelCase=6			, _lowerCAmelCase=False			, _lowerCAmelCase=False			, _lowerCAmelCase=None			, _lowerCAmelCase=None			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   kwargs.pop('''text_config_dict'''			, _lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Dict           =   kwargs.pop('''vision_config_dict'''			, _lowerCAmelCase					)

										super().__init__(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Dict           =   share_cross_modal_transformer_layers
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   hidden_act
										__SCREAMING_SNAKE_CASE:				str           =   hidden_size
										__SCREAMING_SNAKE_CASE:				Any           =   initializer_factor
										__SCREAMING_SNAKE_CASE:				List[Any]           =   layer_norm_eps
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   share_link_tower_layers
										__SCREAMING_SNAKE_CASE:				str           =   link_tower_type
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   num_attention_heads
										__SCREAMING_SNAKE_CASE:				Dict           =   num_hidden_layers
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   tie_word_embeddings
										__SCREAMING_SNAKE_CASE:				str           =   init_layernorm_from_vision_encoder

										if text_config is None:
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   {}
																logger.info('''`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.'''					)

										if vision_config is None:
																__SCREAMING_SNAKE_CASE:				Tuple           =   {}
																logger.info('''`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values.'''					)

										__SCREAMING_SNAKE_CASE:				List[Any]           =   BridgeTowerTextConfig(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   BridgeTowerVisionConfig(**_lowerCAmelCase					)






				@classmethod
				def 			snake_case_    (  cls			, _lowerCAmelCase			, _lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										return cls(text_config=text_config.to_dict()			, vision_config=vision_config.to_dict()			, **_lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   copy.deepcopy(self.__dict__					)
										__SCREAMING_SNAKE_CASE:				int           =   self.text_config.to_dict()
										__SCREAMING_SNAKE_CASE:				Dict           =   self.vision_config.to_dict()
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   self.__class__.model_type
										return output










from ..utils import DummyObject, requires_backends





class 				a			(      metaclass=__lowercase			):
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     ['''torch''', '''scipy''']






				def __init__(  self			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										requires_backends(self			, ['''torch''', '''scipy''']					)






				@classmethod
				def 			snake_case_    (  cls			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										requires_backends(cls			, ['''torch''', '''scipy''']					)






				@classmethod
				def 			snake_case_    (  cls			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




										requires_backends(cls			, ['''torch''', '''scipy''']					)



