"""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     UpperCAmelCase						(_UpperCAmelCase  ):



    """simple docstring"""

    _UpperCAmelCase	:Dict						    = "altclip_text_model"






    def __init__(   self    ,			_UpperCAmelCase=250002    ,			_UpperCAmelCase=1024    ,			_UpperCAmelCase=24    ,			_UpperCAmelCase=16    ,			_UpperCAmelCase=4096    ,			_UpperCAmelCase="gelu"    ,			_UpperCAmelCase=0.1    ,			_UpperCAmelCase=0.1    ,			_UpperCAmelCase=514    ,			_UpperCAmelCase=1    ,			_UpperCAmelCase=0.02    ,			_UpperCAmelCase=0.02    ,			_UpperCAmelCase=1e-0_5    ,			_UpperCAmelCase=1    ,			_UpperCAmelCase=0    ,			_UpperCAmelCase=2    ,			_UpperCAmelCase="absolute"    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=768    ,			**_UpperCAmelCase    ,			):
       super().__init__(pad_token_id=_UpperCAmelCase    ,			bos_token_id=_UpperCAmelCase    ,			eos_token_id=_UpperCAmelCase    ,			**_UpperCAmelCase							)

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



class     UpperCAmelCase						(_UpperCAmelCase  ):



    """simple docstring"""

    _UpperCAmelCase	:List[str]						    = "altclip_vision_model"






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

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






    @classmethod
    def _snake_case			(   cls    ,			_UpperCAmelCase    ,			**_UpperCAmelCase							):
       cls._set_token_in_kwargs(_UpperCAmelCase							)

       lowercase__, lowercase__:   List[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":
          lowercase__:   int					=      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     UpperCAmelCase						(_UpperCAmelCase  ):



    """simple docstring"""

    _UpperCAmelCase	:List[str]						    = "altclip"
    _UpperCAmelCase	:Any						    = True






    def __init__(   self    ,			_UpperCAmelCase=None    ,			_UpperCAmelCase=None    ,			_UpperCAmelCase=768    ,			_UpperCAmelCase=2.6_592    ,			**_UpperCAmelCase							):
       # 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!).
       lowercase__:   Any					=      kwargs.pop('''text_config_dict'''    ,			_UpperCAmelCase							)
       lowercase__:   Optional[Any]					=      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:
             lowercase__:   Union[str, Any]					=      {}

          # This is the complete result when using `text_config_dict`.
          lowercase__:   List[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:
                   lowercase__:   List[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:
                   lowercase__:   List[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:
             lowercase__:   Dict					=      {}

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

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

       lowercase__:   str					=      AltCLIPTextConfig(**_UpperCAmelCase							)
       lowercase__:   Tuple					=      AltCLIPVisionConfig(**_UpperCAmelCase							)

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






    @classmethod
    def _snake_case			(   cls    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			**_UpperCAmelCase							):
       return cls(text_config=text_config.to_dict()    ,			vision_config=vision_config.to_dict()    ,			**_UpperCAmelCase							)






    def _snake_case			(   self							):
       lowercase__:   Tuple					=      copy.deepcopy(self.__dict__							)
       lowercase__:   Optional[Any]					=      self.text_config.to_dict()
       lowercase__:   int					=      self.vision_config.to_dict()
       lowercase__:   Dict					=      self.__class__.model_type
       return output

"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A			   = {
    "configuration_lilt": ["LILT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LiltConfig"],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __A			   = [
           "LILT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "LiltForQuestionAnswering",
           "LiltForSequenceClassification",
           "LiltForTokenClassification",
           "LiltModel",
           "LiltPreTrainedModel",
       ]

if TYPE_CHECKING:
       from .configuration_lilt import LILT_PRETRAINED_CONFIG_ARCHIVE_MAP, LiltConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_lilt import (
                  LILT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  LiltForQuestionAnswering,
                  LiltForSequenceClassification,
                  LiltForTokenClassification,
                  LiltModel,
                  LiltPreTrainedModel,
              )

else:
       import sys

       __A			   = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
