


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


__UpperCamelCase							:							int    							=					logging.get_logger(__name__)

__UpperCamelCase							:							Union[str, Any]    							=					{
    """gpt2""": """https://huggingface.co/gpt2/resolve/main/config.json""",
    """gpt2-medium""": """https://huggingface.co/gpt2-medium/resolve/main/config.json""",
    """gpt2-large""": """https://huggingface.co/gpt2-large/resolve/main/config.json""",
    """gpt2-xl""": """https://huggingface.co/gpt2-xl/resolve/main/config.json""",
    """distilgpt2""": """https://huggingface.co/distilgpt2/resolve/main/config.json""",
}

class    __magic_name__						(  __A):
     A:		Optional[int]								=   "gpt2"
     A:		Optional[int]								=   ["past_key_values"]
     A:		str								=   {
         "hidden_size": "n_embd",
         "max_position_embeddings": "n_positions",
         "num_attention_heads": "n_head",
         "num_hidden_layers": "n_layer",
     }


     def __init__(   self				:  List[Any]				,						lowerCamelCase__				:  Dict=50257				,						lowerCamelCase__				:  List[Any]=1024				,						lowerCamelCase__				:  Tuple=768				,						lowerCamelCase__				:  Optional[Any]=12				,						lowerCamelCase__				:  Optional[Any]=12				,						lowerCamelCase__				:  Union[str, Any]=None				,						lowerCamelCase__				:  int="gelu_new"				,						lowerCamelCase__				:  Tuple=0.1				,						lowerCamelCase__				:  Any=0.1				,						lowerCamelCase__				:  Optional[Any]=0.1				,						lowerCamelCase__				:  Union[str, Any]=1E-5				,						lowerCamelCase__				:  Dict=0.02				,						lowerCamelCase__				:  Dict="cls_index"				,						lowerCamelCase__				:  Any=True				,						lowerCamelCase__				:  str=None				,						lowerCamelCase__				:  str=True				,						lowerCamelCase__				:  Dict=0.1				,						lowerCamelCase__				:  str=True				,						lowerCamelCase__				:  Dict=True				,						lowerCamelCase__				:  Optional[int]=50256				,						lowerCamelCase__				:  Optional[Any]=50256				,						lowerCamelCase__				:  Any=False				,						lowerCamelCase__				:  Dict=False				,						**lowerCamelCase__				:  List[Any]				,						)	->   Optional[int]:





      '''simple docstring'''






      UpperCamelCase__       :     List[Any] 							= vocab_size
      UpperCamelCase__       :     List[Any] 							= n_positions
      UpperCamelCase__       :     List[Any] 							= n_embd
      UpperCamelCase__       :     List[Any] 							= n_layer
      UpperCamelCase__       :     str 							= n_head
      UpperCamelCase__       :     int 							= n_inner
      UpperCamelCase__       :     Tuple 							= activation_function
      UpperCamelCase__       :     str 							= resid_pdrop
      UpperCamelCase__       :     int 							= embd_pdrop
      UpperCamelCase__       :     Dict 							= attn_pdrop
      UpperCamelCase__       :     Any 							= layer_norm_epsilon
      UpperCamelCase__       :     int 							= initializer_range
      UpperCamelCase__       :     Union[str, Any] 							= summary_type
      UpperCamelCase__       :     Any 							= summary_use_proj
      UpperCamelCase__       :     Tuple 							= summary_activation
      UpperCamelCase__       :     Optional[int] 							= summary_first_dropout
      UpperCamelCase__       :     List[str] 							= summary_proj_to_labels
      UpperCamelCase__       :     Optional[Any] 							= scale_attn_weights
      UpperCamelCase__       :     str 							= use_cache
      UpperCamelCase__       :     int 							= scale_attn_by_inverse_layer_idx
      UpperCamelCase__       :     int 							= reorder_and_upcast_attn

      UpperCamelCase__       :     List[Any] 							= bos_token_id
      UpperCamelCase__       :     List[str] 							= eos_token_id

      super().__init__(bos_token_id=_lowercase				,						eos_token_id=_lowercase				,						**_lowercase      )



