






import copy
import os
from typing import Union

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


UpperCamelCase			    =     logging.get_logger(__name__)

UpperCamelCase			    =     {
    '''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 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Optional[Any]									=							"bridgetower_vision_model"







			def __init__(     self:  str				,     UpperCAmelCase_:  Dict=768				,     UpperCAmelCase_:  Tuple=12				,     UpperCAmelCase_:  Optional[int]=3				,     UpperCAmelCase_:  Dict=16				,     UpperCAmelCase_:  Tuple=288				,     UpperCAmelCase_:  List[str]=1				,     UpperCAmelCase_:  Dict=1E-05				,     UpperCAmelCase_:  Optional[int]=False				,     UpperCAmelCase_:  Optional[int]=True				,     UpperCAmelCase_:  str=False				,     **UpperCAmelCase_:  List[str]				,     ) ->    str:







									'''simple docstring'''




									super().__init__(**UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  hidden_size
									_SCREAMING_SNAKE_CASE     				=  num_hidden_layers
									_SCREAMING_SNAKE_CASE     				=  num_channels
									_SCREAMING_SNAKE_CASE     				=  patch_size
									_SCREAMING_SNAKE_CASE     				=  image_size
									_SCREAMING_SNAKE_CASE     				=  initializer_factor
									_SCREAMING_SNAKE_CASE     				=  layer_norm_eps
									_SCREAMING_SNAKE_CASE     				=  stop_gradient
									_SCREAMING_SNAKE_CASE     				=  share_layernorm
									_SCREAMING_SNAKE_CASE     				=  remove_last_layer







			@classmethod
			def 							UpperCamelCase				(     cls:  Any				,     UpperCAmelCase_:  Union[str, os.PathLike]				,     **UpperCAmelCase_:  Tuple					) ->    Optional[int]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE				,					_SCREAMING_SNAKE_CASE     				=  cls.get_config_dict(UpperCAmelCase_				,     **UpperCAmelCase_					)

									if config_dict.get("""model_type"""					) == "bridgetower":
															_SCREAMING_SNAKE_CASE     				=  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(UpperCAmelCase_				,     **UpperCAmelCase_					)



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Optional[int]									=							"bridgetower_text_model"







			def __init__(     self:  int				,     UpperCAmelCase_:  Optional[int]=50_265				,     UpperCAmelCase_:  Optional[int]=768				,     UpperCAmelCase_:  Tuple=12				,     UpperCAmelCase_:  Tuple=12				,     UpperCAmelCase_:  str=1				,     UpperCAmelCase_:  List[str]=3_072				,     UpperCAmelCase_:  Union[str, Any]="gelu"				,     UpperCAmelCase_:  Dict=0.1				,     UpperCAmelCase_:  Any=0.1				,     UpperCAmelCase_:  Dict=514				,     UpperCAmelCase_:  Optional[int]=1				,     UpperCAmelCase_:  List[str]=1E-05				,     UpperCAmelCase_:  Any=1				,     UpperCAmelCase_:  List[Any]=0				,     UpperCAmelCase_:  Tuple=2				,     UpperCAmelCase_:  Dict="absolute"				,     UpperCAmelCase_:  Optional[Any]=True				,     **UpperCAmelCase_:  Union[str, Any]				,     ) ->    Tuple:







									'''simple docstring'''




									super().__init__(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  vocab_size
									_SCREAMING_SNAKE_CASE     				=  hidden_size
									_SCREAMING_SNAKE_CASE     				=  num_hidden_layers
									_SCREAMING_SNAKE_CASE     				=  num_attention_heads
									_SCREAMING_SNAKE_CASE     				=  hidden_act
									_SCREAMING_SNAKE_CASE     				=  initializer_factor
									_SCREAMING_SNAKE_CASE     				=  intermediate_size
									_SCREAMING_SNAKE_CASE     				=  hidden_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  attention_probs_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  max_position_embeddings
									_SCREAMING_SNAKE_CASE     				=  type_vocab_size
									_SCREAMING_SNAKE_CASE     				=  layer_norm_eps
									_SCREAMING_SNAKE_CASE     				=  position_embedding_type
									_SCREAMING_SNAKE_CASE     				=  use_cache
									_SCREAMING_SNAKE_CASE     				=  pad_token_id
									_SCREAMING_SNAKE_CASE     				=  bos_token_id
									_SCREAMING_SNAKE_CASE     				=  eos_token_id







			@classmethod
			def 							UpperCamelCase				(     cls:  Tuple				,     UpperCAmelCase_:  Union[str, os.PathLike]				,     **UpperCAmelCase_:  Dict					) ->    List[Any]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE				,					_SCREAMING_SNAKE_CASE     				=  cls.get_config_dict(UpperCAmelCase_				,     **UpperCAmelCase_					)

									if config_dict.get("""model_type"""					) == "bridgetower":
															_SCREAMING_SNAKE_CASE     				=  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(UpperCAmelCase_				,     **UpperCAmelCase_					)



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Optional[Any]									=							"bridgetower"







			def __init__(     self:  Dict				,     UpperCAmelCase_:  Optional[Any]=True				,     UpperCAmelCase_:  Optional[int]="gelu"				,     UpperCAmelCase_:  Union[str, Any]=768				,     UpperCAmelCase_:  Optional[int]=1				,     UpperCAmelCase_:  Optional[Any]=1E-05				,     UpperCAmelCase_:  Dict=False				,     UpperCAmelCase_:  List[Any]="add"				,     UpperCAmelCase_:  List[Any]=12				,     UpperCAmelCase_:  int=6				,     UpperCAmelCase_:  str=False				,     UpperCAmelCase_:  Tuple=False				,     UpperCAmelCase_:  List[str]=None				,     UpperCAmelCase_:  Any=None				,     **UpperCAmelCase_:  Optional[Any]				,     ) ->    Tuple:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  kwargs.pop("""text_config_dict"""				,     UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  kwargs.pop("""vision_config_dict"""				,     UpperCAmelCase_					)

									super().__init__(**UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  share_cross_modal_transformer_layers
									_SCREAMING_SNAKE_CASE     				=  hidden_act
									_SCREAMING_SNAKE_CASE     				=  hidden_size
									_SCREAMING_SNAKE_CASE     				=  initializer_factor
									_SCREAMING_SNAKE_CASE     				=  layer_norm_eps
									_SCREAMING_SNAKE_CASE     				=  share_link_tower_layers
									_SCREAMING_SNAKE_CASE     				=  link_tower_type
									_SCREAMING_SNAKE_CASE     				=  num_attention_heads
									_SCREAMING_SNAKE_CASE     				=  num_hidden_layers
									_SCREAMING_SNAKE_CASE     				=  tie_word_embeddings
									_SCREAMING_SNAKE_CASE     				=  init_layernorm_from_vision_encoder

									if text_config is None:
															_SCREAMING_SNAKE_CASE     				=  {}
															logger.info("""`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values."""					)

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

									_SCREAMING_SNAKE_CASE     				=  BridgeTowerTextConfig(**UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  BridgeTowerVisionConfig(**UpperCAmelCase_					)







			@classmethod
			def 							UpperCamelCase				(     cls:  int				,     UpperCAmelCase_:  BridgeTowerTextConfig				,     UpperCAmelCase_:  BridgeTowerVisionConfig				,     **UpperCAmelCase_:  List[str]					) ->    List[Any]:







									'''simple docstring'''




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







			def 							UpperCamelCase				(     self:  Optional[int]					) ->    str:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  copy.deepcopy(self.__dict__					)
									_SCREAMING_SNAKE_CASE     				=  self.text_config.to_dict()
									_SCREAMING_SNAKE_CASE     				=  self.vision_config.to_dict()
									_SCREAMING_SNAKE_CASE     				=  self.__class__.model_type
									return output









from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCamelCase			    =     {'''configuration_mmbt''': ['''MMBTConfig''']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCamelCase			    =     ['''MMBTForClassification''', '''MMBTModel''', '''ModalEmbeddings''']


if TYPE_CHECKING:
		from .configuration_mmbt import MMBTConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
		import sys

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

