"""simple docstring"""
import copy
import os
from typing import Union

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


lowercase__					       =	logging.get_logger(__name__)

lowercase__					       =	{
    '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       (     __lowerCAmelCase				):
      a__        =		"""altclip_text_model"""



      def __init__(						self    ,			lowercase=25_00_02    ,			lowercase=10_24    ,			lowercase=24    ,			lowercase=16    ,			lowercase=40_96    ,			lowercase="gelu"    ,			lowercase=0.1    ,			lowercase=0.1    ,			lowercase=5_14    ,			lowercase=1    ,			lowercase=0.02    ,			lowercase=0.02    ,			lowercase=1e-05    ,			lowercase=1    ,			lowercase=0    ,			lowercase=2    ,			lowercase="absolute"    ,			lowercase=True    ,			lowercase=7_68    ,			**lowercase    ,			)	->			Any:





        '''simple docstring'''





        super().__init__(pad_token_id=lowercase    ,			bos_token_id=lowercase    ,			eos_token_id=lowercase    ,			**lowercase)

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







class    __snake_case       (     __lowerCAmelCase				):
      a__        =		"""altclip_vision_model"""



      def __init__(						self    ,			lowercase=7_68    ,			lowercase=30_72    ,			lowercase=5_12    ,			lowercase=12    ,			lowercase=12    ,			lowercase=3    ,			lowercase=2_24    ,			lowercase=32    ,			lowercase="quick_gelu"    ,			lowercase=1e-5    ,			lowercase=0.0    ,			lowercase=0.02    ,			lowercase=1.0    ,			**lowercase    ,			)	->			List[str]:





        '''simple docstring'''





        super().__init__(**lowercase)

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



      @classmethod
      def   lowerCamelCase_   (						cls    ,			lowercase    ,			**lowercase)	->			"PretrainedConfig":





        '''simple docstring'''





        cls._set_token_in_kwargs(lowercase)

        a__							,    a__:     int										=	cls.get_config_dict(lowercase    ,			**lowercase)

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







class    __snake_case       (     __lowerCAmelCase				):
      a__        =		"""altclip"""
      a__        =		True



      def __init__(						self    ,			lowercase=None    ,			lowercase=None    ,			lowercase=7_68    ,			lowercase=2.6592    ,			**lowercase)	->			str:





        '''simple docstring'''





        a__:     List[Any]										=	kwargs.pop('text_config_dict'    ,			lowercase)
        a__:     Tuple										=	kwargs.pop('vision_config_dict'    ,			lowercase)

        super().__init__(**lowercase)

        # 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:
            a__:     str										=	{}

          # This is the complete result when using `text_config_dict`.
          a__:     int										=	AltCLIPTextConfig(**lowercase).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:
                a__:     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:
                a__:     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(lowercase)

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

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

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

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

        if vision_config is None:
          a__:     Union[str, Any]										=	{}
          logger.info('`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.')

        a__:     int										=	AltCLIPTextConfig(**lowercase)
        a__:     Optional[int]										=	AltCLIPVisionConfig(**lowercase)

        a__:     Optional[Any]										=	projection_dim
        a__:     List[str]										=	logit_scale_init_value
        a__:     int										=	1.0



      @classmethod
      def   lowerCamelCase_   (						cls    ,			lowercase    ,			lowercase    ,			**lowercase)	->			Any:





        '''simple docstring'''





        return cls(text_config=text_config.to_dict()    ,			vision_config=vision_config.to_dict()    ,			**lowercase)



      def   lowerCamelCase_   (						self)	->			str:





        '''simple docstring'''





        a__:     Optional[Any]										=	copy.deepcopy(self.__dict__)
        a__:     Tuple										=	self.text_config.to_dict()
        a__:     Optional[int]										=	self.vision_config.to_dict()
        a__:     str										=	self.__class__.model_type
        return output



"""simple docstring"""
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]


