





"""simple docstring"""





import argparse
import os
import re


__A											=		'src/transformers'

# Pattern that looks at the indentation in a line.
__A											=		re.compile(R"""^(\s*)\S""")
# Pattern that matches `"key":" and puts `key` in group 0.
__A											=		re.compile(R"""^\s*\"([^\"]+)\":""")
# Pattern that matches `_import_structure["key"]` and puts `key` in group 0.
__A											=		re.compile(R"""^\s*_import_structure\[\"([^\"]+)\"\]""")
# Pattern that matches `"key",` and puts `key` in group 0.
__A											=		re.compile(R"""^\s*\"([^\"]+)\",\s*$""")
# Pattern that matches any `[stuff]` and puts `stuff` in group 0.
__A											=		re.compile(R"""\[([^\]]+)\]""")
def  __A   (_SCREAMING_SNAKE_CASE			)					->Any:





  """simple docstring"""


  lowerCAmelCase__			:Tuple											=							_re_indent.search(_SCREAMING_SNAKE_CASE			)
  return "" if search is None else search.groups()[0]
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE=""     ,   _SCREAMING_SNAKE_CASE=None     ,   _SCREAMING_SNAKE_CASE=None			)					->str:





  """simple docstring"""


  lowerCAmelCase__			:Any											=							0
  lowerCAmelCase__			:Any											=							code.split('\n'			)
  if start_prompt is not None:
    while not lines[index].startswith(_SCREAMING_SNAKE_CASE			):
      index += 1
    lowerCAmelCase__			:Optional[int]											=							['\n'.join(lines[:index]			)]
  else:
    lowerCAmelCase__			:Any											=							[]

  # We split into blocks until we get to the `end_prompt` (or the end of the block).
  lowerCAmelCase__			:List[str]											=							[lines[index]]
  index += 1
  while index < len(_SCREAMING_SNAKE_CASE			) and (end_prompt is None or not lines[index].startswith(_SCREAMING_SNAKE_CASE			)):
    if len(lines[index]			) > 0 and get_indent(lines[index]			) == indent_level:
      if len(_SCREAMING_SNAKE_CASE			) > 0 and get_indent(current_block[-1]			).startswith(indent_level + ' '			):
        current_block.append(lines[index]			)
        blocks.append('\n'.join(_SCREAMING_SNAKE_CASE			)			)
        if index < len(_SCREAMING_SNAKE_CASE			) - 1:
          lowerCAmelCase__			:str											=							[lines[index + 1]]
          index += 1
        else:
          lowerCAmelCase__			:Optional[int]											=							[]
      else:
        blocks.append('\n'.join(_SCREAMING_SNAKE_CASE			)			)
        lowerCAmelCase__			:List[Any]											=							[lines[index]]
    else:
      current_block.append(lines[index]			)
    index += 1

  # Adds current block if it's nonempty.
  if len(_SCREAMING_SNAKE_CASE			) > 0:
    blocks.append('\n'.join(_SCREAMING_SNAKE_CASE			)			)

  # Add final block after end_prompt if provided.
  if end_prompt is not None and index < len(_SCREAMING_SNAKE_CASE			):
    blocks.append('\n'.join(lines[index:]			)			)

  return blocks
def  __A   (_SCREAMING_SNAKE_CASE			)					->int:





  """simple docstring"""


  def _inner(_SCREAMING_SNAKE_CASE			):
    return key(_SCREAMING_SNAKE_CASE			).lower().replace('_'     ,   ''			)

  return _inner
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE=None			)					->Optional[int]:





  """simple docstring"""


  def noop(_SCREAMING_SNAKE_CASE			):
    return x

  if key is None:
    lowerCAmelCase__			:List[Any]											=							noop
  # Constants are all uppercase, they go first.
  lowerCAmelCase__			:List[str]											=							[obj for obj in objects if key(_SCREAMING_SNAKE_CASE			).isupper()]
  # Classes are not all uppercase but start with a capital, they go second.
  lowerCAmelCase__			:Any											=							[obj for obj in objects if key(_SCREAMING_SNAKE_CASE			)[0].isupper() and not key(_SCREAMING_SNAKE_CASE			).isupper()]
  # Functions begin with a lowercase, they go last.
  lowerCAmelCase__			:int											=							[obj for obj in objects if not key(_SCREAMING_SNAKE_CASE			)[0].isupper()]

  lowerCAmelCase__			:Optional[int]											=							ignore_underscore(_SCREAMING_SNAKE_CASE			)
  return sorted(_SCREAMING_SNAKE_CASE     ,   key=_SCREAMING_SNAKE_CASE			) + sorted(_SCREAMING_SNAKE_CASE     ,   key=_SCREAMING_SNAKE_CASE			) + sorted(_SCREAMING_SNAKE_CASE     ,   key=_SCREAMING_SNAKE_CASE			)
