


import copy
import os
from typing import Union

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


lowerCamelCase						=		logging.get_logger(__name__)

lowerCamelCase						=		{
    '''BAAI/AltCLIP''': '''https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json''',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}





class  _a							(    _lowercase):
	_a  :  Union[str, Any]				   =							'''altclip_text_model'''




	def __init__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=25_0002		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=1024		, _SCREAMING_SNAKE_CASE						:		List[str]=24		, _SCREAMING_SNAKE_CASE						:		List[Any]=16		, _SCREAMING_SNAKE_CASE						:		Dict=4096		, _SCREAMING_SNAKE_CASE						:		List[Any]="gelu"		, _SCREAMING_SNAKE_CASE						:		List[Any]=0.1		, _SCREAMING_SNAKE_CASE						:		int=0.1		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=514		, _SCREAMING_SNAKE_CASE						:		List[Any]=1		, _SCREAMING_SNAKE_CASE						:		Dict=0.02		, _SCREAMING_SNAKE_CASE						:		str=0.02		, _SCREAMING_SNAKE_CASE						:		Any=1E-05		, _SCREAMING_SNAKE_CASE						:		List[str]=1		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=0		, _SCREAMING_SNAKE_CASE						:		Dict=2		, _SCREAMING_SNAKE_CASE						:		Dict="absolute"		, _SCREAMING_SNAKE_CASE						:		List[Any]=True		, _SCREAMING_SNAKE_CASE						:		int=768		, **_SCREAMING_SNAKE_CASE						:		Any		, )->	Any:
			super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE		, bos_token_id=_SCREAMING_SNAKE_CASE		, eos_token_id=_SCREAMING_SNAKE_CASE		, **_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Optional[int]   					= vocab_size
			lowerCAmelCase__       :      Optional[Any]   					= hidden_size
			lowerCAmelCase__       :      Union[str, Any]   					= num_hidden_layers
			lowerCAmelCase__       :      Dict   					= num_attention_heads
			lowerCAmelCase__       :      Optional[int]   					= hidden_act
			lowerCAmelCase__       :      List[str]   					= intermediate_size
			lowerCAmelCase__       :      Dict   					= hidden_dropout_prob
			lowerCAmelCase__       :      Dict   					= attention_probs_dropout_prob
			lowerCAmelCase__       :      Optional[Any]   					= max_position_embeddings
			lowerCAmelCase__       :      Dict   					= type_vocab_size
			lowerCAmelCase__       :      Optional[Any]   					= initializer_range
			lowerCAmelCase__       :      Any   					= initializer_factor
			lowerCAmelCase__       :      List[str]   					= layer_norm_eps
			lowerCAmelCase__       :      List[Any]   					= position_embedding_type
			lowerCAmelCase__       :      Tuple   					= use_cache
			lowerCAmelCase__       :      List[str]   					= project_dim





