
"""simple docstring"""







from collections import OrderedDict
from typing import Any, Mapping, Optional

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


_SCREAMING_SNAKE_CASE	       =logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE	       ={
    """EleutherAI/gpt-neo-1.3B""": """https://huggingface.co/EleutherAI/gpt-neo-1.3B/resolve/main/config.json""",
    # See all GPTNeo models at https://huggingface.co/models?filter=gpt_neo
}







class 							__magic_name__     (		lowercase__   ):
					_SCREAMING_SNAKE_CASE       :					Tuple     							=   'gpt_neo'
					_SCREAMING_SNAKE_CASE       :					str     							=   ['past_key_values']
					_SCREAMING_SNAKE_CASE       :					List[str]     							=   {'num_attention_heads': 'num_heads', 'num_hidden_layers': 'num_layers'}





					def __init__(				self   :							Optional[Any]							,						snake_case_   :							List[Any]=50257							,						snake_case_   :							Union[str, Any]=2048							,						snake_case_   :							Optional[Any]=2048							,						snake_case_   :							List[Any]=24							,						snake_case_   :							Optional[int]=[[["global", "local"], 12]]							,						snake_case_   :							Optional[int]=16							,						snake_case_   :							Optional[int]=None							,						snake_case_   :							Dict=256							,						snake_case_   :							Dict="gelu_new"							,						snake_case_   :							Optional[int]=0.0							,						snake_case_   :							List[str]=0.0							,						snake_case_   :							int=0.0							,						snake_case_   :							List[str]=0.1							,						snake_case_   :							Optional[int]=1e-5							,						snake_case_   :							List[Any]=0.02							,						snake_case_   :							Tuple=True							,						snake_case_   :							int=50256							,						snake_case_   :							Tuple=50256							,						**snake_case_   :							int							,						):
												__snake_case     			=       vocab_size
												__snake_case     			=       max_position_embeddings
												__snake_case     			=       hidden_size
												__snake_case     			=       num_layers
												__snake_case     			=       num_heads
												__snake_case     			=       intermediate_size
												__snake_case     			=       window_size
												__snake_case     			=       activation_function
												__snake_case     			=       resid_dropout
												__snake_case     			=       embed_dropout
												__snake_case     			=       attention_dropout
												__snake_case     			=       classifier_dropout
												__snake_case     			=       layer_norm_epsilon
												__snake_case     			=       initializer_range
												__snake_case     			=       use_cache

												__snake_case     			=       bos_token_id
												__snake_case     			=       eos_token_id

												__snake_case     			=       attention_types
												__snake_case     			=       self.expand_attention_types_params(snake_case_    )

												if len(self.attention_layers    ) != self.num_layers:
																			raise ValueError(
																			    "Configuration for convolutional module is incorrect. "
																			    "It is required that `len(config.attention_layers)` == `config.num_layers` "
																			    F'''but is `len(config.attention_layers) = {len(self.attention_layers    )}`, '''
																			    F'''`config.num_layers = {self.num_layers}`. '''
																			    "`config.attention_layers` is prepared using `config.attention_types`. "
																			    "Please verify the value of `config.attention_types` argument."    )

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





					@staticmethod
					def 							lowerCAmelCase      (				snake_case_   :							Optional[int]    ):
												__snake_case     			=       []
												for item in attention_types:
																			for _ in range(item[1]    ):
																										attentions.extend(item[0]    )
												return attentions




