
"""simple docstring"""

import copy
import os
from typing import Union

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


_A						=			logging.get_logger(__name__)

_A						=			{
    '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       (    __UpperCAmelCase		):
	lowercase_				=     'bridgetower_vision_model'




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




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

			if config_dict.get('model_type' ) == "bridgetower":
					lowerCamelCase					:      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 	_lowercase       (    __UpperCAmelCase		):
	lowercase_				=     'bridgetower_text_model'




	def __init__(			self		,			UpperCAmelCase_=50265		,			UpperCAmelCase_=768		,			UpperCAmelCase_=12		,			UpperCAmelCase_=12		,			UpperCAmelCase_=1		,			UpperCAmelCase_=3072		,			UpperCAmelCase_="gelu"		,			UpperCAmelCase_=0.1		,			UpperCAmelCase_=0.1		,			UpperCAmelCase_=514		,			UpperCAmelCase_=1		,			UpperCAmelCase_=1E-0_5		,			UpperCAmelCase_=1		,			UpperCAmelCase_=0		,			UpperCAmelCase_=2		,			UpperCAmelCase_="absolute"		,			UpperCAmelCase_=True		,			**UpperCAmelCase_		,			)		->							Tuple:
			super().__init__(**UpperCAmelCase_ )

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




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

			if config_dict.get('model_type' ) == "bridgetower":
					lowerCamelCase					:      str          =   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 	_lowercase       (    __UpperCAmelCase		):
	lowercase_				=     'bridgetower'




	def __init__(			self		,			UpperCAmelCase_=True		,			UpperCAmelCase_="gelu"		,			UpperCAmelCase_=768		,			UpperCAmelCase_=1		,			UpperCAmelCase_=1E-0_5		,			UpperCAmelCase_=False		,			UpperCAmelCase_="add"		,			UpperCAmelCase_=12		,			UpperCAmelCase_=6		,			UpperCAmelCase_=False		,			UpperCAmelCase_=False		,			UpperCAmelCase_=None		,			UpperCAmelCase_=None		,			**UpperCAmelCase_		,			)		->							Optional[int]:
			# TODO: remove this once the Hub files are updated.
			lowerCamelCase					:      List[Any]          =   kwargs.pop('text_config_dict'		,			UpperCAmelCase_ )
			lowerCamelCase					:      int          =   kwargs.pop('vision_config_dict'		,			UpperCAmelCase_ )

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

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

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

			lowerCamelCase					:      List[Any]          =   BridgeTowerTextConfig(**UpperCAmelCase_ )
			lowerCamelCase					:      List[Any]          =   BridgeTowerVisionConfig(**UpperCAmelCase_ )




	@classmethod
	def       _UpperCamelCase   (			cls		,			UpperCAmelCase_		,			UpperCAmelCase_		,			**UpperCAmelCase_ )		->							Union[str, Any]:
			return cls(text_config=text_config.to_dict()		,			vision_config=vision_config.to_dict()		,			**UpperCAmelCase_ )




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








"""simple docstring"""

import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
					import ctypes
					import msvcrt  # noqa






					class 	_lowercase       (    ctypes.Structure		):
						# _fields is a specific attr expected by ctypes
						lowercase_				=     [('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def 		UpperCAmelCase (		):





		'''simple docstring'''


		if os.name == "nt":
				lowerCamelCase					:      Optional[int]          =   CursorInfo()
				lowerCamelCase					:      Union[str, Any]          =   ctypes.windll.kernelaa.GetStdHandle(-11      )
				ctypes.windll.kernelaa.GetConsoleCursorInfo(a_,						ctypes.byref(a_      )      )
				lowerCamelCase					:      Dict          =   False
				ctypes.windll.kernelaa.SetConsoleCursorInfo(a_,						ctypes.byref(a_      )      )
		elif os.name == "posix":
				sys.stdout.write('\033[?25l'      )
				sys.stdout.flush()
def 		UpperCAmelCase (		):





		'''simple docstring'''


		if os.name == "nt":
				lowerCamelCase					:      List[str]          =   CursorInfo()
				lowerCamelCase					:      List[Any]          =   ctypes.windll.kernelaa.GetStdHandle(-11      )
				ctypes.windll.kernelaa.GetConsoleCursorInfo(a_,						ctypes.byref(a_      )      )
				lowerCamelCase					:      Optional[Any]          =   True
				ctypes.windll.kernelaa.SetConsoleCursorInfo(a_,						ctypes.byref(a_      )      )
		elif os.name == "posix":
				sys.stdout.write('\033[?25h'      )
				sys.stdout.flush()





@contextmanager
def 		UpperCAmelCase (		):





		'''simple docstring'''


		try:
				hide_cursor()
				yield
		finally:
				show_cursor()






