



import copy
import os
from typing import Union

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


lowercase_	       =			logging.get_logger(__name__)

lowercase_	       =			{
    '''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 (     SCREAMING_SNAKE_CASE				):
	SCREAMING_SNAKE_CASE       =       "blip_text_model"



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

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



	@classmethod
	def 		UpperCamelCase							(						cls							:    Optional[int]				,	snake_case_							:    Union[str, os.PathLike]				,	**snake_case_							:    int)->							"PretrainedConfig":
						cls._set_token_in_kwargs(snake_case_)

						__lowerCAmelCase   ,	__lowerCAmelCase	   =cls.get_config_dict(snake_case_				,	**snake_case_)

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






class 						__a (     SCREAMING_SNAKE_CASE				):
	SCREAMING_SNAKE_CASE       =       "blip_vision_model"



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

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



	@classmethod
	def 		UpperCamelCase							(						cls							:    Tuple				,	snake_case_							:    Union[str, os.PathLike]				,	**snake_case_							:    List[str])->							"PretrainedConfig":
						cls._set_token_in_kwargs(snake_case_)

						__lowerCAmelCase   ,	__lowerCAmelCase	   =cls.get_config_dict(snake_case_				,	**snake_case_)

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






class 						__a (     SCREAMING_SNAKE_CASE				):
	SCREAMING_SNAKE_CASE       =       "blip"
	SCREAMING_SNAKE_CASE       =       True



	def __init__(						self							:    Tuple				,	snake_case_							:    List[str]=None				,	snake_case_							:    List[Any]=None				,	snake_case_							:    Union[str, Any]=5_12				,	snake_case_							:    List[str]=2.6_5_9_2				,	snake_case_							:    Union[str, Any]=2_56				,	**snake_case_							:    Tuple				,	)->							Union[str, Any]:
						super().__init__(**snake_case_)

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

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

						__lowerCAmelCase	   =BlipTextConfig(**snake_case_)
						__lowerCAmelCase	   =BlipVisionConfig(**snake_case_)

						__lowerCAmelCase	   =self.vision_config.hidden_size

						__lowerCAmelCase	   =projection_dim
						__lowerCAmelCase	   =logit_scale_init_value
						__lowerCAmelCase	   =1.0
						__lowerCAmelCase	   =0.0_2
						__lowerCAmelCase	   =image_text_hidden_size



	@classmethod
	def 		UpperCamelCase							(						cls							:    str				,	snake_case_							:    BlipTextConfig				,	snake_case_							:    BlipVisionConfig				,	**snake_case_							:    Any)->							Union[str, Any]:
						return cls(text_config=text_config.to_dict()				,	vision_config=vision_config.to_dict()				,	**snake_case_)



	def 		UpperCamelCase							(						self							:    str)->							Any:
						__lowerCAmelCase	   =copy.deepcopy(self.__dict__)
						__lowerCAmelCase	   =self.text_config.to_dict()
						__lowerCAmelCase	   =self.vision_config.to_dict()
						__lowerCAmelCase	   =self.__class__.model_type
						return output









import os
from typing import Dict, List, Tuple, TypeVar, Union


lowercase_	       =			TypeVar('''T''')

lowercase_	       =			Union[List[T], Tuple[T, ...]]
lowercase_	       =			Union[T, List[T], Dict[str, T]]
lowercase_	       =			Union[str, bytes, os.PathLike]




