
'''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

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


lowerCAmelCase					:    Dict           = [
    'EAGER',
    'AOT_EAGER',
    'INDUCTOR',
    'NVFUSER',
    'AOT_NVFUSER',
    'AOT_CUDAGRAPHS',
    'OFI',
    'FX2TRT',
    'ONNXRT',
    'IPEX',
]







def 		A_(     A						:		str		,     A						:		Tuple=None		,     A						:		int=None		,     A						:		Union[str, Any]=None):
							UpperCamelCase   			=     True
							while ask_again:
														UpperCamelCase   			=     input(A)
														try:
																					if default is not None and len(A) == 0:
																												return default
																					return convert_value(A) if convert_value is not None else result
														except Exception:
																					if error_message is not None:
																												print(A)







def 		A_(     A						:		Any		,     A						:		Union[str, Any]=[]		,     A						:		Dict=None		,     A						:		List[str]=0):
							UpperCamelCase   			=     BulletMenu(A		,     A)
							UpperCamelCase   			=     menu.run(default_choice=A)
							return convert_value(A) if convert_value is not None else result







def 		A_(     A						:		Tuple):
							UpperCamelCase   			=     int(A)
							return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value])







def 		A_(     A						:		List[str]):
							UpperCamelCase   			=     int(A)
							return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value])







def 		A_(     A						:		str):
							UpperCamelCase   			=     int(A)
							return DynamoBackend(DYNAMO_BACKENDS[value]).value







def 		A_(     A						:		Any):
							UpperCamelCase   			=     int(A)
							return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value])







def 		A_(     A						:		Optional[Any]):
							UpperCamelCase   			=     int(A)
							return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value])







def 		A_(     A						:		int):
							return {"yes": True, "no": False}[value.lower()]





class 			SCREAMING_SNAKE_CASE__      (     argparse.RawDescriptionHelpFormatter):







				def 						UpperCAmelCase_    (       self						,				A_						,				A_						,				A_						,				A_     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     super()._format_usage(A_						,				A_						,				A_						,				A_     )
											UpperCamelCase   			=     usage.replace('<command> [<args>] '						,				''     )
											return usage





from typing import List

from .keymap import KEYMAP, get_character
def 					_snake_case	(  __snake_case						):

					def decorator(__snake_case						):
										_UpperCamelCase			     =     getattr(__snake_case  ,     '''handle_key'''  ,     []						)
										handle += [key]
										setattr(__snake_case  ,     '''handle_key'''  ,     __snake_case						)
										return func

					return decorator
def 					_snake_case	(  *__snake_case						):

					def decorator(__snake_case						):
										_UpperCamelCase			     =     getattr(__snake_case  ,     '''handle_key'''  ,     []						)
										handle += keys
										setattr(__snake_case  ,     '''handle_key'''  ,     __snake_case						)
										return func

					return decorator
class     lowerCAmelCase_     (       __lowercase ):







							def __new__(   cls      :     Optional[Any] ,			_A      :     Optional[Any] ,			_A      :     Optional[int] ,			_A      :     Union[str, Any]		):
												_UpperCamelCase			     =     super().__new__(cls ,			_A ,			_A ,			_A		)
												if not hasattr(_A ,			'''key_handler'''		):
																	setattr(_A ,			'''key_handler''' ,			{}		)
												setattr(_A ,			'''handle_input''' ,			KeyHandler.handle_input		)

												for value in attrs.values():
																	_UpperCamelCase			     =     getattr(_A ,			'''handle_key''' ,			[]		)
																	for key in handled_keys:
																						_UpperCamelCase			     =     value
												return new_cls







							@staticmethod
							def  UpperCamelCase_						(   cls      :     str		):
												_UpperCamelCase			     =     get_character()
												if char != KEYMAP["undefined"]:
																	_UpperCamelCase			     =     ord(_A		)
												_UpperCamelCase			     =     cls.key_handler.get(_A		)
												if handler:
																	_UpperCamelCase			     =     char
																	return handler(cls		)
												else:
																	return None




def 					_snake_case	(  cls						):
					return KeyHandler(cls.__name__  ,     cls.__bases__  ,     cls.__dict__.copy()						)