class  _a							(    _lowercase):
	_a  :  Optional[Any]				   =							'''altclip_vision_model'''




	def __init__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		List[str]=768		, _SCREAMING_SNAKE_CASE						:		Any=3072		, _SCREAMING_SNAKE_CASE						:		Dict=512		, _SCREAMING_SNAKE_CASE						:		Dict=12		, _SCREAMING_SNAKE_CASE						:		Optional[int]=12		, _SCREAMING_SNAKE_CASE						:		List[str]=3		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=224		, _SCREAMING_SNAKE_CASE						:		Optional[int]=32		, _SCREAMING_SNAKE_CASE						:		Dict="quick_gelu"		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=1E-5		, _SCREAMING_SNAKE_CASE						:		int=0.0		, _SCREAMING_SNAKE_CASE						:		Dict=0.02		, _SCREAMING_SNAKE_CASE						:		List[str]=1.0		, **_SCREAMING_SNAKE_CASE						:		str		, )->	int:
			super().__init__(**_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Tuple   					= hidden_size
			lowerCAmelCase__       :      List[str]   					= intermediate_size
			lowerCAmelCase__       :      Optional[Any]   					= projection_dim
			lowerCAmelCase__       :      Tuple   					= num_hidden_layers
			lowerCAmelCase__       :      Dict   					= num_attention_heads
			lowerCAmelCase__       :      Any   					= num_channels
			lowerCAmelCase__       :      int   					= patch_size
			lowerCAmelCase__       :      str   					= image_size
			lowerCAmelCase__       :      Dict   					= initializer_range
			lowerCAmelCase__       :      Optional[Any]   					= initializer_factor
			lowerCAmelCase__       :      Dict   					= attention_dropout
			lowerCAmelCase__       :      Optional[Any]   					= layer_norm_eps
			lowerCAmelCase__       :      Optional[int]   					= hidden_act




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

			lowerCAmelCase__       :      List[Any]   					= cls.get_config_dict(_SCREAMING_SNAKE_CASE		, **_SCREAMING_SNAKE_CASE		)

			# get the vision config dict if we are loading from AltCLIPConfig
			if config_dict.get('''model_type'''		) == "altclip":
					lowerCAmelCase__       :      List[Any]   					= 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							(    _lowercase):
	_a  :  str				   =							'''altclip'''
	_a  :  int				   =							True




	def __init__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Any=None		, _SCREAMING_SNAKE_CASE						:		Optional[int]=None		, _SCREAMING_SNAKE_CASE						:		Any=768		, _SCREAMING_SNAKE_CASE						:		Optional[int]=2.6592		, **_SCREAMING_SNAKE_CASE						:		int		)->	List[Any]:
			# If `_config_dict` exist, we use them for the backward compatibility.
			# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
			# of confusion!).
			lowerCAmelCase__       :      List[Any]   					= kwargs.pop('''text_config_dict'''		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      int   					= kwargs.pop('''vision_config_dict'''		, _SCREAMING_SNAKE_CASE		)

			super().__init__(**_SCREAMING_SNAKE_CASE		)

			# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
			# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
			# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
			if text_config_dict is not None:
					if text_config is None:
							lowerCAmelCase__       :      Optional[int]   					= {}

					# This is the complete result when using `text_config_dict`.
					lowerCAmelCase__       :      Optional[int]   					= AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE		).to_dict()

					# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
					for key, value in _text_config_dict.items():
							if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
									# If specified in `text_config_dict`
									if key in text_config_dict:
											lowerCAmelCase__       :      List[Any]   					= (
											    F'`{key}` is found in both `text_config_dict` and `text_config` but with different values. '
											    F'The value `text_config_dict["{key}"]` will be used instead.'
											)
									# If inferred from default argument values (just to be super careful)
									else:
											lowerCAmelCase__       :      List[Any]   					= (
											    F'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
											    F'value `text_config["{key}"]` will be overriden.'
											)
									logger.warning(_SCREAMING_SNAKE_CASE		)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
					text_config.update(_text_config_dict		)

			if vision_config_dict is not None:
					if vision_config is None:
							lowerCAmelCase__       :      List[Any]   					= {}

					# This is the complete result when using `vision_config_dict`.
					lowerCAmelCase__       :      List[Any]   					= AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE		).to_dict()
					# convert keys to string instead of integer
					if "id2label" in _vision_config_dict:
							lowerCAmelCase__       :      Union[str, Any]   					= {
							    str(_SCREAMING_SNAKE_CASE		): value for key, value in _vision_config_dict['''id2label'''].items()
							}

					# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
					for key, value in _vision_config_dict.items():
							if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
									# If specified in `vision_config_dict`
									if key in vision_config_dict:
											lowerCAmelCase__       :      Tuple   					= (
											    F'`{key}` is found in both `vision_config_dict` and `vision_config` but with different '
											    F'values. The value `vision_config_dict["{key}"]` will be used instead.'
											)
									# If inferred from default argument values (just to be super careful)
									else:
											lowerCAmelCase__       :      List[str]   					= (
											    F'`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '
											    F'The value `vision_config["{key}"]` will be overriden.'
											)
									logger.warning(_SCREAMING_SNAKE_CASE		)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
					vision_config.update(_vision_config_dict		)

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

			if vision_config is None:
					lowerCAmelCase__       :      Optional[int]   					= {}
					logger.info('''`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'''		)

			lowerCAmelCase__       :      List[Any]   					= AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Dict   					= AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Tuple   					= projection_dim
			lowerCAmelCase__       :      Tuple   					= logit_scale_init_value
			lowerCAmelCase__       :      Any   					= 1.0




	@classmethod
	def 							UpperCAmelCase__( cls						:		int		, _SCREAMING_SNAKE_CASE						:		AltCLIPTextConfig		, _SCREAMING_SNAKE_CASE						:		AltCLIPVisionConfig		, **_SCREAMING_SNAKE_CASE						:		str		)->	Dict:
			return cls(text_config=text_config.to_dict()		, vision_config=vision_config.to_dict()		, **_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		int		)->	Optional[int]:
			lowerCAmelCase__       :      Dict   					= copy.deepcopy(self.__dict__		)
			lowerCAmelCase__       :      str   					= self.text_config.to_dict()
			lowerCAmelCase__       :      List[Any]   					= self.vision_config.to_dict()
			lowerCAmelCase__       :      List[Any]   					= self.__class__.model_type
			return output




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


