



import copy
import os
from typing import Union

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


a_   :List[str]        =      logging.get_logger(__name__)

a_   :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_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	'altclip_text_model'






     def __init__(       self  :  List[str], _snake_case  :  str=2_5_0_0_0_2, _snake_case  :  str=1_0_2_4, _snake_case  :  Dict=2_4, _snake_case  :  int=1_6, _snake_case  :  Optional[Any]=4_0_9_6, _snake_case  :  str="gelu", _snake_case  :  int=0.1, _snake_case  :  Any=0.1, _snake_case  :  Optional[int]=5_1_4, _snake_case  :  List[Any]=1, _snake_case  :  int=0.0_2, _snake_case  :  Any=0.0_2, _snake_case  :  Optional[Any]=1e-05, _snake_case  :  Any=1, _snake_case  :  Dict=0, _snake_case  :  Any=2, _snake_case  :  Optional[Any]="absolute", _snake_case  :  List[Any]=True, _snake_case  :  int=7_6_8, **_snake_case  :  Union[str, Any], )   ->List[Any]:
            super().__init__(pad_token_id=__UpperCAmelCase, bos_token_id=__UpperCAmelCase, eos_token_id=__UpperCAmelCase, **__UpperCAmelCase					)

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




class 					snake_case__						(       UpperCAmelCase_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	'altclip_vision_model'






     def __init__(       self  :  str, _snake_case  :  List[Any]=7_6_8, _snake_case  :  Optional[Any]=3_0_7_2, _snake_case  :  Union[str, Any]=5_1_2, _snake_case  :  List[str]=1_2, _snake_case  :  Optional[int]=1_2, _snake_case  :  Any=3, _snake_case  :  List[str]=2_2_4, _snake_case  :  Union[str, Any]=3_2, _snake_case  :  Optional[Any]="quick_gelu", _snake_case  :  Optional[Any]=1e-5, _snake_case  :  Dict=0.0, _snake_case  :  Optional[Any]=0.0_2, _snake_case  :  Optional[Any]=1.0, **_snake_case  :  Optional[Any], )   ->Any:
            super().__init__(**__UpperCAmelCase					)

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






     @classmethod
     def    lowercase_   (       cls  :  Any, _snake_case  :  Union[str, os.PathLike], **_snake_case  :  Optional[Any]					)   ->"PretrainedConfig":
            cls._set_token_in_kwargs(__UpperCAmelCase					)

            snake_case__	,				snake_case__							:	str   	=	cls.get_config_dict(__UpperCAmelCase, **__UpperCAmelCase					)

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




class 					snake_case__						(       UpperCAmelCase_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	'altclip'
     _SCREAMING_SNAKE_CASE						=	True






     def __init__(       self  :  Tuple, _snake_case  :  Optional[int]=None, _snake_case  :  Any=None, _snake_case  :  List[Any]=7_6_8, _snake_case  :  Optional[Any]=2.6_5_9_2, **_snake_case  :  List[str]					)   ->str:
            snake_case__							:	int   	=	kwargs.pop('text_config_dict', __UpperCAmelCase					)
            snake_case__							:	Tuple   	=	kwargs.pop('vision_config_dict', __UpperCAmelCase					)

            super().__init__(**__UpperCAmelCase					)

            # 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__							:	Any   	=	{}

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

            # 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__							:	List[Any]   	=	{}

                   # This is the complete result when using `vision_config_dict`.
                   snake_case__							:	List[Any]   	=	AltCLIPVisionConfig(**__UpperCAmelCase					).to_dict()
                   # convert keys to string instead of integer
                   if "id2label" in _vision_config_dict:
                          snake_case__							:	Optional[int]   	=	{
                              str(__UpperCAmelCase					): 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__							:	str   	=	(
                                            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__							:	Dict   	=	(
                                            F'''`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '''
                                            F'''The value `vision_config[\"{key}\"]` will be overriden.'''
                                        )
                                 logger.warning(__UpperCAmelCase					)

            # 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__							:	List[Any]   	=	{}
                   logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'					)

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

            snake_case__							:	Tuple   	=	AltCLIPTextConfig(**__UpperCAmelCase					)
            snake_case__							:	Dict   	=	AltCLIPVisionConfig(**__UpperCAmelCase					)

            snake_case__							:	Optional[Any]   	=	projection_dim
            snake_case__							:	Tuple   	=	logit_scale_init_value
            snake_case__							:	str   	=	1.0






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






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







from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

UpperCamelCase__											=					[
    'python',
    'tqdm',
    'regex',
    'requests',
    'packaging',
    'filelock',
    'numpy',
    'tokenizers',
    'huggingface-hub',
    'safetensors',
    'accelerate',
    'pyyaml',
]

for pkg in pkgs_to_check_at_runtime:
      if pkg in deps:
            if pkg == "tokenizers":
                  # must be loaded here, or else tqdm check may fail
                  from .utils import is_tokenizers_available

                  if not is_tokenizers_available():
                        continue  # not required, check version only if installed
            elif pkg == "accelerate":
                  # must be loaded here, or else tqdm check may fail
                  from .utils import is_accelerate_available

                  # Maybe switch to is_torch_available in the future here so that Accelerate is hard dep of
                  # Transformers with PyTorch
                  if not is_accelerate_available():
                        continue  # not required, check version only if installed

            require_version_core(deps[pkg])
      else:
            raise ValueError(f'''can\'t find {pkg} in {deps.keys()}, check dependency_versions_table.py''')




def    lowerCAmelCase_ (     __A,  __A=None							)     ->				Dict:







      '''simple docstring'''


      require_version(deps[pkg],  __A							)



