



'''simple docstring'''






import copy
import os
from typing import Union

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


UpperCamelCase__:     int										=    logging.get_logger(__name__)

UpperCamelCase__:     Optional[Any]										=    {
    "BAAI/AltCLIP": "https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}

class        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """altclip_text_model"""







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

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

class        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """altclip_vision_model"""







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

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







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

								UpperCAmelCase							,	UpperCAmelCase				: Union[str, Any]											=	cls.get_config_dict(__snake_case	,    **__snake_case	)

								# get the vision config dict if we are loading from AltCLIPConfig
								if config_dict.get('''model_type'''	) == "altclip":
															UpperCAmelCase				: List[str]											=	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        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """altclip"""
	lowerCamelCase__    				= True







	def __init__(		self    :  Dict	,    __snake_case    :  int=None	,    __snake_case    :  int=None	,    __snake_case    :  List[Any]=768	,    __snake_case    :  int=2.65_92	,    **__snake_case    :  List[str]	)    ->	List[str]:
								# 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!).
								UpperCAmelCase				: str											=	kwargs.pop('''text_config_dict'''	,    __snake_case	)
								UpperCAmelCase				: str											=	kwargs.pop('''vision_config_dict'''	,    __snake_case	)

								super().__init__(**__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:
																						UpperCAmelCase				: Union[str, Any]											=	{}

															# This is the complete result when using `text_config_dict`.
															UpperCAmelCase				: Optional[int]											=	AltCLIPTextConfig(**__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:
																																				UpperCAmelCase				: Optional[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:
																																				UpperCAmelCase				: List[str]											=	(
																																				    F"""`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The """
																																				    F"""value `text_config[\"{key}\"]` will be overriden."""
																																				)
																													logger.warning(__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:
																						UpperCAmelCase				: Optional[Any]											=	{}

															# This is the complete result when using `vision_config_dict`.
															UpperCAmelCase				: List[Any]											=	AltCLIPVisionConfig(**__snake_case	).to_dict()
															# convert keys to string instead of integer
															if "id2label" in _vision_config_dict:
																						UpperCAmelCase				: str											=	{
																						    str(__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:
																																				UpperCAmelCase				: 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:
																																				UpperCAmelCase				: Union[str, Any]											=	(
																																				    F"""`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. """
																																				    F"""The value `vision_config[\"{key}\"]` will be overriden."""
																																				)
																													logger.warning(__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:
															UpperCAmelCase				: Union[str, Any]											=	{}
															logger.info('''`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'''	)

								if vision_config is None:
															UpperCAmelCase				: str											=	{}
															logger.info('''`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'''	)

								UpperCAmelCase				: Any											=	AltCLIPTextConfig(**__snake_case	)
								UpperCAmelCase				: Union[str, Any]											=	AltCLIPVisionConfig(**__snake_case	)

								UpperCAmelCase				: List[Any]											=	projection_dim
								UpperCAmelCase				: str											=	logit_scale_init_value
								UpperCAmelCase				: Dict											=	1.0







	@classmethod
	def   A			(		cls    :  Optional[Any]	,    __snake_case    :  AltCLIPTextConfig	,    __snake_case    :  AltCLIPVisionConfig	,    **__snake_case    :  Union[str, Any]	)    ->	List[Any]:
								return cls(text_config=text_config.to_dict()	,    vision_config=vision_config.to_dict()	,    **__snake_case	)







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










'''simple docstring'''






# Lint as: python3
import dataclasses
import re
from dataclasses import dataclass
from functools import total_ordering
from typing import Optional, Union


UpperCamelCase__:     List[str]										=    re.compile(r"^(?P<major>\d+)" r"\.(?P<minor>\d+)" r"\.(?P<patch>\d+)$")

@total_ordering
@dataclass
class        SCREAMING_SNAKE_CASE:







	"""simple docstring"""






	lowerCamelCase__    				= 42
	lowerCamelCase__    				= None
	lowerCamelCase__    				= None
	lowerCamelCase__    				= None
	lowerCamelCase__    				= None







	def   A			(		self    :  Optional[Any]	)    ->	Dict:
								UpperCAmelCase							,	UpperCAmelCase							,	UpperCAmelCase				: Any											=	_str_to_version_tuple(self.version_str	)







	def __repr__(		self    :  str	)    ->	Optional[Any]:
								return F"""{self.tuple[0]}.{self.tuple[1]}.{self.tuple[2]}"""







	@property
	def   A			(		self    :  Tuple	)    ->	Dict:
								return self.major, self.minor, self.patch







	def   A			(		self    :  str	,    __snake_case    :  Any	)    ->	Tuple:
								if isinstance(__snake_case	,    __snake_case	):
															return Version(__snake_case	)
								elif isinstance(__snake_case	,    __snake_case	):
															return other
								raise TypeError(F"""{other} (type {type(__snake_case	)}) cannot be compared to version."""	)







	def __eq__(		self    :  str	,    __snake_case    :  Union[str, Any]	)    ->	List[Any]:
								try:
															UpperCAmelCase				: Dict											=	self._validate_operand(__snake_case	)
								except (TypeError, ValueError):
															return False
								else:
															return self.tuple == other.tuple







	def __lt__(		self    :  Any	,    __snake_case    :  int	)    ->	Optional[int]:
								UpperCAmelCase				: int											=	self._validate_operand(__snake_case	)
								return self.tuple < other.tuple







	def __hash__(		self    :  List[str]	)    ->	str:
								return hash(_version_tuple_to_str(self.tuple	)	)







	@classmethod
	def   A			(		cls    :  Any	,    __snake_case    :  Tuple	)    ->	Union[str, Any]:
								UpperCAmelCase				: Optional[Any]											=	{f.name for f in dataclasses.fields(cls	)}
								return cls(**{k: v for k, v in dic.items() if k in field_names}	)







	def   A			(		self    :  Dict	)    ->	str:
								return self.version_str


def 				snake_case_  (      _lowerCAmelCase						:		Optional[Any]						)   ->     List[Any]:
							UpperCAmelCase				: Optional[Any]											=	_VERSION_REG.match(_lowerCAmelCase						)
							if not res:
														raise ValueError(f"""Invalid version '{version_str}'. Format should be x.y.z with {{x,y,z}} being digits."""						)
							return tuple(int(_lowerCAmelCase						) for v in [res.group('''major'''						), res.group('''minor'''						), res.group('''patch'''						)]						)




def 				snake_case_  (      _lowerCAmelCase						:		List[str]						)   ->     List[Any]:
							return ".".join(str(_lowerCAmelCase						) for v in version_tuple						)





