



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								=   logging.get_logger(__name__)

UpperCAmelCase								=   {
    """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 	__snake_case (				SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							UpperCamelCase__			: Union[str, Any]             =   """gpt2"""
							UpperCamelCase__			: Tuple             =   ["""past_key_values"""]
							UpperCamelCase__			: List[Any]             =   {
							    """hidden_size""": """n_embd""",
							    """max_position_embeddings""": """n_positions""",
							    """num_attention_heads""": """n_head""",
							    """num_hidden_layers""": """n_layer""",
							}


							def __init__(							self					,					a_=50_257					,					a_=1_024					,					a_=768					,					a_=12					,					a_=12					,					a_=None					,					a_="gelu_new"					,					a_=0.1					,					a_=0.1					,					a_=0.1					,					a_=1E-5					,					a_=0.02					,					a_="cls_index"					,					a_=True					,					a_=None					,					a_=True					,					a_=0.1					,					a_=True					,					a_=True					,					a_=50_256					,					a_=50_256					,					a_=False					,					a_=False					,					**a_					,					):
											a__			 =						vocab_size
											a__			 =						n_positions
											a__			 =						n_embd
											a__			 =						n_layer
											a__			 =						n_head
											a__			 =						n_inner
											a__			 =						activation_function
											a__			 =						resid_pdrop
											a__			 =						embd_pdrop
											a__			 =						attn_pdrop
											a__			 =						layer_norm_epsilon
											a__			 =						initializer_range
											a__			 =						summary_type
											a__			 =						summary_use_proj
											a__			 =						summary_activation
											a__			 =						summary_first_dropout
											a__			 =						summary_proj_to_labels
											a__			 =						scale_attn_weights
											a__			 =						use_cache
											a__			 =						scale_attn_by_inverse_layer_idx
											a__			 =						reorder_and_upcast_attn

											a__			 =						bos_token_id
											a__			 =						eos_token_id

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




class 	__snake_case (				SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							def __init__(							self					,					a_					,					a_ = "default"					,					a_ = None					,					a_ = False					,					):
											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						):
											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						):
											return self._config.n_layer


							@property
							def _a (							self						):
											return self._config.n_head


							def _a (							self					,					a_					,					a_ = -1					,					a_ = -1					,					a_ = False					,					a_ = None					,					):
											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						):
											return 13






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


UpperCAmelCase								=   logging.get_logger(__name__)

UpperCAmelCase								=   {
    """facebook/regnet-y-040""": """https://huggingface.co/facebook/regnet-y-040/blob/main/config.json""",
}

class 	__snake_case (				SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							UpperCamelCase__			: Tuple             =   """regnet"""
							UpperCamelCase__			: int             =   ["""x""", """y"""]


							def __init__(							self					,					a_=3					,					a_=32					,					a_=[128, 192, 512, 1_088]					,					a_=[2, 6, 12, 2]					,					a_=64					,					a_="y"					,					a_="relu"					,					**a_					,					):
											super().__init__(**a_						)
											if layer_type not in self.layer_types:
															raise ValueError(F'''layer_type={layer_type} is not one of {",".join(self.layer_types						)}'''						)
											a__			 =						num_channels
											a__			 =						embedding_size
											a__			 =						hidden_sizes
											a__			 =						depths
											a__			 =						groups_width
											a__			 =						layer_type
											a__			 =						hidden_act
											# always downsample in the first stage
											a__			 =						True

