

'''simple docstring'''

import copy
import os
from typing import Union

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


SCREAMING_SNAKE_CASE							:				Any     	=			logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:				List[str]     	=			{
    "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     (      lowercase_		):






				"""simple docstring"""
				_a    	=     """blip_text_model"""



				def __init__(    self,     _lowercase=30524,     _lowercase=768,     _lowercase=768,     _lowercase=3072,     _lowercase=768,     _lowercase=12,     _lowercase=8,     _lowercase=512,     _lowercase="gelu",     _lowercase=1E-12,     _lowercase=0.0,     _lowercase=0.0,     _lowercase=0.02,     _lowercase=30522,     _lowercase=2,     _lowercase=0,     _lowercase=102,     _lowercase=True,     _lowercase=True,     **_lowercase,     )     ->							Dict:
											super().__init__(
											    pad_token_id=_lowercase,     bos_token_id=_lowercase,     eos_token_id=_lowercase,     sep_token_id=_lowercase,     **_lowercase,     )

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





				@classmethod
				def   a__					(    cls,     _lowercase,     **_lowercase       )     ->							"PretrainedConfig":
											cls._set_token_in_kwargs(_lowercase       )

											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				cls.get_config_dict(_lowercase,     **_lowercase       )

											# get the text config dict if we are loading from BlipConfig
											if config_dict.get('model_type'       ) == "blip":
																		SCREAMING_SNAKE_CASE_				=				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(_lowercase,     **_lowercase       )






class    snake_case     (      lowercase_		):






				"""simple docstring"""
				_a    	=     """blip_vision_model"""



				def __init__(    self,     _lowercase=768,     _lowercase=3072,     _lowercase=512,     _lowercase=12,     _lowercase=12,     _lowercase=384,     _lowercase=16,     _lowercase="gelu",     _lowercase=1E-5,     _lowercase=0.0,     _lowercase=1E-10,     **_lowercase,     )     ->							Any:
											super().__init__(**_lowercase       )

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





				@classmethod
				def   a__					(    cls,     _lowercase,     **_lowercase       )     ->							"PretrainedConfig":
											cls._set_token_in_kwargs(_lowercase       )

											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				cls.get_config_dict(_lowercase,     **_lowercase       )

											# get the vision config dict if we are loading from BlipConfig
											if config_dict.get('model_type'       ) == "blip":
																		SCREAMING_SNAKE_CASE_				=				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(_lowercase,     **_lowercase       )






class    snake_case     (      lowercase_		):






				"""simple docstring"""
				_a    	=     """blip"""
				_a    	=     True



				def __init__(    self,     _lowercase=None,     _lowercase=None,     _lowercase=512,     _lowercase=2.6_592,     _lowercase=256,     **_lowercase,     )     ->							Dict:
											super().__init__(**_lowercase       )

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

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

											SCREAMING_SNAKE_CASE_				=				BlipTextConfig(**_lowercase       )
											SCREAMING_SNAKE_CASE_				=				BlipVisionConfig(**_lowercase       )

											SCREAMING_SNAKE_CASE_				=				self.vision_config.hidden_size

											SCREAMING_SNAKE_CASE_				=				projection_dim
											SCREAMING_SNAKE_CASE_				=				logit_scale_init_value
											SCREAMING_SNAKE_CASE_				=				1.0
											SCREAMING_SNAKE_CASE_				=				0.02
											SCREAMING_SNAKE_CASE_				=				image_text_hidden_size



				@classmethod
				def   a__					(    cls,     _lowercase,     _lowercase,     **_lowercase       )     ->							Tuple:
											return cls(text_config=text_config.to_dict(),     vision_config=vision_config.to_dict(),     **_lowercase       )





				def   a__					(    self       )     ->							Optional[Any]:
											SCREAMING_SNAKE_CASE_				=				copy.deepcopy(self.__dict__       )
											SCREAMING_SNAKE_CASE_				=				self.text_config.to_dict()
											SCREAMING_SNAKE_CASE_				=				self.vision_config.to_dict()
											SCREAMING_SNAKE_CASE_				=				self.__class__.model_type
											return output








'''simple docstring'''

import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class    snake_case     (      lowercase_		):






				"""simple docstring"""
				_a    	=     ["""image_processor""", """tokenizer"""]
				_a    	=     """CLIPImageProcessor"""
				_a    	=     ("""XLMRobertaTokenizer""", """XLMRobertaTokenizerFast""")



				def __init__(    self,     _lowercase=None,     _lowercase=None,     **_lowercase       )     ->							int:
											SCREAMING_SNAKE_CASE_				=				None
											if "feature_extractor" in kwargs:
																		warnings.warn(
																		    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
																		    ' instead.',     _lowercase,     )
																		SCREAMING_SNAKE_CASE_				=				kwargs.pop('feature_extractor'       )

											SCREAMING_SNAKE_CASE_				=				image_processor if image_processor is not None else feature_extractor
											if image_processor is None:
																		raise ValueError('You need to specify an `image_processor`.'       )
											if tokenizer is None:
																		raise ValueError('You need to specify a `tokenizer`.'       )

											super().__init__(_lowercase,     _lowercase       )



				def __call__(    self,     _lowercase=None,     _lowercase=None,     _lowercase=None,     **_lowercase       )     ->							str:

											if text is None and images is None:
																		raise ValueError('You have to specify either text or images. Both cannot be none.'       )

											if text is not None:
																		SCREAMING_SNAKE_CASE_				=				self.tokenizer(_lowercase,     return_tensors=_lowercase,     **_lowercase       )

											if images is not None:
																		SCREAMING_SNAKE_CASE_				=				self.image_processor(_lowercase,     return_tensors=_lowercase,     **_lowercase       )

											if text is not None and images is not None:
																		SCREAMING_SNAKE_CASE_				=				image_features.pixel_values
																		return encoding
											elif text is not None:
																		return encoding
											else:
																		return BatchEncoding(data=dict(**_lowercase       ),     tensor_type=_lowercase       )



				def   a__					(    self,     *_lowercase,     **_lowercase       )     ->							Optional[int]:
											return self.tokenizer.batch_decode(*_lowercase,     **_lowercase       )



				def   a__					(    self,     *_lowercase,     **_lowercase       )     ->							Optional[Any]:
											return self.tokenizer.decode(*_lowercase,     **_lowercase       )





				@property
				def   a__					(    self       )     ->							Optional[int]:
											SCREAMING_SNAKE_CASE_				=				self.tokenizer.model_input_names
											SCREAMING_SNAKE_CASE_				=				self.image_processor.model_input_names
											return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names       )       )





