



'''simple docstring'''





import copy
import os
from typing import Union

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


lowercase_		       =  logging.get_logger(__name__)

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






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       int          =       'altclip_text_model'



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


      """simple docstring"""



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

      _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 __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Union[str, Any]          =       'altclip_vision_model'



 def __init__(self ,   A=768 ,   A=3_072 ,   A=512 ,   A=12 ,   A=12 ,   A=3 ,   A=224 ,   A=32 ,   A="quick_gelu" ,   A=1E-5 ,   A=0.0 ,   A=0.02 ,   A=1.0 ,   **A ,   )    ->     List[Any]:


      """simple docstring"""



      super().__init__(**A       )

      _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 					a__  (cls ,   A ,   **A       )    ->     "PretrainedConfig":


      """simple docstring"""



      cls._set_token_in_kwargs(A       )

      _a  ,    _a      =  cls.get_config_dict(A ,   **A       )

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






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Optional[int]          =       'altclip'
 __lowerCamelCase    :       Any          =       True



 def __init__(self ,   A=None ,   A=None ,   A=768 ,   A=2.6592 ,   **A       )    ->     Any:


      """simple docstring"""



      _a      =  kwargs.pop('''text_config_dict''' ,   A       )
      _a      =  kwargs.pop('''vision_config_dict''' ,   A       )

      super().__init__(**A       )

      # 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(**A       ).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(A       )

            # 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(**A       ).to_dict()
           # convert keys to string instead of integer
           if "id2label" in _vision_config_dict:
                _a      =  {
                    str(A       ): 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(A       )

            # 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(**A       )
      _a      =  AltCLIPVisionConfig(**A       )

      _a      =  projection_dim
      _a      =  logit_scale_init_value
      _a      =  1.0



 @classmethod
 def 					a__  (cls ,   A ,   A ,   **A       )    ->     Tuple:


      """simple docstring"""



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



 def 					a__  (self       )    ->     List[Any]:


      """simple docstring"""



      _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 Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


lowercase_		       =  logging.get_logger(__name__)

lowercase_		       =  {
    "EleutherAI/gpt-j-6B": "https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json",
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Any          =       'gptj'
 __lowerCamelCase    :       List[str]          =       {
     'max_position_embeddings': 'n_positions',
     'hidden_size': 'n_embd',
     'num_attention_heads': 'n_head',
     'num_hidden_layers': 'n_layer',
 }



 def __init__(self ,   A=50_400 ,   A=2_048 ,   A=4_096 ,   A=28 ,   A=16 ,   A=64 ,   A=None ,   A="gelu_new" ,   A=0.0 ,   A=0.0 ,   A=0.0 ,   A=1E-5 ,   A=0.02 ,   A=True ,   A=50_256 ,   A=50_256 ,   A=False ,   **A ,   )    ->     Tuple:


      """simple docstring"""



      _a      =  vocab_size
      _a      =  n_positions
      _a      =  n_embd
      _a      =  n_layer
      _a      =  n_head
      _a      =  n_inner
      _a      =  rotary_dim
      _a      =  activation_function
      _a      =  resid_pdrop
      _a      =  embd_pdrop
      _a      =  attn_pdrop
      _a      =  layer_norm_epsilon
      _a      =  initializer_range
      _a      =  use_cache

      _a      =  bos_token_id
      _a      =  eos_token_id

      super().__init__(
          bos_token_id=A ,   eos_token_id=A ,   tie_word_embeddings=A ,   **A       )






class __A			(  A						):



 '''simple docstring'''







 def __init__(self ,   A ,   A = "default" ,   A = None ,   A = False ,   )    ->     List[str]:


      """simple docstring"""



      super().__init__(A ,   task=A ,   patching_specs=A ,   use_past=A       )
      if not getattr(self._config ,   '''pad_token_id''' ,   A       ):
           # TODO: how to do that better?
           _a      =  0



 @property
 def 					a__  (self       )    ->     Mapping[str, Mapping[int, str]]:


      """simple docstring"""



      _a      =  OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}       )
      if self.use_past:
           self.fill_with_past_key_values_(A ,   direction='''inputs'''       )
           _a      =  {0: '''batch''', 1: '''past_sequence + sequence'''}
      else:
           _a      =  {0: '''batch''', 1: '''sequence'''}

      return common_inputs



 @property
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      return self._config.n_layer



 @property
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      return self._config.n_head



 def 					a__  (self ,   A ,   A = -1 ,   A = -1 ,   A = False ,   A = None ,   )    ->     Mapping[str, Any]:


      """simple docstring"""



      _a      =  super(A ,   self       ).generate_dummy_inputs(
          A ,   batch_size=A ,   seq_length=A ,   is_pair=A ,   framework=A       )

      # We need to order the input in the way they appears in the forward()
      _a      =  OrderedDict({'''input_ids''': common_inputs['''input_ids''']}       )

      # Need to add the past_keys
      if self.use_past:
           if not is_torch_available():
                raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''       )
           else:
                import torch

                _a  ,    _a      =  common_inputs['''input_ids'''].shape
                # Not using the same length for past_key_values
                _a      =  seqlen + 2
                _a      =  (
                    batch,
                    self.num_attention_heads,
                    past_key_values_length,
                    self._config.hidden_size // self.num_attention_heads,
                )
                _a      =  [
                    (torch.zeros(A       ), torch.zeros(A       )) for _ in range(self.num_layers       )
                ]

      _a      =  common_inputs['''attention_mask''']
      if self.use_past:
           _a      =  ordered_inputs['''attention_mask'''].dtype
           _a      =  torch.cat(
               [ordered_inputs['''attention_mask'''], torch.ones(A ,   A ,   dtype=A       )] ,   dim=1       )

      return ordered_inputs



 @property
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      return 13



