
import copy
import os
from typing import Union

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


UpperCamelCase_						:     Any	       =							logging.get_logger(__name__)

UpperCamelCase_						:     int	       =							{
    """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   __lowercase						(						__snake_case       ):
	_A       =   "bridgetower_vision_model"






	def __init__(self				: Union[str, Any]      ,	snake_case				: Dict=768      ,	snake_case				: str=12      ,	snake_case				: List[Any]=3      ,	snake_case				: Any=16      ,	snake_case				: Any=288      ,	snake_case				: Any=1      ,	snake_case				: Any=1e-05      ,	snake_case				: str=False      ,	snake_case				: str=True      ,	snake_case				: Optional[int]=False      ,	**snake_case				: List[str]      ,	) ->			int:
							super().__init__(**snake_case    )
							_lowercase       :	List[str]           =   hidden_size
							_lowercase       :	Dict           =   num_hidden_layers
							_lowercase       :	Dict           =   num_channels
							_lowercase       :	Dict           =   patch_size
							_lowercase       :	str           =   image_size
							_lowercase       :	Any           =   initializer_factor
							_lowercase       :	str           =   layer_norm_eps
							_lowercase       :	Tuple           =   stop_gradient
							_lowercase       :	List[str]           =   share_layernorm
							_lowercase       :	List[Any]           =   remove_last_layer






	@classmethod
	def       _a(cls				: Tuple      ,	snake_case				: Union[str, os.PathLike]      ,	**snake_case				: Dict    ) ->			"PretrainedConfig":
							_lowercase      ,    _lowercase       :	str           =   cls.get_config_dict(snake_case      ,	**snake_case    )

							if config_dict.get("model_type"    ) == "bridgetower":
													_lowercase       :	List[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(snake_case      ,	**snake_case    )




class   __lowercase						(						__snake_case       ):
	_A       =   "bridgetower_text_model"






	def __init__(self				: Any      ,	snake_case				: Optional[Any]=5_0265      ,	snake_case				: Tuple=768      ,	snake_case				: Any=12      ,	snake_case				: Dict=12      ,	snake_case				: Dict=1      ,	snake_case				: str=3072      ,	snake_case				: Dict="gelu"      ,	snake_case				: Dict=0.1      ,	snake_case				: List[Any]=0.1      ,	snake_case				: Any=514      ,	snake_case				: Tuple=1      ,	snake_case				: List[Any]=1e-05      ,	snake_case				: Any=1      ,	snake_case				: str=0      ,	snake_case				: Union[str, Any]=2      ,	snake_case				: Optional[Any]="absolute"      ,	snake_case				: Optional[Any]=True      ,	**snake_case				: Any      ,	) ->			Tuple:
							super().__init__(**snake_case    )

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






	@classmethod
	def       _a(cls				: Optional[int]      ,	snake_case				: Union[str, os.PathLike]      ,	**snake_case				: Tuple    ) ->			"PretrainedConfig":
							_lowercase      ,    _lowercase       :	Union[str, Any]           =   cls.get_config_dict(snake_case      ,	**snake_case    )

							if config_dict.get("model_type"    ) == "bridgetower":
													_lowercase       :	Optional[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(snake_case      ,	**snake_case    )




class   __lowercase						(						__snake_case       ):
	_A       =   "bridgetower"






	def __init__(self				: Optional[int]      ,	snake_case				: Union[str, Any]=True      ,	snake_case				: int="gelu"      ,	snake_case				: List[Any]=768      ,	snake_case				: Optional[Any]=1      ,	snake_case				: List[Any]=1e-05      ,	snake_case				: List[str]=False      ,	snake_case				: Optional[int]="add"      ,	snake_case				: str=12      ,	snake_case				: Any=6      ,	snake_case				: str=False      ,	snake_case				: Tuple=False      ,	snake_case				: List[Any]=None      ,	snake_case				: List[Any]=None      ,	**snake_case				: Dict      ,	) ->			Optional[int]:
							# TODO: remove this once the Hub files are updated.
							_lowercase       :	List[Any]           =   kwargs.pop("text_config_dict"      ,	snake_case    )
							_lowercase       :	Dict           =   kwargs.pop("vision_config_dict"      ,	snake_case    )

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

							if text_config is None:
													_lowercase       :	Optional[Any]           =   {}
													logger.info("`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values."    )

							if vision_config is None:
													_lowercase       :	List[str]           =   {}
													logger.info("`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values."    )

							_lowercase       :	int           =   BridgeTowerTextConfig(**snake_case    )
							_lowercase       :	str           =   BridgeTowerVisionConfig(**snake_case    )






	@classmethod
	def       _a(cls				: str      ,	snake_case				: BridgeTowerTextConfig      ,	snake_case				: BridgeTowerVisionConfig      ,	**snake_case				: Any    ) ->			Dict:
							return cls(text_config=text_config.to_dict()      ,	vision_config=vision_config.to_dict()      ,	**snake_case    )






	def       _a(self				: Tuple    ) ->			List[Any]:
							_lowercase       :	Optional[Any]           =   copy.deepcopy(self.__dict__    )
							_lowercase       :	List[Any]           =   self.text_config.to_dict()
							_lowercase       :	List[str]           =   self.vision_config.to_dict()
							_lowercase       :	Tuple           =   self.__class__.model_type
							return output






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


UpperCamelCase_						:     Optional[int]	       =							logging.get_logger(__name__)




class   __lowercase						(						__snake_case       ):
	_A       =   "timm_backbone"






	def __init__(self				: Any      ,	snake_case				: List[Any]=None      ,	snake_case				: int=3      ,	snake_case				: Dict=True      ,	snake_case				: Union[str, Any]=True      ,	snake_case				: Any=None      ,	**snake_case				: int      ,	) ->			Optional[int]:
							super().__init__(**snake_case    )
							_lowercase       :	Dict           =   backbone
							_lowercase       :	Optional[Any]           =   num_channels
							_lowercase       :	Union[str, Any]           =   features_only
							_lowercase       :	Tuple           =   use_pretrained_backbone
							_lowercase       :	List[str]           =   True
							_lowercase       :	Tuple           =   out_indices if out_indices is not None else (-1,)




