


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


UpperCAmelCase    :     str   						=		[
    'EAGER',
    'AOT_EAGER',
    'INDUCTOR',
    'NVFUSER',
    'AOT_NVFUSER',
    'AOT_CUDAGRAPHS',
    'OFI',
    'FX2TRT',
    'ONNXRT',
    'IPEX',
]
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]       ,			_UpperCamelCase		:      Optional[int]=None       ,			_UpperCamelCase		:      Union[str, Any]=None       ,			_UpperCamelCase		:      Any=None							)		->       List[str]:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[int]      							=					True
							while ask_again:
														__UpperCAmelCase   :						Optional[int]      							=					input(_UpperCamelCase							)
														try:
																					if default is not None and len(_UpperCamelCase							) == 0:
																												return default
																					return convert_value(_UpperCamelCase							) if convert_value is not None else result
														except Exception:
																					if error_message is not None:
																												print(_UpperCamelCase							)
def      lowerCamelCase       (     _UpperCamelCase		:      Dict       ,			_UpperCamelCase		:      Union[str, Any]=[]       ,			_UpperCamelCase		:      Optional[Any]=None       ,			_UpperCamelCase		:      Optional[int]=0							)		->       Tuple:

							'''simple docstring'''



							__UpperCAmelCase   :						List[str]      							=					BulletMenu(_UpperCamelCase       ,			_UpperCamelCase							)
							__UpperCAmelCase   :						Any      							=					menu.run(default_choice=_UpperCamelCase							)
							return convert_value(_UpperCamelCase							) if convert_value is not None else result
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple							)		->       str:

							'''simple docstring'''



							__UpperCAmelCase   :						Dict      							=					int(_UpperCamelCase							)
							return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[Any]							)		->       str:

							'''simple docstring'''



							__UpperCAmelCase   :						str      							=					int(_UpperCamelCase							)
							return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]							)
def      lowerCamelCase       (     _UpperCamelCase		:      List[str]							)		->       int:

							'''simple docstring'''



							__UpperCAmelCase   :						int      							=					int(_UpperCamelCase							)
							return DynamoBackend(DYNAMO_BACKENDS[value]							).value
def      lowerCamelCase       (     _UpperCamelCase		:      Tuple							)		->       Tuple:

							'''simple docstring'''



							__UpperCAmelCase   :						Tuple      							=					int(_UpperCamelCase							)
							return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]							)
def      lowerCamelCase       (     _UpperCamelCase		:      Optional[int]							)		->       int:

							'''simple docstring'''



							__UpperCAmelCase   :						Optional[Any]      							=					int(_UpperCamelCase							)
							return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]							)
def      lowerCamelCase       (     _UpperCamelCase		:      int							)		->       Optional[Any]:

							'''simple docstring'''



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





class      lowerCamelCase__   (     argparse.RawDescriptionHelpFormatter				):







					"""simple docstring"""


					def lowerCamelCase__							(       self    : Tuple ,       UpperCamelCase    : Optional[Any] ,       UpperCamelCase    : Dict ,       UpperCamelCase    : Any ,       UpperCamelCase    : Tuple  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Dict      							=					super()._format_usage(UpperCamelCase ,       UpperCamelCase ,       UpperCamelCase ,       UpperCamelCase  )
												__UpperCAmelCase   :						Any      							=					usage.replace("""<command> [<args>] """ ,       """"""  )
												return usage




"""simple docstring"""






import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
							import ctypes
							import msvcrt  # noqa





							class      lowerCamelCase__   (     ctypes.Structure				):







												"""simple docstring"""


												__a	       =							[("""size""", ctypes.c_int), ("""visible""", ctypes.c_byte)]
def      lowerCamelCase       (     )		->       Optional[int]:

							'''simple docstring'''



							if os.name == "nt":
														__UpperCAmelCase   :						Dict      							=					CursorInfo()
														__UpperCAmelCase   :						Any      							=					ctypes.windll.kernelaa.GetStdHandle(-1_1							)
														ctypes.windll.kernelaa.GetConsoleCursorInfo(_UpperCamelCase       ,			ctypes.byref(_UpperCamelCase							)							)
														__UpperCAmelCase   :						Tuple      							=					False
														ctypes.windll.kernelaa.SetConsoleCursorInfo(_UpperCamelCase       ,			ctypes.byref(_UpperCamelCase							)							)
							elif os.name == "posix":
														sys.stdout.write("""\033[?25l"""							)
														sys.stdout.flush()
def      lowerCamelCase       (     )		->       Optional[int]:

							'''simple docstring'''



							if os.name == "nt":
														__UpperCAmelCase   :						str      							=					CursorInfo()
														__UpperCAmelCase   :						int      							=					ctypes.windll.kernelaa.GetStdHandle(-1_1							)
														ctypes.windll.kernelaa.GetConsoleCursorInfo(_UpperCamelCase       ,			ctypes.byref(_UpperCamelCase							)							)
														__UpperCAmelCase   :						Union[str, Any]      							=					True
														ctypes.windll.kernelaa.SetConsoleCursorInfo(_UpperCamelCase       ,			ctypes.byref(_UpperCamelCase							)							)
							elif os.name == "posix":
														sys.stdout.write("""\033[?25h"""							)
														sys.stdout.flush()
@contextmanager
def      lowerCamelCase       (     )		->       str:

							'''simple docstring'''



							try:
														hide_cursor()
														yield
							finally:
														show_cursor()
