
"""simple docstring"""





import copy
import os
from typing import Union

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


_a		       =							logging.get_logger(__name__)

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


class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						Any       =		"""altclip_text_model"""







  def __init__(		self				,   lowercase_=25_0002				,   lowercase_=1024				,   lowercase_=24				,   lowercase_=16				,   lowercase_=4096				,   lowercase_="gelu"				,   lowercase_=0.1				,   lowercase_=0.1				,   lowercase_=514				,   lowercase_=1				,   lowercase_=0.02				,   lowercase_=0.02				,   lowercase_=1E-0_5				,   lowercase_=1				,   lowercase_=0				,   lowercase_=2				,   lowercase_="absolute"				,   lowercase_=True				,   lowercase_=768				,   **lowercase_				,   ):

     """simple docstring"""
     super().__init__(pad_token_id=lowercase_				,   bos_token_id=lowercase_				,   eos_token_id=lowercase_				,   **lowercase_  )

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




class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						Optional[Any]       =		"""altclip_vision_model"""







  def __init__(		self				,   lowercase_=768				,   lowercase_=3072				,   lowercase_=512				,   lowercase_=12				,   lowercase_=12				,   lowercase_=3				,   lowercase_=224				,   lowercase_=32				,   lowercase_="quick_gelu"				,   lowercase_=1E-5				,   lowercase_=0.0				,   lowercase_=0.02				,   lowercase_=1.0				,   **lowercase_				,   ):

     """simple docstring"""
     super().__init__(**lowercase_  )

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







  @classmethod
  def        UpperCamelCase__					(		cls				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     cls._set_token_in_kwargs(lowercase_  )

     UpperCAmelCase_     ,   UpperCAmelCase_					:					Optional[Any]			     =    cls.get_config_dict(lowercase_				,   **lowercase_  )

     # 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(lowercase_				,   **lowercase_  )




class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						Any       =		"""altclip"""
  SCREAMING_SNAKE_CASE__			:						Optional[Any]       =		True







  def __init__(		self				,   lowercase_=None				,   lowercase_=None				,   lowercase_=768				,   lowercase_=2.65_92				,   **lowercase_  ):

     """simple docstring"""
     # 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_					:					Dict			     =    kwargs.pop("text_config_dict"				,   lowercase_  )
     UpperCAmelCase_					:					List[Any]			     =    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:
           UpperCAmelCase_					:					Union[str, Any]			     =    {}

        # This is the complete result when using `text_config_dict`.
        UpperCAmelCase_					:					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:
                 UpperCAmelCase_					:					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:
                 UpperCAmelCase_					:					Optional[int]			     =    (
                     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:
           UpperCAmelCase_					:					Optional[int]			     =    {}

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

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







  @classmethod
  def        UpperCamelCase__					(		cls				,   lowercase_				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     return cls(text_config=text_config.to_dict()				,   vision_config=vision_config.to_dict()				,   **lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Tuple			     =    copy.deepcopy(self.__dict__  )
     UpperCAmelCase_					:					int			     =    self.text_config.to_dict()
     UpperCAmelCase_					:					Union[str, Any]			     =    self.vision_config.to_dict()
     UpperCAmelCase_					:					Dict			     =    self.__class__.model_type
     return output



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


__lowerCamelCase					:	Dict       =  {'''configuration_vit_mae''': ['''VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTMAEConfig''']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	Any       =  [
		    '''VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ViTMAEForPreTraining''',
		    '''ViTMAELayer''',
		    '''ViTMAEModel''',
		    '''ViTMAEPreTrainedModel''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	Optional[Any]       =  [
		    '''TFViTMAEForPreTraining''',
		    '''TFViTMAEModel''',
		    '''TFViTMAEPreTrainedModel''',
		]

if TYPE_CHECKING:
		from .configuration_vit_mae import VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTMAEConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_vit_mae import (
				    VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ViTMAEForPreTraining,
				    ViTMAELayer,
				    ViTMAEModel,
				    ViTMAEPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_vit_mae import TFViTMAEForPreTraining, TFViTMAEModel, TFViTMAEPreTrainedModel


else:
		import sys

		__lowerCamelCase					:	Any       =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
