




"""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 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''
 UpperCAmelCase       :	Tuple     =      '''altclip_text_model'''

 def __init__(					self			:			Dict       ,				_UpperCAmelCase			:			Union[str, Any]=250_002       ,				_UpperCAmelCase			:			Optional[int]=1_024       ,				_UpperCAmelCase			:			Dict=24       ,				_UpperCAmelCase			:			List[str]=16       ,				_UpperCAmelCase			:			Optional[int]=4_096       ,				_UpperCAmelCase			:			Optional[Any]="gelu"       ,				_UpperCAmelCase			:			Any=0.1       ,				_UpperCAmelCase			:			Optional[int]=0.1       ,				_UpperCAmelCase			:			Optional[Any]=514       ,				_UpperCAmelCase			:			Optional[Any]=1       ,				_UpperCAmelCase			:			str=0.02       ,				_UpperCAmelCase			:			List[str]=0.02       ,				_UpperCAmelCase			:			Optional[Any]=1E-0_5       ,				_UpperCAmelCase			:			List[str]=1       ,				_UpperCAmelCase			:			Dict=0       ,				_UpperCAmelCase			:			List[Any]=2       ,				_UpperCAmelCase			:			Union[str, Any]="absolute"       ,				_UpperCAmelCase			:			Optional[Any]=True       ,				_UpperCAmelCase			:			int=768       ,				**_UpperCAmelCase			:			Union[str, Any]       ,				):
       super().__init__(pad_token_id=_UpperCAmelCase       ,				bos_token_id=_UpperCAmelCase       ,				eos_token_id=_UpperCAmelCase       ,				**_UpperCAmelCase						)

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





class 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''
 UpperCAmelCase       :	Tuple     =      '''altclip_vision_model'''

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

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



 @classmethod
 def      lowerCAmelCase_				(					cls			:			Optional[Any]       ,				_UpperCAmelCase			:			Union[str, os.PathLike]       ,				**_UpperCAmelCase			:			List[Any]						):
       cls._set_token_in_kwargs(_UpperCAmelCase						)

       _A  ,       _A     =  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     =  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 							lowercase_			(	__lowerCAmelCase				):



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

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

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

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

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

       _A     =  AltCLIPTextConfig(**_UpperCAmelCase						)
       _A     =  AltCLIPVisionConfig(**_UpperCAmelCase						)

       _A     =  projection_dim
       _A     =  logit_scale_init_value
       _A     =  1.0

 @classmethod
 def      lowerCAmelCase_				(					cls			:			List[Any]       ,				_UpperCAmelCase			:			AltCLIPTextConfig       ,				_UpperCAmelCase			:			AltCLIPVisionConfig       ,				**_UpperCAmelCase			:			Any						):
       return cls(text_config=text_config.to_dict()       ,				vision_config=vision_config.to_dict()       ,				**_UpperCAmelCase						)



 def      lowerCAmelCase_				(					self			:			Dict						):
       _A     =  copy.deepcopy(self.__dict__						)
       _A     =  self.text_config.to_dict()
       _A     =  self.vision_config.to_dict()
       _A     =  self.__class__.model_type
       return output







"""simple docstring"""

from collections import OrderedDict
from typing import Mapping

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


a							      =     logging.get_logger(__name__)

a							      =     {
    '''facebook/xmod-base''': '''https://huggingface.co/facebook/xmod-base/resolve/main/config.json''',
    '''facebook/xmod-large-prenorm''': '''https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json''',
    '''facebook/xmod-base-13-125k''': '''https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json''',
    '''facebook/xmod-base-30-125k''': '''https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json''',
    '''facebook/xmod-base-30-195k''': '''https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json''',
    '''facebook/xmod-base-60-125k''': '''https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json''',
    '''facebook/xmod-base-60-265k''': '''https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json''',
    '''facebook/xmod-base-75-125k''': '''https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json''',
    '''facebook/xmod-base-75-269k''': '''https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json''',
}





class 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''
 UpperCAmelCase       :	Optional[Any]     =      '''xmod'''

 def __init__(					self			:			str       ,				_UpperCAmelCase			:			Optional[Any]=30_522       ,				_UpperCAmelCase			:			Any=768       ,				_UpperCAmelCase			:			int=12       ,				_UpperCAmelCase			:			List[str]=12       ,				_UpperCAmelCase			:			Dict=3_072       ,				_UpperCAmelCase			:			Union[str, Any]="gelu"       ,				_UpperCAmelCase			:			Optional[int]=0.1       ,				_UpperCAmelCase			:			Tuple=0.1       ,				_UpperCAmelCase			:			List[str]=512       ,				_UpperCAmelCase			:			Dict=2       ,				_UpperCAmelCase			:			Optional[int]=0.02       ,				_UpperCAmelCase			:			Any=1E-1_2       ,				_UpperCAmelCase			:			Tuple=1       ,				_UpperCAmelCase			:			int=0       ,				_UpperCAmelCase			:			List[Any]=2       ,				_UpperCAmelCase			:			List[str]="absolute"       ,				_UpperCAmelCase			:			Tuple=True       ,				_UpperCAmelCase			:			Tuple=None       ,				_UpperCAmelCase			:			int=False       ,				_UpperCAmelCase			:			Union[str, Any]=2       ,				_UpperCAmelCase			:			List[Any]=False       ,				_UpperCAmelCase			:			Dict=True       ,				_UpperCAmelCase			:			List[str]=True       ,				_UpperCAmelCase			:			Tuple=("en_XX",)       ,				_UpperCAmelCase			:			List[str]=None       ,				**_UpperCAmelCase			:			Optional[Any]       ,				):
       super().__init__(pad_token_id=_UpperCAmelCase       ,				bos_token_id=_UpperCAmelCase       ,				eos_token_id=_UpperCAmelCase       ,				**_UpperCAmelCase						)

       _A     =  vocab_size
       _A     =  hidden_size
       _A     =  num_hidden_layers
       _A     =  num_attention_heads
       _A     =  hidden_act
       _A     =  intermediate_size
       _A     =  hidden_dropout_prob
       _A     =  attention_probs_dropout_prob
       _A     =  max_position_embeddings
       _A     =  type_vocab_size
       _A     =  initializer_range
       _A     =  layer_norm_eps
       _A     =  position_embedding_type
       _A     =  use_cache
       _A     =  classifier_dropout
       _A     =  pre_norm
       _A     =  adapter_reduction_factor
       _A     =  adapter_layer_norm
       _A     =  adapter_reuse_layer_norm
       _A     =  ln_before_adapter
       _A     =  list(_UpperCAmelCase						)
       _A     =  default_language





class 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''

 @property
 def      lowerCAmelCase_				(					self			:			Dict						):
       if self.task == "multiple-choice":
             _A     =  {0: 'batch', 1: 'choice', 2: 'sequence'}
       else:
             _A     =  {0: 'batch', 1: 'sequence'}
       return OrderedDict(
           [
               ('input_ids', dynamic_axis),
               ('attention_mask', dynamic_axis),
           ]						)

