



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


lowercase_										=  logging.get_logger(__name__)


lowercase_										=  {
    'Salesforce/codegen-350M-nl': 'https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json',
    'Salesforce/codegen-350M-multi': 'https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json',
    'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json',
    'Salesforce/codegen-2B-nl': 'https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json',
    'Salesforce/codegen-2B-multi': 'https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json',
    'Salesforce/codegen-2B-mono': 'https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json',
    'Salesforce/codegen-6B-nl': 'https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json',
    'Salesforce/codegen-6B-multi': 'https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json',
    'Salesforce/codegen-6B-mono': 'https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json',
    'Salesforce/codegen-16B-nl': 'https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json',
    'Salesforce/codegen-16B-multi': 'https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json',
    'Salesforce/codegen-16B-mono': 'https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json',
}
class 					_snake_case      (       _A):
				UpperCamelCase__					:       List[str]  		="""codegen"""
				UpperCamelCase__					:       str  		={
				    """max_position_embeddings""": """n_positions""",
				    """hidden_size""": """n_embd""",
				    """num_attention_heads""": """n_head""",
				    """num_hidden_layers""": """n_layer""",
				}




				def __init__(    self       :    List[str],       __lowercase       :    Optional[Any]=5_0400,       __lowercase       :    str=2048,       __lowercase       :    Union[str, Any]=2048,       __lowercase       :    Optional[int]=4096,       __lowercase       :    Any=28,       __lowercase       :    Any=16,       __lowercase       :    Any=64,       __lowercase       :    Optional[int]=None,       __lowercase       :    Optional[int]="gelu_new",       __lowercase       :    Optional[Any]=0.0,       __lowercase       :    Dict=0.0,       __lowercase       :    Union[str, Any]=0.0,       __lowercase       :    Dict=1e-5,       __lowercase       :    Tuple=0.02,       __lowercase       :    Optional[int]=True,       __lowercase       :    List[str]=5_0256,       __lowercase       :    Tuple=5_0256,       __lowercase       :    str=False,       **__lowercase       :    Dict,       ):
							lowercase__       	=					vocab_size
							lowercase__       	=					n_ctx
							lowercase__       	=					n_positions
							lowercase__       	=					n_embd
							lowercase__       	=					n_layer
							lowercase__       	=					n_head
							lowercase__       	=					n_inner
							lowercase__       	=					rotary_dim
							lowercase__       	=					activation_function
							lowercase__       	=					resid_pdrop
							lowercase__       	=					embd_pdrop
							lowercase__       	=					attn_pdrop
							lowercase__       	=					layer_norm_epsilon
							lowercase__       	=					initializer_range
							lowercase__       	=					use_cache

							lowercase__       	=					bos_token_id
							lowercase__       	=					eos_token_id

							super().__init__(
							    bos_token_id=UpperCamelCase__,       eos_token_id=UpperCamelCase__,       tie_word_embeddings=UpperCamelCase__,       **UpperCamelCase__    )
class 					_snake_case      (       _A):




				def __init__(    self       :    int,       __lowercase       :    PretrainedConfig,       __lowercase       :    str = "default",       __lowercase       :    List[PatchingSpec] = None,       __lowercase       :    bool = False,       ):
							super().__init__(UpperCamelCase__,       task=UpperCamelCase__,       patching_specs=UpperCamelCase__,       use_past=UpperCamelCase__    )
							if not getattr(self._config,       "pad_token_id",       UpperCamelCase__    ):
										# TODO: how to do that better?
										lowercase__       	=					0




				@property
				def 				A__   (    self       :    Any    ):
							lowercase__       	=					OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}    )
							if self.use_past:
										self.fill_with_past_key_values_(UpperCamelCase__,       direction="inputs"    )
										lowercase__       	=					{0: "batch", 1: "past_sequence + sequence"}
							else:
										lowercase__       	=					{0: "batch", 1: "sequence"}

							return common_inputs




				@property
				def 				A__   (    self       :    Optional[Any]    ):
							return self._config.n_layer




				@property
				def 				A__   (    self       :    List[Any]    ):
							return self._config.n_head




				def 				A__   (    self       :    List[str],       __lowercase       :    PreTrainedTokenizer,       __lowercase       :    int = -1,       __lowercase       :    int = -1,       __lowercase       :    bool = False,       __lowercase       :    Optional[TensorType] = None,       ):
							lowercase__       	=					super(UpperCamelCase__,       self    ).generate_dummy_inputs(
							    UpperCamelCase__,       batch_size=UpperCamelCase__,       seq_length=UpperCamelCase__,       is_pair=UpperCamelCase__,       framework=UpperCamelCase__    )

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

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

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

							return ordered_inputs




				@property
				def 				A__   (    self       :    Optional[int]    ):
							return 13






# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os

from accelerate.utils import ComputeEnvironment

from .cluster import get_cluster_input
from .config_args import cache_dir, default_config_file, default_yaml_config_file, load_config_from_file  # noqa: F401
from .config_utils import _ask_field, _ask_options, _convert_compute_environment  # noqa: F401
from .sagemaker import get_sagemaker_input


__lowerCAmelCase     :	Optional[Any]       			=  'Launches a series of prompts to create and save a `default_config.yaml` configuration file for your training system. Should always be ran first on your machine'

def a__       (			):






  '''simple docstring'''





  __magic_name__								=			_ask_options(
      """In which compute environment are you running?""",	["""This machine""", """AWS (Amazon SageMaker)"""],	_convert_compute_environment,	)
  if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
    __magic_name__								=			get_sagemaker_input()
  else:
    __magic_name__								=			get_cluster_input()
  return config

def a__       (			A_=None   ):






  '''simple docstring'''





  if subparsers is not None:
    __magic_name__								=			subparsers.add_parser("""config""",	description=A_   )
  else:
    __magic_name__								=			argparse.ArgumentParser("""Accelerate config command""",	description=A_   )

  parser.add_argument(
      """--config_file""",	default=A_,	help=(
          """The path to use to store the config file. Will default to a file named default_config.yaml in the cache """
          """location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have """
          """such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed """
          """with 'huggingface'."""
      ),	)

  if subparsers is not None:
    parser.set_defaults(func=A_   )
  return parser

def a__       (			A_   ):






  '''simple docstring'''





  __magic_name__								=			get_user_input()
  if args.config_file is not None:
    __magic_name__								=			args.config_file
  else:
    if not os.path.isdir(A_   ):
      os.makedirs(A_   )
    __magic_name__								=			default_yaml_config_file

  if config_file.endswith(""".json"""   ):
    config.to_json_file(A_   )
  else:
    config.to_yaml_file(A_   )
  print(f'''accelerate configuration saved at {config_file}'''   )

def a__       (			):






  '''simple docstring'''





  __magic_name__								=			config_command_parser()
  __magic_name__								=			parser.parse_args()
  config_command(A_   )


if __name__ == "__main__":
    main()

