


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

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


UpperCamelCase__    					=      logging.get_logger(__name__)

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




class 			lowerCamelCase_   (	__snake_case      ):
      lowerCAmelCase__		     =     """altclip_text_model"""






      def __init__(					self				:    str						,						_A				:    Any=250_002						,						_A				:    Union[str, Any]=1_024						,						_A				:    List[Any]=24						,						_A				:    Union[str, Any]=16						,						_A				:    int=4_096						,						_A				:    int="gelu"						,						_A				:    str=0.1						,						_A				:    Any=0.1						,						_A				:    Union[str, Any]=514						,						_A				:    int=1						,						_A				:    List[str]=0.0_2						,						_A				:    str=0.0_2						,						_A				:    Optional[Any]=1e-05						,						_A				:    Any=1						,						_A				:    Union[str, Any]=0						,						_A				:    Dict=2						,						_A				:    str="absolute"						,						_A				:    Union[str, Any]=True						,						_A				:    Union[str, Any]=768						,						**_A				:    List[Any]						,						):


          '''simple docstring'''


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

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




class 			lowerCamelCase_   (	__snake_case      ):
      lowerCAmelCase__		     =     """altclip_vision_model"""






      def __init__(					self				:    Dict						,						_A				:    Dict=768						,						_A				:    int=3_072						,						_A				:    Optional[int]=512						,						_A				:    int=12						,						_A				:    str=12						,						_A				:    List[str]=3						,						_A				:    Dict=224						,						_A				:    Any=32						,						_A				:    List[str]="quick_gelu"						,						_A				:    Optional[int]=1e-5						,						_A				:    Union[str, Any]=0.0						,						_A				:    Union[str, Any]=0.0_2						,						_A				:    Any=1.0						,						**_A				:    Optional[int]						,						):


          '''simple docstring'''


          super().__init__(**UpperCamelCase__ )

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






      @classmethod
      def lowercase_							(					cls				:    int						,						_A				:    Union[str, os.PathLike]						,						**_A				:    Optional[int] ):


          '''simple docstring'''


          cls._set_token_in_kwargs(UpperCamelCase__ )

          UpperCAmelCase__			:		Optional[Any]													=				cls.get_config_dict(UpperCamelCase__						,						**UpperCamelCase__ )

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




