






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   lowerCamelCase				(_snake_case      ):







		'''simple docstring'''



		_snake_case   :   List[str]							=  '''bridgetower_vision_model'''



		def __init__(							self    ,		_UpperCamelCase=7_6_8    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=3    ,		_UpperCamelCase=1_6    ,		_UpperCamelCase=2_8_8    ,		_UpperCamelCase=1    ,		_UpperCamelCase=1E-05    ,		_UpperCamelCase=False    ,		_UpperCamelCase=True    ,		_UpperCamelCase=False    ,		**_UpperCamelCase    ,		)     ->							Optional[int]:
							super().__init__(**_UpperCamelCase       )
							UpperCAmelCase_   :				Union[str, Any]						=						hidden_size
							UpperCAmelCase_   :				int						=						num_hidden_layers
							UpperCAmelCase_   :				List[Any]						=						num_channels
							UpperCAmelCase_   :				str						=						patch_size
							UpperCAmelCase_   :				Tuple						=						image_size
							UpperCAmelCase_   :				str						=						initializer_factor
							UpperCAmelCase_   :				int						=						layer_norm_eps
							UpperCAmelCase_   :				Tuple						=						stop_gradient
							UpperCAmelCase_   :				Union[str, Any]						=						share_layernorm
							UpperCAmelCase_   :				Any						=						remove_last_layer



		@classmethod
		def  __UpperCAmelCase      (							cls    ,		_UpperCamelCase    ,		**_UpperCamelCase       )     ->							"PretrainedConfig":
							UpperCAmelCase_	,  UpperCAmelCase_   :				Optional[Any]						=						cls.get_config_dict(_UpperCamelCase    ,		**_UpperCamelCase       )

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





class   lowerCamelCase				(_snake_case      ):







		'''simple docstring'''



		_snake_case   :   Any							=  '''bridgetower_text_model'''



		def __init__(							self    ,		_UpperCamelCase=5_0_2_6_5    ,		_UpperCamelCase=7_6_8    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=1    ,		_UpperCamelCase=3_0_7_2    ,		_UpperCamelCase="gelu"    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=5_1_4    ,		_UpperCamelCase=1    ,		_UpperCamelCase=1E-05    ,		_UpperCamelCase=1    ,		_UpperCamelCase=0    ,		_UpperCamelCase=2    ,		_UpperCamelCase="absolute"    ,		_UpperCamelCase=True    ,		**_UpperCamelCase    ,		)     ->							Optional[int]:
							super().__init__(**_UpperCamelCase       )

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



		@classmethod
		def  __UpperCAmelCase      (							cls    ,		_UpperCamelCase    ,		**_UpperCamelCase       )     ->							"PretrainedConfig":
							UpperCAmelCase_	,  UpperCAmelCase_   :				List[Any]						=						cls.get_config_dict(_UpperCamelCase    ,		**_UpperCamelCase       )

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





class   lowerCamelCase				(_snake_case      ):







		'''simple docstring'''



		_snake_case   :   str							=  '''bridgetower'''



		def __init__(							self    ,		_UpperCamelCase=True    ,		_UpperCamelCase="gelu"    ,		_UpperCamelCase=7_6_8    ,		_UpperCamelCase=1    ,		_UpperCamelCase=1E-05    ,		_UpperCamelCase=False    ,		_UpperCamelCase="add"    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=6    ,		_UpperCamelCase=False    ,		_UpperCamelCase=False    ,		_UpperCamelCase=None    ,		_UpperCamelCase=None    ,		**_UpperCamelCase    ,		)     ->							Union[str, Any]:
							# TODO: remove this once the Hub files are updated.
							UpperCAmelCase_   :				Dict						=						kwargs.pop('text_config_dict'    ,		_UpperCamelCase       )
							UpperCAmelCase_   :				Union[str, Any]						=						kwargs.pop('vision_config_dict'    ,		_UpperCamelCase       )

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

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

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

							UpperCAmelCase_   :				Any						=						BridgeTowerTextConfig(**_UpperCamelCase       )
							UpperCAmelCase_   :				Any						=						BridgeTowerVisionConfig(**_UpperCamelCase       )



		@classmethod
		def  __UpperCAmelCase      (							cls    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		**_UpperCamelCase       )     ->							int:
							return cls(text_config=text_config.to_dict()    ,		vision_config=vision_config.to_dict()    ,		**_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							Optional[Any]:
							UpperCAmelCase_   :				Union[str, Any]						=						copy.deepcopy(self.__dict__       )
							UpperCAmelCase_   :				Any						=						self.text_config.to_dict()
							UpperCAmelCase_   :				Union[str, Any]						=						self.vision_config.to_dict()
							UpperCAmelCase_   :				Any						=						self.__class__.model_type
							return output














def 					lowercase__				(					__snake_case   :							str					,	__snake_case   :							int					,	__snake_case   :							List[str]  ):


					'''simple docstring'''


					if n == 0:
										return 1

					elif n % 2 == 1:
										return (binary_exponentiation(__snake_case					,	n - 1					,	__snake_case  ) * a) % mod

					else:
										UpperCAmelCase_   :				Optional[int]						=						binary_exponentiation(__snake_case					,	n / 2					,	__snake_case  )
										return (b * b) % mod


# a prime number
__UpperCAmelCase     							=						701

__UpperCAmelCase     							=						1000000000
__UpperCAmelCase     							=						10

# using binary exponentiation function, O(log(p)):
print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p)






print((a / b) % p == (a * b ** (p - 2)) % p)






