


import copy
import os
from typing import Union

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


UpperCAmelCase_   :				str						      = logging.get_logger(__name__)

UpperCAmelCase_   :				List[Any]						      = {
    '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 				SCREAMING_SNAKE_CASE__						(       lowercase__    ):
      snake_case__       :  Union[str, Any]       =		'''bridgetower_vision_model'''
      def __init__( self       : Optional[Any]  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=7_6_8  ,							SCREAMING_SNAKE_CASE__       : Tuple=1_2  ,							SCREAMING_SNAKE_CASE__       : List[Any]=3  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=1_6  ,							SCREAMING_SNAKE_CASE__       : List[Any]=2_8_8  ,							SCREAMING_SNAKE_CASE__       : str=1  ,							SCREAMING_SNAKE_CASE__       : str=1E-05  ,							SCREAMING_SNAKE_CASE__       : Dict=False  ,							SCREAMING_SNAKE_CASE__       : Any=True  ,							SCREAMING_SNAKE_CASE__       : List[Any]=False  ,							**SCREAMING_SNAKE_CASE__       : str  ,							)	->    List[Any]:
             super().__init__(**SCREAMING_SNAKE_CASE__  )
             a_      :	Any							=						hidden_size
             a_      :	str							=						num_hidden_layers
             a_      :	Tuple							=						num_channels
             a_      :	int							=						patch_size
             a_      :	Optional[Any]							=						image_size
             a_      :	Optional[int]							=						initializer_factor
             a_      :	Any							=						layer_norm_eps
             a_      :	Tuple							=						stop_gradient
             a_      :	List[Any]							=						share_layernorm
             a_      :	str							=						remove_last_layer

      @classmethod
      def  SCREAMING_SNAKE_CASE							( cls       : str  ,							SCREAMING_SNAKE_CASE__       : Union[str, os.PathLike]  ,							**SCREAMING_SNAKE_CASE__       : Union[str, Any]  )	->    "PretrainedConfig":
             a_      :	Tuple							=						cls.get_config_dict(SCREAMING_SNAKE_CASE__  ,							**SCREAMING_SNAKE_CASE__  )

             if config_dict.get('model_type'  ) == "bridgetower":
                    a_      :	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(SCREAMING_SNAKE_CASE__  ,							**SCREAMING_SNAKE_CASE__  )
class 				SCREAMING_SNAKE_CASE__						(       lowercase__    ):
      snake_case__       :  Tuple       =		'''bridgetower_text_model'''
      def __init__( self       : Optional[Any]  ,							SCREAMING_SNAKE_CASE__       : Dict=5_0_2_6_5  ,							SCREAMING_SNAKE_CASE__       : Tuple=7_6_8  ,							SCREAMING_SNAKE_CASE__       : Tuple=1_2  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=1_2  ,							SCREAMING_SNAKE_CASE__       : Tuple=1  ,							SCREAMING_SNAKE_CASE__       : int=3_0_7_2  ,							SCREAMING_SNAKE_CASE__       : Tuple="gelu"  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=0.1  ,							SCREAMING_SNAKE_CASE__       : Tuple=0.1  ,							SCREAMING_SNAKE_CASE__       : List[Any]=5_1_4  ,							SCREAMING_SNAKE_CASE__       : str=1  ,							SCREAMING_SNAKE_CASE__       : Any=1E-05  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=1  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=0  ,							SCREAMING_SNAKE_CASE__       : List[Any]=2  ,							SCREAMING_SNAKE_CASE__       : Dict="absolute"  ,							SCREAMING_SNAKE_CASE__       : Dict=True  ,							**SCREAMING_SNAKE_CASE__       : Dict  ,							)	->    List[Any]:
             super().__init__(**SCREAMING_SNAKE_CASE__  )

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

      @classmethod
      def  SCREAMING_SNAKE_CASE							( cls       : Any  ,							SCREAMING_SNAKE_CASE__       : Union[str, os.PathLike]  ,							**SCREAMING_SNAKE_CASE__       : Optional[Any]  )	->    "PretrainedConfig":
             a_      :	Union[str, Any]							=						cls.get_config_dict(SCREAMING_SNAKE_CASE__  ,							**SCREAMING_SNAKE_CASE__  )

             if config_dict.get('model_type'  ) == "bridgetower":
                    a_      :	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(SCREAMING_SNAKE_CASE__  ,							**SCREAMING_SNAKE_CASE__  )
class 				SCREAMING_SNAKE_CASE__						(       lowercase__    ):
      snake_case__       :  Union[str, Any]       =		'''bridgetower'''
      def __init__( self       : Any  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=True  ,							SCREAMING_SNAKE_CASE__       : int="gelu"  ,							SCREAMING_SNAKE_CASE__       : List[str]=7_6_8  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=1  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=1E-05  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=False  ,							SCREAMING_SNAKE_CASE__       : Any="add"  ,							SCREAMING_SNAKE_CASE__       : Any=1_2  ,							SCREAMING_SNAKE_CASE__       : Tuple=6  ,							SCREAMING_SNAKE_CASE__       : Any=False  ,							SCREAMING_SNAKE_CASE__       : int=False  ,							SCREAMING_SNAKE_CASE__       : List[str]=None  ,							SCREAMING_SNAKE_CASE__       : Dict=None  ,							**SCREAMING_SNAKE_CASE__       : Optional[Any]  ,							)	->    Optional[Any]:
             # TODO: remove this once the Hub files are updated.
             a_      :	Tuple							=						kwargs.pop('text_config_dict'  ,							SCREAMING_SNAKE_CASE__  )
             a_      :	str							=						kwargs.pop('vision_config_dict'  ,							SCREAMING_SNAKE_CASE__  )

             super().__init__(**SCREAMING_SNAKE_CASE__  )
             a_      :	Dict							=						share_cross_modal_transformer_layers
             a_      :	List[str]							=						hidden_act
             a_      :	int							=						hidden_size
             a_      :	List[Any]							=						initializer_factor
             a_      :	int							=						layer_norm_eps
             a_      :	str							=						share_link_tower_layers
             a_      :	Optional[Any]							=						link_tower_type
             a_      :	Optional[int]							=						num_attention_heads
             a_      :	List[Any]							=						num_hidden_layers
             a_      :	Tuple							=						tie_word_embeddings
             a_      :	Dict							=						init_layernorm_from_vision_encoder

             if text_config is None:
                    a_      :	Union[str, Any]							=						{}
                    logger.info('`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values.'  )

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

             a_      :	Dict							=						BridgeTowerTextConfig(**SCREAMING_SNAKE_CASE__  )
             a_      :	List[str]							=						BridgeTowerVisionConfig(**SCREAMING_SNAKE_CASE__  )
      @classmethod
      def  SCREAMING_SNAKE_CASE							( cls       : int  ,							SCREAMING_SNAKE_CASE__       : BridgeTowerTextConfig  ,							SCREAMING_SNAKE_CASE__       : BridgeTowerVisionConfig  ,							**SCREAMING_SNAKE_CASE__       : Optional[Any]  )	->    Dict:
             return cls(text_config=text_config.to_dict()  ,							vision_config=vision_config.to_dict()  ,							**SCREAMING_SNAKE_CASE__  )

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






UpperCAmelCase_   :				Optional[int]						      = '\n# Transformers installation\n! pip install transformers datasets\n# To install from source instead of the last release, comment the command above and uncomment the following one.\n# ! pip install git+https://github.com/huggingface/transformers.git\n'

UpperCAmelCase_   :				List[str]						      = [{'type': 'code', 'content': INSTALL_CONTENT}]
UpperCAmelCase_   :				int						      = {
    '{processor_class}': 'FakeProcessorClass',
    '{model_class}': 'FakeModelClass',
    '{object_class}': 'FakeObjectClass',
}


