


"""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_       							=    threading.Lock()
a_       							=    None

a_       							=    {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

a_       							=    logging.WARNING

a_       							=    True






def      a__ (				)	->	Any:
				_A					  =			os.getenv("TRANSFORMERS_VERBOSITY"     ,			__lowercase   )
				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      a__ (				)	->	str:
				return __name__.split("."   )[0]






def      a__ (				)	->	logging.Logger:
				return logging.getLogger(_get_library_name()   )






def      a__ (				)	->	None:
				global _default_handler

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

								# Apply our default configuration to the library root logger.
								_A					  =			_get_library_root_logger()
								library_root_logger.addHandler(_default_handler   )
								library_root_logger.setLevel(_get_default_logging_level()   )
								_A					  =			False






def      a__ (				)	->	None:
				global _default_handler

				with _lock:
								if not _default_handler:
												return

								_A					  =			_get_library_root_logger()
								library_root_logger.removeHandler(_default_handler   )
								library_root_logger.setLevel(logging.NOTSET   )
								_A					  =			None






def      a__ (				)	->	Any:
				return log_levels






def      a__ (				__lowercase = None   )	->	logging.Logger:

				if name is None:
								_A					  =			_get_library_name()

				_configure_library_root_logger()
				return logging.getLogger(__lowercase   )






def      a__ (				)	->	int:
				_configure_library_root_logger()
				return _get_library_root_logger().getEffectiveLevel()






def      a__ (				__lowercase   )	->	None:
				_configure_library_root_logger()
				_get_library_root_logger().setLevel(__lowercase   )






def      a__ (				)	->	List[Any]:
				return set_verbosity(__lowercase   )






def      a__ (				)	->	Optional[Any]:
				return set_verbosity(__lowercase   )






def      a__ (				)	->	Dict:
				return set_verbosity(__lowercase   )






def      a__ (				)	->	Optional[int]:
				return set_verbosity(__lowercase   )






def      a__ (				)	->	None:
				_configure_library_root_logger()

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






def      a__ (				)	->	None:
				_configure_library_root_logger()

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






def      a__ (				__lowercase   )	->	None:
				_configure_library_root_logger()

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






def      a__ (				__lowercase   )	->	None:
				_configure_library_root_logger()

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






def      a__ (				)	->	None:
				_configure_library_root_logger()
				_A					  =			False






def      a__ (				)	->	None:
				_configure_library_root_logger()
				_A					  =			True






def      a__ (				)	->	None:
				_A					  =			_get_library_root_logger().handlers

				for handler in handlers:
								_A					  =			logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"   )
								handler.setFormatter(__lowercase   )






def      a__ (				)	->	None:
				_A					  =			_get_library_root_logger().handlers

				for handler in handlers:
								handler.setFormatter(__lowercase   )






def      a__ (				self     ,			*__lowercase     ,			**__lowercase   )	->	int:
				_A					  =			os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"     ,			__lowercase   )
				if no_advisory_warnings:
								return
				self.warning(*__lowercase     ,			**__lowercase   )


a_       							=    warning_advice






@functools.lru_cache(__lowercase   )
def      a__ (				self     ,			*__lowercase     ,			**__lowercase   )	->	Union[str, Any]:
				self.warning(*__lowercase     ,			**__lowercase   )


a_       							=    warning_once
class snake_case      :







		def __init__(					self      :       int    ,   *a__      :       Any    ,   **a__      :       int		)       ->						List[str]:  # pylint: disable=unused-argument





						'''simple docstring'''







						_A					  =			args[0] if args else None







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





						'''simple docstring'''







						return iter(self._iterator		)







		def __getattr__(					self      :       List[str]    ,   a__      :       Optional[Any]		)       ->						Dict:





						'''simple docstring'''







						def empty_fn(*a__      :       int    ,   **a__      :       Union[str, Any]		):  # pylint: disable=unused-argument
										return

						return empty_fn







		def __enter__(					self      :       Optional[Any]		)       ->						Dict:





						'''simple docstring'''







						return self







		def __exit__(					self      :       Optional[int]    ,   a__      :       Optional[int]    ,   a__      :       Union[str, Any]    ,   a__      :       int		)       ->						List[str]:





						'''simple docstring'''







						return





class snake_case      :







		def __call__(					self      :       Dict    ,   *a__      :       str    ,   **a__      :       Dict		)       ->						int:





						'''simple docstring'''







						if _tqdm_active:
										return tqdm_lib.tqdm(*a__    ,   **a__		)
						else:
										return EmptyTqdm(*a__    ,   **a__		)







		def  a_ (					self      :       Union[str, Any]    ,   *a__      :       Any    ,   **a__      :       str		)       ->						Tuple:





						'''simple docstring'''







						_A					  =			None
						if _tqdm_active:
										return tqdm_lib.tqdm.set_lock(*a__    ,   **a__		)







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





						'''simple docstring'''







						if _tqdm_active:
										return tqdm_lib.tqdm.get_lock()





a_       							=    _tqdm_cls()






def      a__ (				)	->	bool:
				global _tqdm_active
				return bool(_tqdm_active   )






def      a__ (				)	->	Dict:
				global _tqdm_active
				_A					  =			True
				hf_hub_utils.enable_progress_bars()






def      a__ (				)	->	List[Any]:
				global _tqdm_active
				_A					  =			False
				hf_hub_utils.disable_progress_bars()



"""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_       							=    {
    "Salesforce/blip-vqa-base": "https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json",
    "Salesforce/blip-vqa-capfit-large": (
        "https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json"
    ),
    "Salesforce/blip-image-captioning-base": (
        "https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json"
    ),
    "Salesforce/blip-image-captioning-large": (
        "https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json"
    ),
    "Salesforce/blip-itm-base-coco": "https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json",
    "Salesforce/blip-itm-large-coco": "https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json",
    "Salesforce/blip-itm-base-flikr": "https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json",
    "Salesforce/blip-itm-large-flikr": (
        "https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json"
    ),
}
class snake_case      (  _UpperCamelCase):
		__UpperCamelCase           =			'blip_text_model'







		def __init__(					self      :       int    ,   a__      :       List[str]=3_05_24    ,   a__      :       List[str]=7_68    ,   a__      :       List[Any]=7_68    ,   a__      :       int=30_72    ,   a__      :       List[str]=7_68    ,   a__      :       Dict=12    ,   a__      :       Optional[int]=8    ,   a__      :       Optional[Any]=5_12    ,   a__      :       List[Any]="gelu"    ,   a__      :       Optional[Any]=1E-1_2    ,   a__      :       Any=0.0    ,   a__      :       int=0.0    ,   a__      :       Dict=0.0_2    ,   a__      :       Optional[Any]=3_05_22    ,   a__      :       Any=2    ,   a__      :       int=0    ,   a__      :       Union[str, Any]=1_02    ,   a__      :       Tuple=True    ,   a__      :       Optional[int]=True    ,   **a__      :       Any    ,   )       ->						List[Any]:





						'''simple docstring'''







						super().__init__(
						    pad_token_id=a__    ,   bos_token_id=a__    ,   eos_token_id=a__    ,   sep_token_id=a__    ,   **a__    ,   )

						_A					  =			vocab_size
						_A					  =			hidden_size
						_A					  =			encoder_hidden_size
						_A					  =			intermediate_size
						_A					  =			projection_dim
						_A					  =			hidden_dropout_prob
						_A					  =			num_hidden_layers
						_A					  =			num_attention_heads
						_A					  =			max_position_embeddings
						_A					  =			layer_norm_eps
						_A					  =			hidden_act
						_A					  =			initializer_range
						_A					  =			attention_probs_dropout_prob
						_A					  =			is_decoder
						_A					  =			use_cache







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





						'''simple docstring'''







						cls._set_token_in_kwargs(a__		)

						_A  ,		_A					  =			cls.get_config_dict(a__    ,   **a__		)

						# get the text config dict if we are loading from BlipConfig
						if config_dict.get("model_type"		) == "blip":
										_A					  =			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 snake_case      (  _UpperCamelCase):
		__UpperCamelCase           =			'blip_vision_model'







		def __init__(					self      :       Optional[Any]    ,   a__      :       Any=7_68    ,   a__      :       List[str]=30_72    ,   a__      :       str=5_12    ,   a__      :       Any=12    ,   a__      :       int=12    ,   a__      :       int=3_84    ,   a__      :       Tuple=16    ,   a__      :       str="gelu"    ,   a__      :       Tuple=1E-5    ,   a__      :       List[str]=0.0    ,   a__      :       List[Any]=1E-1_0    ,   **a__      :       int    ,   )       ->						List[str]:





						'''simple docstring'''







						super().__init__(**a__		)

						_A					  =			hidden_size
						_A					  =			intermediate_size
						_A					  =			projection_dim
						_A					  =			num_hidden_layers
						_A					  =			num_attention_heads
						_A					  =			patch_size
						_A					  =			image_size
						_A					  =			initializer_range
						_A					  =			attention_dropout
						_A					  =			layer_norm_eps
						_A					  =			hidden_act







		@classmethod
		def  a_ (					cls      :       Any    ,   a__      :       Union[str, os.PathLike]    ,   **a__      :       int		)       ->						"PretrainedConfig":





						'''simple docstring'''







						cls._set_token_in_kwargs(a__		)

						_A  ,		_A					  =			cls.get_config_dict(a__    ,   **a__		)

						# get the vision config dict if we are loading from BlipConfig
						if config_dict.get("model_type"		) == "blip":
										_A					  =			config_dict["vision_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 snake_case      (  _UpperCamelCase):
		__UpperCamelCase           =			'blip'
		__UpperCamelCase           =			True







		def __init__(					self      :       List[Any]    ,   a__      :       Optional[int]=None    ,   a__      :       str=None    ,   a__      :       List[str]=5_12    ,   a__      :       Any=2.6_5_9_2    ,   a__      :       str=2_56    ,   **a__      :       Optional[int]    ,   )       ->						Dict:





						'''simple docstring'''







						super().__init__(**a__		)

						if text_config is None:
										_A					  =			{}
										logger.info("`text_config` is `None`. Initializing the `BlipTextConfig` with default values."		)

						if vision_config is None:
										_A					  =			{}
										logger.info("`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values."		)

						_A					  =			BlipTextConfig(**a__		)
						_A					  =			BlipVisionConfig(**a__		)

						_A					  =			self.vision_config.hidden_size

						_A					  =			projection_dim
						_A					  =			logit_scale_init_value
						_A					  =			1.0
						_A					  =			0.0_2
						_A					  =			image_text_hidden_size







		@classmethod
		def  a_ (					cls      :       Tuple    ,   a__      :       BlipTextConfig    ,   a__      :       BlipVisionConfig    ,   **a__      :       Optional[int]		)       ->						str:





						'''simple docstring'''







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







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





						'''simple docstring'''







						_A					  =			copy.deepcopy(self.__dict__		)
						_A					  =			self.text_config.to_dict()
						_A					  =			self.vision_config.to_dict()
						_A					  =			self.__class__.model_type
						return output