def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     str:







							"""simple docstring"""


							import torch

							__snake_case     			=       input.size()
							__snake_case     			=       len(SCREAMING_SNAKE_CASE )
							__snake_case     			=       shape[dimension]

							__snake_case     			=       torch.arange(0							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )
							__snake_case     			=       torch.div(sizedim - size							,    SCREAMING_SNAKE_CASE							,    rounding_mode="floor" ) + 1
							__snake_case     			=       torch.arange(SCREAMING_SNAKE_CASE ) + low_indices[:min_length][:, None]

							__snake_case     			=       [slice(SCREAMING_SNAKE_CASE )] * rank
							__snake_case     			=       indices
							__snake_case     			=       input[s]

							__snake_case     			=       list(range(0							,    rank + 1 ) )
							perm.append(perm.pop(dimension + 1 ) )

							return sliced.permute(SCREAMING_SNAKE_CASE )
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )  ->     int:







							"""simple docstring"""


							import torch

							__snake_case     			=       torch.arange(1							,    SCREAMING_SNAKE_CASE )
							__snake_case     			=       torch.remainder(SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE )
							__snake_case     			=       remainders == 0
							__snake_case     			=       candidates[divisor_indices]
							__snake_case     			=       torch.max(SCREAMING_SNAKE_CASE )
							return largest_divisor, torch.div(SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    rounding_mode="floor" )







class 							__magic_name__     (		lowercase__   ):





					@property
					def 							lowerCAmelCase      (				self   :							Optional[Any]    ):
												__snake_case     			=       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}    )
												if self.use_past:
																			self.fill_with_past_key_values_(snake_case_							,						direction="inputs"    )
																			__snake_case     			=       {0: "batch", 1: "past_sequence + sequence"}
												else:
																			__snake_case     			=       {0: "batch", 1: "sequence"}

												return common_inputs





					@property
					def 							lowerCAmelCase      (				self   :							str    ):
												return self._config.num_heads





					def 							lowerCAmelCase      (				self   :							Tuple							,						snake_case_   :							PreTrainedTokenizer							,						snake_case_   :							int = -1							,						snake_case_   :							int = -1							,						snake_case_   :							bool = False							,						snake_case_   :							Optional[TensorType] = None							,						):
												__snake_case     			=       super(snake_case_							,						self    ).generate_dummy_inputs(
												    snake_case_							,						batch_size=snake_case_							,						seq_length=snake_case_							,						is_pair=snake_case_							,						framework=snake_case_    )

												# We need to order the input in the way they appears in the forward()
												__snake_case     			=       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

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

												__snake_case     			=       common_inputs["attention_mask"]
												if self.use_past:
																			__snake_case     			=       ordered_inputs["attention_mask"].dtype
																			__snake_case     			=       torch.cat(
																			    [ordered_inputs["attention_mask"], torch.ones(snake_case_							,						snake_case_							,						dtype=snake_case_    )]							,						dim=1    )

												return ordered_inputs





					@property
					def 							lowerCAmelCase      (				self   :							str    ):
												return 13


"""simple docstring"""







import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     str:







							"""simple docstring"""


							__snake_case     			=       []
							for line in lines:
														__snake_case     			=       re.sub(r"#.*"							,    ""							,    SCREAMING_SNAKE_CASE )  # remove comments
														if line:
																					filtered_lines.append(SCREAMING_SNAKE_CASE )
							__snake_case     			=       "\n".join(SCREAMING_SNAKE_CASE )

							# Make a hash from all this code
							__snake_case     			=       full_str.encode("utf-8" )
							return shaaaa(SCREAMING_SNAKE_CASE ).hexdigest()


# get importable module names and hash for caching
_SCREAMING_SNAKE_CASE	       =      {
    """csv""": (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    """json""": (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    """pandas""": (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    """parquet""": (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    """arrow""": (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    """text""": (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    """imagefolder""": (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    """audiofolder""": (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
_SCREAMING_SNAKE_CASE	       =      {
    """.csv""": ("""csv""", {}),
    """.tsv""": ("""csv""", {"""sep""": """\t"""}),
    """.json""": ("""json""", {}),
    """.jsonl""": ("""json""", {}),
    """.parquet""": ("""parquet""", {}),
    """.arrow""": ("""arrow""", {}),
    """.txt""": ("""text""", {}),
}
_EXTENSION_TO_MODULE.update({ext: ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_SCREAMING_SNAKE_CASE	       =      {"""imagefolder""", """audiofolder"""}

# Used to filter data files based on extensions given a module name
_SCREAMING_SNAKE_CASE	       =      {}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
		_MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append(""".zip""")



_MODULE_TO_EXTENSIONS["audiofolder"].append(""".zip""")
