


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

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


UpperCAmelCase_			:  Dict										=   logging.get_logger(__name__)

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

class     _lowerCamelCase       (     __lowerCAmelCase					):




 '''simple docstring'''
 __lowercase					:		Tuple     				=    '''altclip_text_model'''


 def __init__(   self   ,   __lowercase=250_002   ,   __lowercase=1_024   ,   __lowercase=24   ,   __lowercase=16   ,   __lowercase=4_096   ,   __lowercase="gelu"   ,   __lowercase=0.1   ,   __lowercase=0.1   ,   __lowercase=514   ,   __lowercase=1   ,   __lowercase=0.0_2   ,   __lowercase=0.0_2   ,   __lowercase=1E-05   ,   __lowercase=1   ,   __lowercase=0   ,   __lowercase=2   ,   __lowercase="absolute"   ,   __lowercase=True   ,   __lowercase=768   ,   **__lowercase   ,   ):

  """simple docstring"""







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

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


class     _lowerCamelCase       (     __lowerCAmelCase					):




 '''simple docstring'''
 __lowercase					:		Tuple     				=    '''altclip_vision_model'''


 def __init__(   self   ,   __lowercase=768   ,   __lowercase=3_072   ,   __lowercase=512   ,   __lowercase=12   ,   __lowercase=12   ,   __lowercase=3   ,   __lowercase=224   ,   __lowercase=32   ,   __lowercase="quick_gelu"   ,   __lowercase=1E-5   ,   __lowercase=0.0   ,   __lowercase=0.0_2   ,   __lowercase=1.0   ,   **__lowercase   ,   ):

  """simple docstring"""







  super().__init__(**_UpperCAmelCase    )

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







 @classmethod
 def 			snake_case__ (   cls   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







  cls._set_token_in_kwargs(_UpperCAmelCase    )

  __A  ,__A	:		Union[str, 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":
   __A	:		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(_UpperCAmelCase   ,   **_UpperCAmelCase    )


class     _lowerCamelCase       (     __lowerCAmelCase					):




 '''simple docstring'''
 __lowercase					:		Dict     				=    '''altclip'''
 __lowercase					:		Optional[int]     				=    True


 def __init__(   self   ,   __lowercase=None   ,   __lowercase=None   ,   __lowercase=768   ,   __lowercase=2.6_5_9_2   ,   **__lowercase    ):

  """simple docstring"""







  __A	:		int	  =      kwargs.pop('text_config_dict'   ,   _UpperCAmelCase    )
  __A	:		int	  =      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:
    __A	:		List[Any]	  =      {}

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

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

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

  __A	:		Dict	  =      AltCLIPTextConfig(**_UpperCAmelCase    )
  __A	:		str	  =      AltCLIPVisionConfig(**_UpperCAmelCase    )

  __A	:		str	  =      projection_dim
  __A	:		int	  =      logit_scale_init_value
  __A	:		str	  =      1.0


 @classmethod
 def 			snake_case__ (   cls   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







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







 def 			snake_case__ (   self    ):

  """simple docstring"""







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












"""simple docstring"""

from .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
    MaskedBertForMultipleChoice,
    MaskedBertForQuestionAnswering,
    MaskedBertForSequenceClassification,
    MaskedBertForTokenClassification,
    MaskedBertModel,
)
from .modules import *