class    __magic_name__						(  __A):


     def __init__(   self				:  Union[str, Any]				,						lowerCamelCase__				:  str				,						lowerCamelCase__				:  Dict = "default"				,						lowerCamelCase__				:  List[Any] = None				,						lowerCamelCase__				:  List[Any] = False				,						)	->   int:





      '''simple docstring'''






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


     @property
     def   UpperCAmelCase__						(   self				:  Optional[int]      )	->   Any:





      '''simple docstring'''






      UpperCamelCase__       :     str 							= OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}      )
      if self.use_past:
       self.fill_with_past_key_values_(_lowercase				,						direction='''inputs'''      )
       UpperCamelCase__       :     Optional[int] 							= {0: """batch""", 1: """past_sequence + sequence"""}
      else:
       UpperCamelCase__       :     Any 							= {0: """batch""", 1: """sequence"""}

      return common_inputs


     @property
     def   UpperCAmelCase__						(   self				:  List[Any]      )	->   Union[str, Any]:





      '''simple docstring'''






      return self._config.n_layer


     @property
     def   UpperCAmelCase__						(   self				:  Optional[int]      )	->   Optional[int]:





      '''simple docstring'''






      return self._config.n_head


     def   UpperCAmelCase__						(   self				:  int				,						lowerCamelCase__				:  Any				,						lowerCamelCase__				:  Dict = -1				,						lowerCamelCase__				:  Dict = -1				,						lowerCamelCase__				:  List[Any] = False				,						lowerCamelCase__				:  List[Any] = None				,						)	->   int:





      '''simple docstring'''






      UpperCamelCase__       :     Optional[int] 							= super(_lowercase				,						self      ).generate_dummy_inputs(
          _lowercase				,						batch_size=_lowercase				,						seq_length=_lowercase				,						is_pair=_lowercase				,						framework=_lowercase      )

      # We need to order the input in the way they appears in the forward()
      UpperCamelCase__       :     List[str] 							= 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

        UpperCamelCase__       :     Optional[Any] 							= common_inputs["""input_ids"""].shape
        # Not using the same length for past_key_values
        UpperCamelCase__       :     Optional[Any] 							= seqlen + 2
        UpperCamelCase__       :     Optional[Any] 							= (
            batch,
            self.num_attention_heads,
            past_key_values_length,
            self._config.hidden_size // self.num_attention_heads,
        )
        UpperCamelCase__       :     Tuple 							= [
            (torch.zeros(_lowercase      ), torch.zeros(_lowercase      )) for _ in range(self.num_layers      )
        ]

      UpperCamelCase__       :     Optional[int] 							= common_inputs["""attention_mask"""]
      if self.use_past:
       UpperCamelCase__       :     List[str] 							= ordered_inputs["""attention_mask"""].dtype
       UpperCamelCase__       :     Union[str, Any] 							= torch.cat(
           [ordered_inputs['''attention_mask'''], torch.ones(_lowercase				,						_lowercase				,						dtype=_lowercase      )]				,						dim=1      )

      return ordered_inputs


     @property
     def   UpperCAmelCase__						(   self				:  Optional[Any]      )	->   Optional[Any]:





      '''simple docstring'''






      return 13









import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


UpperCAmelCase_       : Union[str, Any]							=    logging.get_logger(__name__)





class   lowercase__     (				__A	):
  __UpperCamelCase						  =	"""vision-text-dual-encoder"""
  __UpperCamelCase						  =	True







  def __init__(						self     ,    _lowercase=512     ,    _lowercase=2.6592     ,    **_lowercase    ):
       super().__init__(**_lowercase    )

       if "vision_config" not in kwargs:
            raise ValueError("""`vision_config` can not be `None`."""    )

       if "text_config" not in kwargs:
            raise ValueError("""`text_config` can not be `None`."""    )

       lowerCAmelCase_       :							Dict			 =		kwargs.pop("""vision_config"""    )
       lowerCAmelCase_       :							Optional[int]			 =		kwargs.pop("""text_config"""    )

       lowerCAmelCase_       :							Tuple			 =		vision_config.pop("""model_type"""    )
       lowerCAmelCase_       :							str			 =		text_config.pop("""model_type"""    )

       if vision_model_type == "clip":
            lowerCAmelCase_       :							Dict			 =		AutoConfig.for_model(_lowercase     ,    **_lowercase    ).vision_config
       elif vision_model_type == "clip_vision_model":
            lowerCAmelCase_       :							Any			 =		CLIPVisionConfig(**_lowercase    )
       else:
            lowerCAmelCase_       :							Tuple			 =		AutoConfig.for_model(_lowercase     ,    **_lowercase    )

       lowerCAmelCase_       :							List[Any]			 =		AutoConfig.for_model(_lowercase     ,    **_lowercase    )

       lowerCAmelCase_       :							Union[str, Any]			 =		projection_dim
       lowerCAmelCase_       :							Optional[int]			 =		logit_scale_init_value







  @classmethod
  def 						UpperCAmelCase__		(						cls     ,    _lowercase     ,    _lowercase     ,    **_lowercase    ):
       return cls(vision_config=vision_config.to_dict()     ,    text_config=text_config.to_dict()     ,    **_lowercase    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							int			 =		copy.deepcopy(self.__dict__    )
       lowerCAmelCase_       :							List[str]			 =		self.vision_config.to_dict()
       lowerCAmelCase_       :							List[str]			 =		self.text_config.to_dict()
       lowerCAmelCase_       :							str			 =		self.__class__.model_type
       return output
