
import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
				from ... import PreTrainedTokenizerBase, TensorType

snake_case					:						Any				 =    logging.get_logger(__name__)





class  _snake_case   (	a_							):
			UpperCamelCase__        =       'vision-encoder-decoder'
			UpperCamelCase__        =       True







			def __init__(							self		,  **_a						):
				super().__init__(**__SCREAMING_SNAKE_CASE						)
				if "encoder" not in kwargs or "decoder" not in kwargs:
					raise ValueError(
					    f'''A configuraton of type {self.model_type} cannot be instantiated because '''
					    f'''not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}'''						)

				__magic_name__						:						Optional[int]        =	kwargs.pop("encoder"						)
				__magic_name__						:						List[str]        =	encoder_config.pop("model_type"						)
				__magic_name__						:						Tuple        =	kwargs.pop("decoder"						)
				__magic_name__						:						Union[str, Any]        =	decoder_config.pop("model_type"						)

				__magic_name__						:						List[str]        =	AutoConfig.for_model(__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						Union[str, Any]        =	AutoConfig.for_model(__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						List[str]        =	True







			@classmethod
			def      SCREAMING_SNAKE_CASE       (							cls		,  _a		,  _a		,  **_a						):
				logger.info("Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"						)
				__magic_name__						:						str        =	True
				__magic_name__						:						List[str]        =	True

				return cls(encoder=encoder_config.to_dict()		,  decoder=decoder_config.to_dict()		,  **__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self						):
				__magic_name__						:						List[Any]        =	copy.deepcopy(self.__dict__						)
				__magic_name__						:						Tuple        =	self.encoder.to_dict()
				__magic_name__						:						Optional[int]        =	self.decoder.to_dict()
				__magic_name__						:						List[Any]        =	self.__class__.model_type
				return output







class  _snake_case   (	a_							):
			UpperCamelCase__        =       version.parse('1.11'							)







			@property
			def      SCREAMING_SNAKE_CASE       (							self						):
				return OrderedDict(
				    [
				        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
				    ]						)







			@property
			def      SCREAMING_SNAKE_CASE       (							self						):
				return 1e-4







			@property
			def      SCREAMING_SNAKE_CASE       (							self						):
				return OrderedDict({"last_hidden_state": {0: "batch", 1: "encoder_sequence"}}						)







class  _snake_case   (	a_							):







			@property
			def      SCREAMING_SNAKE_CASE       (							self						):
				__magic_name__						:						Optional[Any]        =	OrderedDict()
				__magic_name__						:						str        =	{0: "batch", 1: "past_decoder_sequence + sequence"}
				__magic_name__						:						Optional[int]        =	{0: "batch", 1: "past_decoder_sequence + sequence"}
				__magic_name__						:						List[str]        =	{0: "batch", 1: "encoder_sequence"}

				return common_inputs







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a = -1		,  _a = -1		,  _a = False		,  _a = None		,  ):
				import torch

				__magic_name__						:						Optional[int]        =	OrderedDict()

				__magic_name__						:						int        =	super().generate_dummy_inputs(
				    __SCREAMING_SNAKE_CASE		,  batch_size=__SCREAMING_SNAKE_CASE		,  seq_length=__SCREAMING_SNAKE_CASE		,  is_pair=__SCREAMING_SNAKE_CASE		,  framework=__SCREAMING_SNAKE_CASE						)

				__magic_name__  ,       __magic_name__						:						int        =	dummy_input["input_ids"].shape
				__magic_name__						:						Optional[Any]        =	(batch, encoder_sequence, self._config.encoder_hidden_size)
				__magic_name__						:						str        =	dummy_input.pop("input_ids"						)
				__magic_name__						:						str        =	dummy_input.pop("attention_mask"						)
				__magic_name__						:						List[Any]        =	torch.zeros(__SCREAMING_SNAKE_CASE						)

				return common_inputs







class  _snake_case   (	a_							):







			@property
			def      SCREAMING_SNAKE_CASE       (							self						):
				pass







			def      SCREAMING_SNAKE_CASE       (							self		,  _a						):
				return VisionEncoderDecoderEncoderOnnxConfig(__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a		,  _a = "default"						):
				__magic_name__						:						Union[str, Any]        =	encoder_config.hidden_size
				return VisionEncoderDecoderDecoderOnnxConfig(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						)

import copy
import os
from typing import Union

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


SCREAMING_SNAKE_CASE			:						List[Any]				  =		logging.get_logger(__name__)

SCREAMING_SNAKE_CASE			:						Optional[int]				  =		{
    """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  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_text_model"""

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   str=3_05_24  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=30_72  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=12  ,				__SCREAMING_SNAKE_CASE			:   Dict=8  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   int=1E-12  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Dict=0.02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=3_05_22  ,				__SCREAMING_SNAKE_CASE			:   Any=2  ,				__SCREAMING_SNAKE_CASE			:   List[str]=0  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=1_02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=True  ,				__SCREAMING_SNAKE_CASE			:   Dict=True  ,				**__SCREAMING_SNAKE_CASE			:   str  ,				):
   super().__init__(
       pad_token_id=__SCREAMING_SNAKE_CASE  ,				bos_token_id=__SCREAMING_SNAKE_CASE  ,				eos_token_id=__SCREAMING_SNAKE_CASE  ,				sep_token_id=__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE  ,				)

   __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 		_UpperCAmelCase (		cls			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   int							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # 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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_vision_model"""

  def __init__(		self			:   Optional[int]  ,				__SCREAMING_SNAKE_CASE			:   str=7_68  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=30_72  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=5_12  ,				__SCREAMING_SNAKE_CASE			:   int=12  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=12  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=3_84  ,				__SCREAMING_SNAKE_CASE			:   str=16  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=1E-5  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=0.0  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=1E-10  ,				**__SCREAMING_SNAKE_CASE			:   List[str]  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   __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 		_UpperCAmelCase (		cls			:   Optional[Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   str							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # 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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip"""
  _SCREAMING_SNAKE_CASE     					=      True

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=None  ,				__SCREAMING_SNAKE_CASE			:   Any=None  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=2.65_92  ,				__SCREAMING_SNAKE_CASE			:   Any=2_56  ,				**__SCREAMING_SNAKE_CASE			:   Any  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   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(**__SCREAMING_SNAKE_CASE							)
   __a							=	BlipVisionConfig(**__SCREAMING_SNAKE_CASE							)

   __a							=	self.vision_config.hidden_size

   __a							=	projection_dim
   __a							=	logit_scale_init_value
   __a							=	1.0
   __a							=	0.02
   __a							=	image_text_hidden_size

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Any  ,				__SCREAMING_SNAKE_CASE			:   BlipTextConfig  ,				__SCREAMING_SNAKE_CASE			:   BlipVisionConfig  ,				**__SCREAMING_SNAKE_CASE			:   List[Any]							):
   return cls(text_config=text_config.to_dict()  ,				vision_config=vision_config.to_dict()  ,				**__SCREAMING_SNAKE_CASE							)

  def 		_UpperCAmelCase (		self			:   Union[str, Any]							):
   __a							=	copy.deepcopy(self.__dict__							)
   __a							=	self.text_config.to_dict()
   __a							=	self.vision_config.to_dict()
   __a							=	self.__class__.model_type
   return output