lowerCamelCase						=		logging.get_logger(__name__)

lowerCamelCase						=		{
    '''facebook/dpr-ctx_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-ctx_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json'''
    ),
}





class  _a							(    _lowercase):
	_a  :  List[Any]				   =							'''dpr'''




	def __init__( self						:		List[str]		, _SCREAMING_SNAKE_CASE						:		List[str]=3_0522		, _SCREAMING_SNAKE_CASE						:		Optional[int]=768		, _SCREAMING_SNAKE_CASE						:		List[str]=12		, _SCREAMING_SNAKE_CASE						:		Tuple=12		, _SCREAMING_SNAKE_CASE						:		str=3072		, _SCREAMING_SNAKE_CASE						:		Optional[Any]="gelu"		, _SCREAMING_SNAKE_CASE						:		Dict=0.1		, _SCREAMING_SNAKE_CASE						:		Optional[int]=0.1		, _SCREAMING_SNAKE_CASE						:		List[str]=512		, _SCREAMING_SNAKE_CASE						:		int=2		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=0.02		, _SCREAMING_SNAKE_CASE						:		Tuple=1E-12		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=0		, _SCREAMING_SNAKE_CASE						:		List[str]="absolute"		, _SCREAMING_SNAKE_CASE						:		int = 0		, **_SCREAMING_SNAKE_CASE						:		Optional[Any]		, )->	Optional[int]:
			super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE		, **_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Union[str, Any]   					= vocab_size
			lowerCAmelCase__       :      Tuple   					= hidden_size
			lowerCAmelCase__       :      Union[str, Any]   					= num_hidden_layers
			lowerCAmelCase__       :      List[Any]   					= num_attention_heads
			lowerCAmelCase__       :      Optional[int]   					= hidden_act
			lowerCAmelCase__       :      Optional[Any]   					= intermediate_size
			lowerCAmelCase__       :      Optional[Any]   					= hidden_dropout_prob
			lowerCAmelCase__       :      int   					= attention_probs_dropout_prob
			lowerCAmelCase__       :      str   					= max_position_embeddings
			lowerCAmelCase__       :      List[Any]   					= type_vocab_size
			lowerCAmelCase__       :      Optional[int]   					= initializer_range
			lowerCAmelCase__       :      List[str]   					= layer_norm_eps
			lowerCAmelCase__       :      Dict   					= projection_dim
			lowerCAmelCase__       :      int   					= position_embedding_type




