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      A							(				UpperCAmelCase_     ):
   __UpperCAmelCase : str      =			'altclip_text_model'


   def __init__(self     :						List[str]       ,  __UpperCAmelCase     :						str=2_5_0_0_0_2       ,  __UpperCAmelCase     :						str=1_0_2_4       ,  __UpperCAmelCase     :						Dict=2_4       ,  __UpperCAmelCase     :						int=1_6       ,  __UpperCAmelCase     :						Optional[Any]=4_0_9_6       ,  __UpperCAmelCase     :						str="gelu"       ,  __UpperCAmelCase     :						int=0.1       ,  __UpperCAmelCase     :						Any=0.1       ,  __UpperCAmelCase     :						Optional[int]=5_1_4       ,  __UpperCAmelCase     :						List[Any]=1       ,  __UpperCAmelCase     :						int=0.02       ,  __UpperCAmelCase     :						Any=0.02       ,  __UpperCAmelCase     :						Optional[Any]=1E-05       ,  __UpperCAmelCase     :						Any=1       ,  __UpperCAmelCase     :						Dict=0       ,  __UpperCAmelCase     :						Any=2       ,  __UpperCAmelCase     :						Optional[Any]="absolute"       ,  __UpperCAmelCase     :						List[Any]=True       ,  __UpperCAmelCase     :						int=7_6_8       ,  **__UpperCAmelCase     :						Union[str, Any]       ,  )						->				List[Any]:
         """simple docstring"""



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

         UpperCAmelCase__								=  vocab_size
         UpperCAmelCase__								=  hidden_size
         UpperCAmelCase__								=  num_hidden_layers
         UpperCAmelCase__								=  num_attention_heads
         UpperCAmelCase__								=  hidden_act
         UpperCAmelCase__								=  intermediate_size
         UpperCAmelCase__								=  hidden_dropout_prob
         UpperCAmelCase__								=  attention_probs_dropout_prob
         UpperCAmelCase__								=  max_position_embeddings
         UpperCAmelCase__								=  type_vocab_size
         UpperCAmelCase__								=  initializer_range
         UpperCAmelCase__								=  initializer_factor
         UpperCAmelCase__								=  layer_norm_eps
         UpperCAmelCase__								=  position_embedding_type
         UpperCAmelCase__								=  use_cache
         UpperCAmelCase__								=  project_dim





class      A							(				UpperCAmelCase_     ):
   __UpperCAmelCase : Union[str, Any]      =			'altclip_vision_model'


   def __init__(self     :						str       ,  __UpperCAmelCase     :						List[Any]=7_6_8       ,  __UpperCAmelCase     :						Optional[Any]=3_0_7_2       ,  __UpperCAmelCase     :						Union[str, Any]=5_1_2       ,  __UpperCAmelCase     :						List[str]=1_2       ,  __UpperCAmelCase     :						Optional[int]=1_2       ,  __UpperCAmelCase     :						Any=3       ,  __UpperCAmelCase     :						List[str]=2_2_4       ,  __UpperCAmelCase     :						Union[str, Any]=3_2       ,  __UpperCAmelCase     :						Optional[Any]="quick_gelu"       ,  __UpperCAmelCase     :						Optional[Any]=1E-5       ,  __UpperCAmelCase     :						Dict=0.0       ,  __UpperCAmelCase     :						Optional[Any]=0.02       ,  __UpperCAmelCase     :						Optional[Any]=1.0       ,  **__UpperCAmelCase     :						Optional[Any]       ,  )						->				Any:
         """simple docstring"""



         super().__init__(**__UpperCAmelCase		)

         UpperCAmelCase__								=  hidden_size
         UpperCAmelCase__								=  intermediate_size
         UpperCAmelCase__								=  projection_dim
         UpperCAmelCase__								=  num_hidden_layers
         UpperCAmelCase__								=  num_attention_heads
         UpperCAmelCase__								=  num_channels
         UpperCAmelCase__								=  patch_size
         UpperCAmelCase__								=  image_size
         UpperCAmelCase__								=  initializer_range
         UpperCAmelCase__								=  initializer_factor
         UpperCAmelCase__								=  attention_dropout
         UpperCAmelCase__								=  layer_norm_eps
         UpperCAmelCase__								=  hidden_act





   @classmethod
   def 			lowercase_      (cls     :						Any       ,  __UpperCAmelCase     :						Union[str, os.PathLike]       ,  **__UpperCAmelCase     :						Optional[Any]		)						->				"PretrainedConfig":
         """simple docstring"""



         cls._set_token_in_kwargs(__UpperCAmelCase		)

         UpperCAmelCase__		,      UpperCAmelCase__								=  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__								=  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      A							(				UpperCAmelCase_     ):
   __UpperCAmelCase : Union[str, Any]      =			'altclip'
   __UpperCAmelCase : Union[str, Any]      =			True


   def __init__(self     :						Tuple       ,  __UpperCAmelCase     :						Optional[int]=None       ,  __UpperCAmelCase     :						Any=None       ,  __UpperCAmelCase     :						List[Any]=7_6_8       ,  __UpperCAmelCase     :						Optional[Any]=2.6592       ,  **__UpperCAmelCase     :						List[str]		)						->				str:
         """simple docstring"""



         UpperCAmelCase__								=  kwargs.pop("text_config_dict"       ,  __UpperCAmelCase		)
         UpperCAmelCase__								=  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__								=  {}

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

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

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

         UpperCAmelCase__								=  AltCLIPTextConfig(**__UpperCAmelCase		)
         UpperCAmelCase__								=  AltCLIPVisionConfig(**__UpperCAmelCase		)

         UpperCAmelCase__								=  projection_dim
         UpperCAmelCase__								=  logit_scale_init_value
         UpperCAmelCase__								=  1.0


   @classmethod
   def 			lowercase_      (cls     :						List[str]       ,  __UpperCAmelCase     :						AltCLIPTextConfig       ,  __UpperCAmelCase     :						AltCLIPVisionConfig       ,  **__UpperCAmelCase     :						Union[str, Any]		)						->				Any:
         """simple docstring"""



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





   def 			lowercase_      (self     :						Any		)						->				Optional[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  copy.deepcopy(self.__dict__		)
         UpperCAmelCase__								=  self.text_config.to_dict()
         UpperCAmelCase__								=  self.vision_config.to_dict()
         UpperCAmelCase__								=  self.__class__.model_type
         return output





from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase			:     Any           =   {
    'configuration_mctct': ['MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MCTCTConfig'],
    'feature_extraction_mctct': ['MCTCTFeatureExtractor'],
    'processing_mctct': ['MCTCTProcessor'],
}


try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCAmelCase			:     int           =   [
        'MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST',
        'MCTCTForCTC',
        'MCTCTModel',
        'MCTCTPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
    from .feature_extraction_mctct import MCTCTFeatureExtractor
    from .processing_mctct import MCTCTProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
    import sys

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

