






import copy
import os
from typing import Union

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


__UpperCAmelCase							:   Tuple							=  logging.get_logger(__name__)

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


class 					_snake_case						(			_UpperCamelCase ):
	_A          =   "altclip_text_model"






	def __init__(		self					,UpperCamelCase=250_002					,UpperCamelCase=1_024					,UpperCamelCase=24					,UpperCamelCase=16					,UpperCamelCase=4_096					,UpperCamelCase="gelu"					,UpperCamelCase=0.1					,UpperCamelCase=0.1					,UpperCamelCase=514					,UpperCamelCase=1					,UpperCamelCase=0.02					,UpperCamelCase=0.02					,UpperCamelCase=1E-05					,UpperCamelCase=1					,UpperCamelCase=0					,UpperCamelCase=2					,UpperCamelCase="absolute"					,UpperCamelCase=True					,UpperCamelCase=768					,**UpperCamelCase					,)						->    Optional[int]:
					super().__init__(pad_token_id=__a					,bos_token_id=__a					,eos_token_id=__a					,**__a       )

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




class 					_snake_case						(			_UpperCamelCase ):
	_A          =   "altclip_vision_model"






	def __init__(		self					,UpperCamelCase=768					,UpperCamelCase=3_072					,UpperCamelCase=512					,UpperCamelCase=12					,UpperCamelCase=12					,UpperCamelCase=3					,UpperCamelCase=224					,UpperCamelCase=32					,UpperCamelCase="quick_gelu"					,UpperCamelCase=1E-5					,UpperCamelCase=0.0					,UpperCamelCase=0.02					,UpperCamelCase=1.0					,**UpperCamelCase					,)						->    Any:
					super().__init__(**__a       )

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






	@classmethod
	def    lowerCAmelCase_							(		cls					,UpperCamelCase					,**UpperCamelCase       )						->    "PretrainedConfig":
					cls._set_token_in_kwargs(__a       )

					snake_case__      :int         =   cls.get_config_dict(__a					,**__a       )

					# get the vision config dict if we are loading from AltCLIPConfig
					if config_dict.get("model_type"       ) == "altclip":
									snake_case__      :Tuple         =   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(__a					,**__a       )




class 					_snake_case						(			_UpperCamelCase ):
	_A          =   "altclip"
	_A          =   True






	def __init__(		self					,UpperCamelCase=None					,UpperCamelCase=None					,UpperCamelCase=768					,UpperCamelCase=2.6592					,**UpperCamelCase       )						->    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!).
					snake_case__      :Tuple         =   kwargs.pop("text_config_dict"					,__a       )
					snake_case__      :Tuple         =   kwargs.pop("vision_config_dict"					,__a       )

					super().__init__(**__a       )

					# 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:
													snake_case__      :int         =   {}

									# This is the complete result when using `text_config_dict`.
									snake_case__      :Any         =   AltCLIPTextConfig(**__a       ).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:
																					snake_case__      :Optional[int]         =   (
																					    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:
																					snake_case__      :Union[str, 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(__a       )

            # 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:
													snake_case__      :int         =   {}

									# This is the complete result when using `vision_config_dict`.
									snake_case__      :List[Any]         =   AltCLIPVisionConfig(**__a       ).to_dict()
									# convert keys to string instead of integer
									if "id2label" in _vision_config_dict:
													snake_case__      :Dict         =   {
													    str(__a       ): 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:
																					snake_case__      :Optional[int]         =   (
																					    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:
																					snake_case__      :Optional[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(__a       )

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

					if text_config is None:
									snake_case__      :Optional[Any]         =   {}
									logger.info("`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."       )

					if vision_config is None:
									snake_case__      :Dict         =   {}
									logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."       )

					snake_case__      :Union[str, Any]         =   AltCLIPTextConfig(**__a       )
					snake_case__      :Dict         =   AltCLIPVisionConfig(**__a       )

					snake_case__      :Any         =   projection_dim
					snake_case__      :Union[str, Any]         =   logit_scale_init_value
					snake_case__      :Optional[Any]         =   1.0






	@classmethod
	def    lowerCAmelCase_							(		cls					,UpperCamelCase					,UpperCamelCase					,**UpperCamelCase       )						->    Optional[Any]:
					return cls(text_config=text_config.to_dict()					,vision_config=vision_config.to_dict()					,**__a       )






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












def 					lowercase_ (    __snake_case     :							str      )     -> list:





				'''simple docstring'''


				return [
				    txt[:a] + txt[a].upper() + txt[a + 1 :]
				    for a in range(len(__snake_case      )      )
				    if txt[a].isalpha()
				]


if __name__ == "__main__":
	__import__("doctest").testmod()