def  __A   (_SCREAMING_SNAKE_CASE			)					->str:





  """simple docstring"""


  def _replace(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:Any											=							match.groups()[0]
    if "," not in imports:
      return F"[{imports}]"
    lowerCAmelCase__			:Optional[Any]											=							[part.strip().replace('\"'     ,   ''			) for part in imports.split(','			)]
    # We will have a final empty element if the line finished with a comma.
    if len(keys[-1]			) == 0:
      lowerCAmelCase__			:Dict											=							keys[:-1]
    return "[" + ", ".join([F"\"{k}\"" for k in sort_objects(_SCREAMING_SNAKE_CASE			)]			) + "]"

  lowerCAmelCase__			:List[str]											=							import_statement.split('\n'			)
  if len(_SCREAMING_SNAKE_CASE			) > 3:
    # Here we have to sort internal imports that are on several lines (one per name):
    # key: [
    #     "object1",
    #     "object2",
    #     ...
    # ]

    # We may have to ignore one or two lines on each side.
    lowerCAmelCase__			:Any											=							2 if lines[1].strip() == '[' else 1
    lowerCAmelCase__			:List[Any]											=							[(i, _re_strip_line.search(_SCREAMING_SNAKE_CASE			).groups()[0]) for i, line in enumerate(lines[idx:-idx]			)]
    lowerCAmelCase__			:Tuple											=							sort_objects(_SCREAMING_SNAKE_CASE     ,   key=lambda _SCREAMING_SNAKE_CASE			: x[1]			)
    lowerCAmelCase__			:Optional[int]											=							[lines[x[0] + idx] for x in sorted_indices]
    return "\n".join(lines[:idx] + sorted_lines + lines[-idx:]			)
  elif len(_SCREAMING_SNAKE_CASE			) == 3:
    # Here we have to sort internal imports that are on one separate line:
    # key: [
    #     "object1", "object2", ...
    # ]
    if _re_bracket_content.search(lines[1]			) is not None:
      lowerCAmelCase__			:str											=							_re_bracket_content.sub(_replace     ,   lines[1]			)
    else:
      lowerCAmelCase__			:List[str]											=							[part.strip().replace('\"'     ,   ''			) for part in lines[1].split(','			)]
      # We will have a final empty element if the line finished with a comma.
      if len(keys[-1]			) == 0:
        lowerCAmelCase__			:Any											=							keys[:-1]
      lowerCAmelCase__			:Dict											=							get_indent(lines[1]			) + ', '.join([F"\"{k}\"" for k in sort_objects(_SCREAMING_SNAKE_CASE			)]			)
    return "\n".join(_SCREAMING_SNAKE_CASE			)
  else:
    # Finally we have to deal with imports fitting on one line
    lowerCAmelCase__			:Tuple											=							_re_bracket_content.sub(_replace     ,   _SCREAMING_SNAKE_CASE			)
    return import_statement
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE=True			)					->str:





  """simple docstring"""


  with open(_SCREAMING_SNAKE_CASE     ,   encoding='utf-8'			) as f:
    lowerCAmelCase__			:List[Any]											=							f.read()

  if "_import_structure" not in code:
    return

  # Blocks of indent level 0
  lowerCAmelCase__			:Union[str, Any]											=							split_code_in_indented_blocks(
      _SCREAMING_SNAKE_CASE     ,   start_prompt='_import_structure = {'     ,   end_prompt='if TYPE_CHECKING:'			)

  # We ignore block 0 (everything untils start_prompt) and the last block (everything after end_prompt).
  for block_idx in range(1     ,   len(_SCREAMING_SNAKE_CASE			) - 1			):
    # Check if the block contains some `_import_structure`s thingy to sort.
    lowerCAmelCase__			:Any											=							main_blocks[block_idx]
    lowerCAmelCase__			:List[str]											=							block.split('\n'			)

    # Get to the start of the imports.
    lowerCAmelCase__			:Union[str, Any]											=							0
    while line_idx < len(_SCREAMING_SNAKE_CASE			) and "_import_structure" not in block_lines[line_idx]:
      # Skip dummy import blocks
      if "import dummy" in block_lines[line_idx]:
        lowerCAmelCase__			:List[Any]											=							len(_SCREAMING_SNAKE_CASE			)
      else:
        line_idx += 1
    if line_idx >= len(_SCREAMING_SNAKE_CASE			):
      continue

    # Ignore beginning and last line: they don't contain anything.
    lowerCAmelCase__			:Optional[int]											=							'\n'.join(block_lines[line_idx:-1]			)
    lowerCAmelCase__			:Union[str, Any]											=							get_indent(block_lines[1]			)
    # Slit the internal block into blocks of indent level 1.
    lowerCAmelCase__			:Optional[int]											=							split_code_in_indented_blocks(_SCREAMING_SNAKE_CASE     ,   indent_level=_SCREAMING_SNAKE_CASE			)
    # We have two categories of import key: list or _import_structure[key].append/extend
    lowerCAmelCase__			:Dict											=							_re_direct_key if '_import_structure = {' in block_lines[0] else _re_indirect_key
    # Grab the keys, but there is a trap: some lines are empty or just comments.
    lowerCAmelCase__			:Optional[int]											=							[(pattern.search(_SCREAMING_SNAKE_CASE			).groups()[0] if pattern.search(_SCREAMING_SNAKE_CASE			) is not None else None) for b in internal_blocks]
    # We only sort the lines with a key.
    lowerCAmelCase__			:Any											=							[(i, key) for i, key in enumerate(_SCREAMING_SNAKE_CASE			) if key is not None]
    lowerCAmelCase__			:Any											=							[x[0] for x in sorted(_SCREAMING_SNAKE_CASE     ,   key=lambda _SCREAMING_SNAKE_CASE			: x[1]			)]

    # We reorder the blocks by leaving empty lines/comments as they were and reorder the rest.
    lowerCAmelCase__			:Dict											=							0
    lowerCAmelCase__			:Optional[int]											=							[]
    for i in range(len(_SCREAMING_SNAKE_CASE			)			):
      if keys[i] is None:
        reorderded_blocks.append(internal_blocks[i]			)
      else:
        lowerCAmelCase__			:str											=							sort_objects_in_import(internal_blocks[sorted_indices[count]]			)
        reorderded_blocks.append(_SCREAMING_SNAKE_CASE			)
        count += 1

        # And we put our main block back together with its first and last line.
    lowerCAmelCase__			:Optional[int]											=							'\n'.join(block_lines[:line_idx] + reorderded_blocks + [block_lines[-1]]			)

  if code != "\n".join(_SCREAMING_SNAKE_CASE			):
    if check_only:
      return True
    else:
      print(F"Overwriting {file}."			)
      with open(_SCREAMING_SNAKE_CASE     ,   'w'     ,   encoding='utf-8'			) as f:
        f.write('\n'.join(_SCREAMING_SNAKE_CASE			)			)