class 			lowerCamelCase_   (	__snake_case      ):
      lowerCAmelCase__		     =     """altclip"""
      lowerCAmelCase__		     =     True






      def __init__(					self				:    Tuple						,						_A				:    Optional[int]=None						,						_A				:    List[str]=None						,						_A				:    Dict=768						,						_A				:    Any=2.6_5_9_2						,						**_A				:    str ):


          '''simple docstring'''


          UpperCAmelCase__			:		str													=				kwargs.pop('''text_config_dict'''						,						UpperCamelCase__ )
          UpperCAmelCase__			:		Dict													=				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:
                  UpperCAmelCase__			:		List[Any]													=				{}

              # This is the complete result when using `text_config_dict`.
              UpperCAmelCase__			:		Tuple													=				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:
                          UpperCAmelCase__			:		str													=				(
                              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__			:		Dict													=				(
                              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:
                  UpperCAmelCase__			:		str													=				{}

              # This is the complete result when using `vision_config_dict`.
              UpperCAmelCase__			:		Dict													=				AltCLIPVisionConfig(**UpperCamelCase__ ).to_dict()
              # convert keys to string instead of integer
              if "id2label" in _vision_config_dict:
                  UpperCAmelCase__			:		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:
                          UpperCAmelCase__			:		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:
                          UpperCAmelCase__			:		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(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:
              UpperCAmelCase__			:		List[str]													=				{}
              logger.info('''`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.''' )

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

          UpperCAmelCase__			:		str													=				AltCLIPTextConfig(**UpperCamelCase__ )
          UpperCAmelCase__			:		str													=				AltCLIPVisionConfig(**UpperCamelCase__ )

          UpperCAmelCase__			:		Any													=				projection_dim
          UpperCAmelCase__			:		Any													=				logit_scale_init_value
          UpperCAmelCase__			:		int													=				1.0






      @classmethod
      def lowercase_							(					cls				:    Dict						,						_A				:    AltCLIPTextConfig						,						_A				:    AltCLIPVisionConfig						,						**_A				:    int ):


          '''simple docstring'''


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






      def lowercase_							(					self				:    List[Any] ):


          '''simple docstring'''


          UpperCAmelCase__			:		Dict													=				copy.deepcopy(self.__dict__ )
          UpperCAmelCase__			:		List[str]													=				self.text_config.to_dict()
          UpperCAmelCase__			:		str													=				self.vision_config.to_dict()
          UpperCAmelCase__			:		Any													=				self.__class__.model_type
          return output



"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A						   =			logging.get_logger(__name__)

__A						   =			{
    "microsoft/beit-base-patch16-224-pt22k": (
        "https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Tuple         =  """beit"""

				def __init__(	self							:				List[Any]     ,  UpperCamelCase__							:				List[str]=8_1_9_2     ,  UpperCamelCase__							:				Dict=7_6_8     ,  UpperCamelCase__							:				List[str]=1_2     ,  UpperCamelCase__							:				Union[str, Any]=1_2     ,  UpperCamelCase__							:				Dict=3_0_7_2     ,  UpperCamelCase__							:				Optional[int]="gelu"     ,  UpperCamelCase__							:				Tuple=0.0     ,  UpperCamelCase__							:				Tuple=0.0     ,  UpperCamelCase__							:				Union[str, Any]=0.02     ,  UpperCamelCase__							:				Optional[Any]=1e-12     ,  UpperCamelCase__							:				str=2_2_4     ,  UpperCamelCase__							:				str=1_6     ,  UpperCamelCase__							:				Union[str, Any]=3     ,  UpperCamelCase__							:				Optional[int]=False     ,  UpperCamelCase__							:				int=False     ,  UpperCamelCase__							:				Optional[Any]=False     ,  UpperCamelCase__							:				Optional[Any]=False     ,  UpperCamelCase__							:				Dict=0.1     ,  UpperCamelCase__							:				List[Any]=0.1     ,  UpperCamelCase__							:				Any=True     ,  UpperCamelCase__							:				Optional[Any]=[3, 5, 7, 1_1]     ,  UpperCamelCase__							:				Optional[Any]=[1, 2, 3, 6]     ,  UpperCamelCase__							:				Optional[Any]=True     ,  UpperCamelCase__							:				Tuple=0.4     ,  UpperCamelCase__							:				Optional[Any]=2_5_6     ,  UpperCamelCase__							:				Optional[int]=1     ,  UpperCamelCase__							:				Optional[int]=False     ,  UpperCamelCase__							:				Optional[Any]=2_5_5     ,  **UpperCamelCase__							:				Optional[int]     ,  )->   int:



						'''simple docstring'''


						super().__init__(**UpperCamelCase__)

						__lowerCAmelCase:       str          =			vocab_size
						__lowerCAmelCase:       List[Any]          =			hidden_size
						__lowerCAmelCase:       str          =			num_hidden_layers
						__lowerCAmelCase:       Tuple          =			num_attention_heads
						__lowerCAmelCase:       Union[str, Any]          =			intermediate_size
						__lowerCAmelCase:       List[Any]          =			hidden_act
						__lowerCAmelCase:       Optional[Any]          =			hidden_dropout_prob
						__lowerCAmelCase:       List[Any]          =			attention_probs_dropout_prob
						__lowerCAmelCase:       str          =			initializer_range
						__lowerCAmelCase:       Optional[Any]          =			layer_norm_eps

						__lowerCAmelCase:       Any          =			image_size
						__lowerCAmelCase:       Any          =			patch_size
						__lowerCAmelCase:       Union[str, Any]          =			num_channels
						__lowerCAmelCase:       Tuple          =			use_mask_token
						__lowerCAmelCase:       Optional[Any]          =			use_absolute_position_embeddings
						__lowerCAmelCase:       List[Any]          =			use_relative_position_bias
						__lowerCAmelCase:       Optional[Any]          =			use_shared_relative_position_bias
						__lowerCAmelCase:       List[str]          =			layer_scale_init_value
						__lowerCAmelCase:       str          =			drop_path_rate
						__lowerCAmelCase:       str          =			use_mean_pooling
						# decode head attributes (semantic segmentation)
						__lowerCAmelCase:       Optional[Any]          =			out_indices
						__lowerCAmelCase:       Union[str, Any]          =			pool_scales
						# auxiliary head attributes (semantic segmentation)
						__lowerCAmelCase:       List[str]          =			use_auxiliary_head
						__lowerCAmelCase:       Union[str, Any]          =			auxiliary_loss_weight
						__lowerCAmelCase:       Optional[int]          =			auxiliary_channels
						__lowerCAmelCase:       Dict          =			auxiliary_num_convs
						__lowerCAmelCase:       List[Any]          =			auxiliary_concat_input
						__lowerCAmelCase:       str          =			semantic_loss_ignore_index





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Optional[Any]         =  version.parse("""1.11"""  )

				@property
				def 							lowercase_     (	self							:				str)->   Mapping[str, Mapping[int, str]]:



						'''simple docstring'''


						return OrderedDict(
						    [
						        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
						    ])




				@property
				def 							lowercase_     (	self							:				Any)->   float:



						'''simple docstring'''


						return 1e-4


