
"""simple docstring"""




import copy
import os
from typing import Union

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


A__ :       Union[str, Any]				= logging.get_logger(__name__)

A__ :       List[str]				= {
    '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       __magic_name__							(							SCREAMING_SNAKE_CASE__			):
       UpperCamelCase_ =		'''bridgetower_vision_model'''
       def __init__(  self			,					A_=768			,					A_=12			,					A_=3			,					A_=16			,					A_=288			,					A_=1			,					A_=1E-05			,					A_=False			,					A_=True			,					A_=False			,					**A_			,					)  ->						Optional[Any]:





         """simple docstring"""




         super().__init__(**A_							)
         _lowercase:      Any   			=  hidden_size
         _lowercase:      Any   			=  num_hidden_layers
         _lowercase:      Any   			=  num_channels
         _lowercase:      str   			=  patch_size
         _lowercase:      int   			=  image_size
         _lowercase:      Optional[int]   			=  initializer_factor
         _lowercase:      Dict   			=  layer_norm_eps
         _lowercase:      Optional[int]   			=  stop_gradient
         _lowercase:      List[Any]   			=  share_layernorm
         _lowercase:      int   			=  remove_last_layer



       @classmethod
       def 				lowercase_				(  cls			,					A_			,					**A_							)  ->						"PretrainedConfig":





         """simple docstring"""




         _lowercase			,					_lowercase:      Any   			=  cls.get_config_dict(A_			,					**A_							)

         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(A_			,					**A_							)


class       __magic_name__							(							SCREAMING_SNAKE_CASE__			):
       UpperCamelCase_ =		'''bridgetower_text_model'''
       def __init__(  self			,					A_=5_0265			,					A_=768			,					A_=12			,					A_=12			,					A_=1			,					A_=3072			,					A_="gelu"			,					A_=0.1			,					A_=0.1			,					A_=514			,					A_=1			,					A_=1E-05			,					A_=1			,					A_=0			,					A_=2			,					A_="absolute"			,					A_=True			,					**A_			,					)  ->						List[Any]:





         """simple docstring"""




         super().__init__(**A_							)

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



       @classmethod
       def 				lowercase_				(  cls			,					A_			,					**A_							)  ->						"PretrainedConfig":





         """simple docstring"""




         _lowercase			,					_lowercase:      Optional[int]   			=  cls.get_config_dict(A_			,					**A_							)

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


class       __magic_name__							(							SCREAMING_SNAKE_CASE__			):
       UpperCamelCase_ =		'''bridgetower'''
       def __init__(  self			,					A_=True			,					A_="gelu"			,					A_=768			,					A_=1			,					A_=1E-05			,					A_=False			,					A_="add"			,					A_=12			,					A_=6			,					A_=False			,					A_=False			,					A_=None			,					A_=None			,					**A_			,					)  ->						List[Any]:





         """simple docstring"""




         _lowercase:      List[Any]   			=  kwargs.pop('''text_config_dict'''			,					A_							)
         _lowercase:      str   			=  kwargs.pop('''vision_config_dict'''			,					A_							)

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

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

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

         _lowercase:      Optional[int]   			=  BridgeTowerTextConfig(**A_							)
         _lowercase:      str   			=  BridgeTowerVisionConfig(**A_							)
       @classmethod
       def 				lowercase_				(  cls			,					A_			,					A_			,					**A_							)  ->						Optional[Any]:





         """simple docstring"""




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



       def 				lowercase_				(  self							)  ->						Union[str, Any]:





         """simple docstring"""




         _lowercase:      Union[str, Any]   			=  copy.deepcopy(self.__dict__							)
         _lowercase:      Union[str, Any]   			=  self.text_config.to_dict()
         _lowercase:      Optional[int]   			=  self.vision_config.to_dict()
         _lowercase:      List[str]   			=  self.__class__.model_type
         return output


"""simple docstring"""




import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


A__ :       int				= threading.Lock()
A__ :       Optional[logging.Handler]				= None

A__ :       str				= {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

A__ :       str				= logging.WARNING

A__ :       Union[str, Any]				= True




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _lowercase:      List[Any]   			=  os.getenv('''TRANSFORMERS_VERBOSITY'''			,					_UpperCamelCase    )
  if env_level_str:
    if env_level_str in log_levels:
      return log_levels[env_level_str]
    else:
      logging.getLogger().warning(
          f'''Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '''
          f'''has to be one of: { ", ".join(log_levels.keys()    ) }'''    )
  return _default_log_level




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return __name__.split('''.'''    )[0]




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return logging.getLogger(_get_library_name()    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  global _default_handler

  with _lock:
    if _default_handler:
      # This library has already configured the library root logger.
      return
    _lowercase:      int   			=  logging.StreamHandler()  # Set sys.stderr as stream.
    _lowercase:      Dict   			=  sys.stderr.flush

    # Apply our default configuration to the library root logger.
    _lowercase:      Dict   			=  _get_library_root_logger()
    library_root_logger.addHandler(_default_handler    )
    library_root_logger.setLevel(_get_default_logging_level()    )
    _lowercase:      Optional[Any]   			=  False




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  global _default_handler

  with _lock:
    if not _default_handler:
      return

    _lowercase:      Tuple   			=  _get_library_root_logger()
    library_root_logger.removeHandler(_default_handler    )
    library_root_logger.setLevel(logging.NOTSET    )
    _lowercase:      Dict   			=  None




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return log_levels




def 			_lowerCAmelCase		(		_UpperCamelCase = None    ):






  """simple docstring"""



  if name is None:
    _lowercase:      Tuple   			=  _get_library_name()

  _configure_library_root_logger()
  return logging.getLogger(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _configure_library_root_logger()
  return _get_library_root_logger().getEffectiveLevel()




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



  _configure_library_root_logger()
  _get_library_root_logger().setLevel(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return set_verbosity(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return set_verbosity(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return set_verbosity(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  return set_verbosity(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().removeHandler(_default_handler    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().addHandler(_default_handler    )




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



  _configure_library_root_logger()

  assert handler is not None
  _get_library_root_logger().addHandler(_UpperCamelCase    )




def 			_lowerCAmelCase		(		_UpperCamelCase    ):






  """simple docstring"""



  _configure_library_root_logger()

  assert handler is not None and handler not in _get_library_root_logger().handlers
  _get_library_root_logger().removeHandler(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _configure_library_root_logger()
  _lowercase:      str   			=  False




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _configure_library_root_logger()
  _lowercase:      List[str]   			=  True




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _lowercase:      Any   			=  _get_library_root_logger().handlers

  for handler in handlers:
    _lowercase:      int   			=  logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''    )
    handler.setFormatter(_UpperCamelCase    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  _lowercase:      List[str]   			=  _get_library_root_logger().handlers

  for handler in handlers:
    handler.setFormatter(_UpperCamelCase    )




def 			_lowerCAmelCase		(		self			,					*_UpperCamelCase			,					**_UpperCamelCase    ):






  """simple docstring"""



  _lowercase:      Any   			=  os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''			,					_UpperCamelCase    )
  if no_advisory_warnings:
    return
  self.warning(*_UpperCamelCase			,					**_UpperCamelCase    )


A__ :       Optional[int]				= warning_advice




@functools.lru_cache(_UpperCamelCase    )
def 			_lowerCAmelCase		(		self			,					*_UpperCamelCase			,					**_UpperCamelCase    ):






  """simple docstring"""



  self.warning(*_UpperCamelCase			,					**_UpperCamelCase    )


A__ :       List[Any]				= warning_once


class       __magic_name__							:
       def __init__(  self			,					*A_			,					**A_							)  ->						Any:  # pylint: disable=unused-argument





         """simple docstring"""




         _lowercase:      Tuple   			=  args[0] if args else None
       def __iter__(  self							)  ->						Union[str, Any]:





         """simple docstring"""




         return iter(self._iterator							)
       def __getattr__(  self			,					A_							)  ->						List[Any]:





         """simple docstring"""




         def empty_fn(*A_			,					**A_							):  # pylint: disable=unused-argument
           return

         return empty_fn
       def __enter__(  self							)  ->						Tuple:





         """simple docstring"""




         return self



       def __exit__(  self			,					A_			,					A_			,					A_							)  ->						Optional[Any]:





         """simple docstring"""




         return


class       __magic_name__							:
       def __call__(  self			,					*A_			,					**A_							)  ->						Dict:





         """simple docstring"""




         if _tqdm_active:
           return tqdm_lib.tqdm(*A_			,					**A_							)
         else:
           return EmptyTqdm(*A_			,					**A_							)
       def 				lowercase_				(  self			,					*A_			,					**A_							)  ->						List[str]:





         """simple docstring"""




         _lowercase:      Optional[Any]   			=  None
         if _tqdm_active:
           return tqdm_lib.tqdm.set_lock(*A_			,					**A_							)



       def 				lowercase_				(  self							)  ->						Optional[Any]:





         """simple docstring"""




         if _tqdm_active:
           return tqdm_lib.tqdm.get_lock()

A__ :       str				= _tqdm_cls()




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  global _tqdm_active
  return bool(_tqdm_active    )




def 			_lowerCAmelCase		(		):






  """simple docstring"""



  global _tqdm_active
  _lowercase:      str   			=  True
  hf_hub_utils.enable_progress_bars()







def 			_lowerCAmelCase		(		):






  """simple docstring"""



  global _tqdm_active
  _lowercase:      Union[str, Any]   			=  False
  hf_hub_utils.disable_progress_bars()