def  __A   (_SCREAMING_SNAKE_CASE=True			)					->List[str]:





  """simple docstring"""


  lowerCAmelCase__			:Optional[Any]											=							[]
  for root, _, files in os.walk(_SCREAMING_SNAKE_CASE			):
    if "__init__.py" in files:
      lowerCAmelCase__			:Union[str, Any]											=							sort_imports(os.path.join(_SCREAMING_SNAKE_CASE     ,   '__init__.py'			)     ,   check_only=_SCREAMING_SNAKE_CASE			)
      if result:
        lowerCAmelCase__			:Dict											=							[os.path.join(_SCREAMING_SNAKE_CASE     ,   '__init__.py'			)]
  if len(_SCREAMING_SNAKE_CASE			) > 0:
    raise ValueError(F"Would overwrite {len(_SCREAMING_SNAKE_CASE			)} files, run `make style`."			)


if __name__ == "__main__":
  __A											=		argparse.ArgumentParser()
  parser.add_argument("""--check_only""", action="""store_true""", help="""Whether to only check or fix style.""")
  __A											=		parser.parse_args()

  sort_imports_in_all_inits(check_only=args.check_only)







'''simple docstring'''







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


lowerCAmelCase_					:    Dict      	=			logging.get_logger(__name__)

lowerCAmelCase_					:    int      	=			{
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            ='gpt_bigcode'
				__a            =['past_key_values']
				__a            ={
				    'hidden_size': 'n_embd',
				    'max_position_embeddings': 'n_positions',
				    'num_attention_heads': 'n_head',
				    'num_hidden_layers': 'n_layer',
				}




				def __init__(  self     :					Optional[Any]					,				__a     :					Tuple=5_02_57					,				__a     :					str=10_24					,				__a     :					Dict=7_68					,				__a     :					Tuple=12					,				__a     :					str=12					,				__a     :					Optional[int]=None					,				__a     :					Dict="gelu_pytorch_tanh"					,				__a     :					Tuple=0.1					,				__a     :					Tuple=0.1					,				__a     :					Union[str, Any]=0.1					,				__a     :					Tuple=1e-5					,				__a     :					str=0.02					,				__a     :					Dict=True					,				__a     :					Union[str, Any]=True					,				__a     :					Optional[int]=5_02_56					,				__a     :					Optional[int]=5_02_56					,				__a     :					Union[str, Any]=True					,				__a     :					Dict=True					,				__a     :					Union[str, Any]=True					,				**__a     :					List[Any]					,				):
								_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								= scale_attn_weights
								_a								= use_cache
								_a								= attention_softmax_in_fpaa
								_a								= scale_attention_softmax_in_fpaa
								_a								= multi_query

								_a								= bos_token_id
								_a								= eos_token_id

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