

'''simple docstring'''





import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
			pass

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


a_						     =    logging.get_logger(__name__)

a_						     =    {
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}






class _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			lowerCamelCase__           ='align_text_model'
			def __init__(			self							: List[str]      ,      a							: List[str]=3_0522      ,      a							: Tuple=768      ,      a							: Dict=12      ,      a							: Any=12      ,      a							: Union[str, Any]=3072      ,      a							: Tuple="gelu"      ,      a							: int=0.1      ,      a							: Optional[Any]=0.1      ,      a							: str=512      ,      a							: Dict=2      ,      a							: Union[str, Any]=0.02      ,      a							: int=1e-12      ,      a							: Any=0      ,      a							: Union[str, Any]="absolute"      ,      a							: Any=True      ,      **a							: int      ,      )							->       Tuple:

				"""simple docstring"""

				super().__init__(**_lowerCAmelCase	)

				SCREAMING_SNAKE_CASE   :      List[str]				     =       vocab_size
				SCREAMING_SNAKE_CASE   :      str				     =       hidden_size
				SCREAMING_SNAKE_CASE   :      int				     =       num_hidden_layers
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       num_attention_heads
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       hidden_act
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       intermediate_size
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       hidden_dropout_prob
				SCREAMING_SNAKE_CASE   :      List[str]				     =       attention_probs_dropout_prob
				SCREAMING_SNAKE_CASE   :      Dict				     =       max_position_embeddings
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       type_vocab_size
				SCREAMING_SNAKE_CASE   :      List[str]				     =       initializer_range
				SCREAMING_SNAKE_CASE   :      Any				     =       layer_norm_eps
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       position_embedding_type
				SCREAMING_SNAKE_CASE   :      str				     =       use_cache
				SCREAMING_SNAKE_CASE   :      List[str]				     =       pad_token_id






			@classmethod
			def 							__UpperCamelCase (			cls							: Any      ,      a							: Tuple      ,      **a							: Union[str, Any]	)							->       Dict:

				"""simple docstring"""

				cls._set_token_in_kwargs(_lowerCAmelCase	)

				SCREAMING_SNAKE_CASE     ,SCREAMING_SNAKE_CASE   :      int				     =       cls.get_config_dict(_lowerCAmelCase      ,      **_lowerCAmelCase	)

				# get the text config dict if we are loading from AlignConfig
				if config_dict.get("model_type"	) == "align":
					SCREAMING_SNAKE_CASE   :      str				     =       config_dict["text_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(_lowerCAmelCase      ,      **_lowerCAmelCase	)






class _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			lowerCamelCase__           ='align_vision_model'
			def __init__(			self							: Any      ,      a							: int = 3      ,      a							: int = 600      ,      a							: List[Any] = 2.0      ,      a							: str = 3.1      ,      a							: Dict = 8      ,      a							: Tuple = [3, 3, 5, 3, 5, 5, 3]      ,      a							: str = [32, 16, 24, 40, 80, 112, 192]      ,      a							: Union[str, Any] = [16, 24, 40, 80, 112, 192, 320]      ,      a							: Optional[Any] = []      ,      a							: str = [1, 2, 2, 2, 1, 2, 1]      ,      a							: Dict = [1, 2, 2, 3, 3, 4, 1]      ,      a							: str = [1, 6, 6, 6, 6, 6, 6]      ,      a							: int = 0.25      ,      a							: Union[str, Any] = "swish"      ,      a							: Dict = 2560      ,      a							: Optional[int] = "mean"      ,      a							: int = 0.02      ,      a							: str = 0.001      ,      a							: Union[str, Any] = 0.99      ,      a							: Union[str, Any] = 0.2      ,      **a							: str      ,      )							->       List[str]:

				"""simple docstring"""

				super().__init__(**_lowerCAmelCase	)

				SCREAMING_SNAKE_CASE   :      Any				     =       num_channels
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       image_size
				SCREAMING_SNAKE_CASE   :      Dict				     =       width_coefficient
				SCREAMING_SNAKE_CASE   :      str				     =       depth_coefficient
				SCREAMING_SNAKE_CASE   :      List[str]				     =       depth_divisor
				SCREAMING_SNAKE_CASE   :      str				     =       kernel_sizes
				SCREAMING_SNAKE_CASE   :      int				     =       in_channels
				SCREAMING_SNAKE_CASE   :      int				     =       out_channels
				SCREAMING_SNAKE_CASE   :      Tuple				     =       depthwise_padding
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       strides
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       num_block_repeats
				SCREAMING_SNAKE_CASE   :      Dict				     =       expand_ratios
				SCREAMING_SNAKE_CASE   :      str				     =       squeeze_expansion_ratio
				SCREAMING_SNAKE_CASE   :      Optional[Any]				     =       hidden_act
				SCREAMING_SNAKE_CASE   :      str				     =       hidden_dim
				SCREAMING_SNAKE_CASE   :      Any				     =       pooling_type
				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       initializer_range
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       batch_norm_eps
				SCREAMING_SNAKE_CASE   :      int				     =       batch_norm_momentum
				SCREAMING_SNAKE_CASE   :      List[str]				     =       drop_connect_rate
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       sum(_lowerCAmelCase	) * 4






			@classmethod
			def 							__UpperCamelCase (			cls							: List[str]      ,      a							: Dict      ,      **a							: Dict	)							->       List[Any]:

				"""simple docstring"""

				cls._set_token_in_kwargs(_lowerCAmelCase	)

				SCREAMING_SNAKE_CASE     ,SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       cls.get_config_dict(_lowerCAmelCase      ,      **_lowerCAmelCase	)

				# get the vision config dict if we are loading from AlignConfig
				if config_dict.get("model_type"	) == "align":
					SCREAMING_SNAKE_CASE   :      Tuple				     =       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(_lowerCAmelCase      ,      **_lowerCAmelCase	)






class _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			lowerCamelCase__           ='align'
			lowerCamelCase__           =True
			def __init__(			self							: List[Any]      ,      a							: Any=None      ,      a							: Optional[Any]=None      ,      a							: List[Any]=640      ,      a							: str=1.0      ,      a							: str=0.02      ,      **a							: Optional[Any]      ,      )							->       Any:

				"""simple docstring"""

				super().__init__(**_lowerCAmelCase	)

				if text_config is None:
					SCREAMING_SNAKE_CASE   :      List[str]				     =       {}
					logger.info("text_config is None. Initializing the AlignTextConfig with default values."	)

				if vision_config is None:
					SCREAMING_SNAKE_CASE   :      List[str]				     =       {}
					logger.info("vision_config is None. Initializing the AlignVisionConfig with default values."	)

				SCREAMING_SNAKE_CASE   :      str				     =       AlignTextConfig(**_lowerCAmelCase	)
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       AlignVisionConfig(**_lowerCAmelCase	)

				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       projection_dim
				SCREAMING_SNAKE_CASE   :      List[str]				     =       temperature_init_value
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       initializer_range
			@classmethod
			def 							__UpperCamelCase (			cls							: List[Any]      ,      a							: Optional[Any]      ,      a							: Union[str, Any]      ,      **a							: Optional[int]	)							->       Any:

				"""simple docstring"""

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






			def 							__UpperCamelCase (			self							: Tuple	)							->       int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      int				     =       copy.deepcopy(self.__dict__	)
				SCREAMING_SNAKE_CASE   :      Dict				     =       self.text_config.to_dict()
				SCREAMING_SNAKE_CASE   :      Tuple				     =       self.vision_config.to_dict()
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       self.__class__.model_type
				return output


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


a_						     =    logging.get_logger(__name__)

a_						     =    {
    '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 _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			lowerCamelCase__           ='gptj'
			lowerCamelCase__           ={
			    'max_position_embeddings': 'n_positions',
			    'hidden_size': 'n_embd',
			    'num_attention_heads': 'n_head',
			    'num_hidden_layers': 'n_layer',
			}
			def __init__(			self							: Dict      ,      a							: Optional[Any]=5_0400      ,      a							: List[str]=2048      ,      a							: List[Any]=4096      ,      a							: int=28      ,      a							: Union[str, Any]=16      ,      a							: List[Any]=64      ,      a							: int=None      ,      a							: Optional[int]="gelu_new"      ,      a							: Optional[Any]=0.0      ,      a							: Any=0.0      ,      a							: Union[str, Any]=0.0      ,      a							: Union[str, Any]=1e-5      ,      a							: Any=0.02      ,      a							: Optional[int]=True      ,      a							: Tuple=5_0256      ,      a							: Union[str, Any]=5_0256      ,      a							: List[Any]=False      ,      **a							: str      ,      )							->       Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      str				     =       vocab_size
				SCREAMING_SNAKE_CASE   :      int				     =       n_positions
				SCREAMING_SNAKE_CASE   :      Tuple				     =       n_embd
				SCREAMING_SNAKE_CASE   :      Tuple				     =       n_layer
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       n_head
				SCREAMING_SNAKE_CASE   :      Tuple				     =       n_inner
				SCREAMING_SNAKE_CASE   :      Any				     =       rotary_dim
				SCREAMING_SNAKE_CASE   :      str				     =       activation_function
				SCREAMING_SNAKE_CASE   :      int				     =       resid_pdrop
				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       embd_pdrop
				SCREAMING_SNAKE_CASE   :      Tuple				     =       attn_pdrop
				SCREAMING_SNAKE_CASE   :      List[str]				     =       layer_norm_epsilon
				SCREAMING_SNAKE_CASE   :      int				     =       initializer_range
				SCREAMING_SNAKE_CASE   :      Tuple				     =       use_cache

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       bos_token_id
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       eos_token_id

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






class _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			def __init__(			self							: Optional[int]      ,      a							: PretrainedConfig      ,      a							: str = "default"      ,      a							: List[PatchingSpec] = None      ,      a							: bool = False      ,      )							->       Any:

				"""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?
					SCREAMING_SNAKE_CASE   :      Dict				     =       0
			@property
			def 							__UpperCamelCase (			self							: Any	)							->       Mapping[str, Mapping[int, str]]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      List[Any]				     =       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}	)
				if self.use_past:
					self.fill_with_past_key_values_(a      ,      direction="inputs"	)
					SCREAMING_SNAKE_CASE   :      int				     =       {0: "batch", 1: "past_sequence + sequence"}
				else:
					SCREAMING_SNAKE_CASE   :      Any				     =       {0: "batch", 1: "sequence"}

				return common_inputs
			@property
			def 							__UpperCamelCase (			self							: Any	)							->       int:

				"""simple docstring"""

				return self._config.n_layer
			@property
			def 							__UpperCamelCase (			self							: str	)							->       int:

				"""simple docstring"""

				return self._config.n_head
			def 							__UpperCamelCase (			self							: str      ,      a							: PreTrainedTokenizer      ,      a							: int = -1      ,      a							: int = -1      ,      a							: bool = False      ,      a							: Optional[TensorType] = None      ,      )							->       Mapping[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      int				     =       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()
				SCREAMING_SNAKE_CASE   :      Tuple				     =       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

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

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

				return ordered_inputs






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

				"""simple docstring"""

				return 13