"""simple docstring"""






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

from packaging import version


if TYPE_CHECKING:
						from ... import PreTrainedTokenizer, TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import is_torch_available, logging


lowerCAmelCase__						:						List[str]		  =			logging.get_logger(__name__)

lowerCAmelCase__						:						Tuple		  =			{
    'bigscience/bloom': 'https://huggingface.co/bigscience/bloom/resolve/main/config.json',
    'bigscience/bloom-560m': 'https://huggingface.co/bigscience/bloom-560m/blob/main/config.json',
    'bigscience/bloom-1b1': 'https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json',
    'bigscience/bloom-1b7': 'https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json',
    'bigscience/bloom-3b': 'https://huggingface.co/bigscience/bloom-3b/blob/main/config.json',
    'bigscience/bloom-7b1': 'https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json',
}
class        snake_case (				__UpperCAmelCase       ):




		"""simple docstring"""

		snake_case__       					=				"bloom"
		snake_case__       					=				["past_key_values"]
		snake_case__       					=				{
		    "num_hidden_layers": "n_layer",
		    "num_attention_heads": "n_head",
		}







		def __init__(       self     :			List[Any]					,lowerCamelCase__     :			Optional[Any]=250_880					,lowerCamelCase__     :			int=64					,lowerCamelCase__     :			List[Any]=2					,lowerCamelCase__     :			int=8					,lowerCamelCase__     :			int=1e-5					,lowerCamelCase__     :			Dict=0.0_2					,lowerCamelCase__     :			int=True					,lowerCamelCase__     :			Optional[int]=1					,lowerCamelCase__     :			Tuple=2					,lowerCamelCase__     :			str=False					,lowerCamelCase__     :			Optional[Any]=0.0					,lowerCamelCase__     :			List[Any]=0.0					,lowerCamelCase__     :			Any=1					,lowerCamelCase__     :			Tuple=False					,**lowerCamelCase__     :			str					,):
						UpperCAmelCase__    =							vocab_size
						# Backward compatibility with n_embed kwarg
						UpperCAmelCase__    =							kwargs.pop('n_embed'					,lowerCamelCase__    )
						UpperCAmelCase__    =							hidden_size if n_embed is None else n_embed
						UpperCAmelCase__    =							n_layer
						UpperCAmelCase__    =							n_head
						UpperCAmelCase__    =							layer_norm_epsilon
						UpperCAmelCase__    =							initializer_range
						UpperCAmelCase__    =							use_cache
						UpperCAmelCase__    =							pretraining_tp
						UpperCAmelCase__    =							apply_residual_connection_post_layernorm
						UpperCAmelCase__    =							hidden_dropout
						UpperCAmelCase__    =							attention_dropout

						UpperCAmelCase__    =							bos_token_id
						UpperCAmelCase__    =							eos_token_id
						UpperCAmelCase__    =							slow_but_exact

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






class        snake_case (				__UpperCAmelCase       ):




		"""simple docstring"""

		snake_case__       					=				version.parse("1.12"       )







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







		@property
		def 	__lowerCAmelCase		(       self     :			Tuple    ):
						UpperCAmelCase__    =							OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}    )
						if self.use_past:
										# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
										self.fill_with_past_key_values_(lowerCamelCase__					,direction='inputs'					,inverted_values_shape=lowerCamelCase__    )
										UpperCAmelCase__    =							{0: 'batch', 1: 'past_sequence + sequence'}
						else:
										UpperCAmelCase__    =							{0: 'batch', 1: 'sequence'}

						return common_inputs







		@property
		def 	__lowerCAmelCase		(       self     :			Dict    ):
						return self._config.n_layer







		@property
		def 	__lowerCAmelCase		(       self     :			Any    ):
						return self._config.n_head







		@property
		def 	__lowerCAmelCase		(       self     :			Any    ):
						return 1e-3







		def 	__lowerCAmelCase		(       self     :			List[Any]					,lowerCamelCase__     :			"PreTrainedTokenizer"					,lowerCamelCase__     :			int = -1					,lowerCamelCase__     :			int = -1					,lowerCamelCase__     :			bool = False					,lowerCamelCase__     :			Optional["TensorType"] = None					,):
						UpperCAmelCase__    =							super(lowerCamelCase__					,self    ).generate_dummy_inputs(
						    lowerCamelCase__					,batch_size=lowerCamelCase__					,seq_length=lowerCamelCase__					,is_pair=lowerCamelCase__					,framework=lowerCamelCase__    )

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

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

						UpperCAmelCase__    =							common_inputs['attention_mask']
						if self.use_past:
										UpperCAmelCase__    =							ordered_inputs['attention_mask'].dtype
										UpperCAmelCase__    =							torch.cat(
										    [ordered_inputs['attention_mask'], torch.ones(lowerCamelCase__					,lowerCamelCase__					,dtype=lowerCamelCase__    )]					,dim=1    )

						return ordered_inputs







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




"""simple docstring"""






# 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__						:						Dict		  =			'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_		(      ):
				UpperCAmelCase__    =							_ask_options(
				    'In which compute environment are you running?'      ,    ['This machine', 'AWS (Amazon SageMaker)']      ,    _convert_compute_environment      ,    )
				if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
								UpperCAmelCase__    =							get_sagemaker_input()
				else:
								UpperCAmelCase__    =							get_cluster_input()
				return config



def 						a_		(      lowerCamelCase=None ):
				if subparsers is not None:
								UpperCAmelCase__    =							subparsers.add_parser('config'      ,    description=lowerCamelCase )
				else:
								UpperCAmelCase__    =							argparse.ArgumentParser('Accelerate config command'      ,    description=lowerCamelCase )

				parser.add_argument(
				    '--config_file'      ,    default=lowerCamelCase      ,    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=lowerCamelCase )
				return parser



def 						a_		(      lowerCamelCase ):
				UpperCAmelCase__    =							get_user_input()
				if args.config_file is not None:
								UpperCAmelCase__    =							args.config_file
				else:
								if not os.path.isdir(lowerCamelCase ):
												os.makedirs(lowerCamelCase )
								UpperCAmelCase__    =							default_yaml_config_file

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



def 						a_		(      ):
				UpperCAmelCase__    =							config_command_parser()
				UpperCAmelCase__    =							parser.parse_args()
				config_command(lowerCamelCase )


if __name__ == "__main__":
						main()



