
# 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_						     =					[
    '''EAGER''',
    '''AOT_EAGER''',
    '''INDUCTOR''',
    '''NVFUSER''',
    '''AOT_NVFUSER''',
    '''AOT_CUDAGRAPHS''',
    '''OFI''',
    '''FX2TRT''',
    '''ONNXRT''',
    '''IPEX''',
]






def 						__magic_name__			(   __a      :	Dict	,		__a      :	str=None	,		__a      :	List[Any]=None	,		__a      :	List[str]=None						):



     '''simple docstring'''




     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 						__magic_name__			(   __a      :	Optional[Any]	,		__a      :	int=[]	,		__a      :	Tuple=None	,		__a      :	Union[str, Any]=0						):



     '''simple docstring'''




     UpperCamelCase__				=    BulletMenu(__a	,		__a						)
     UpperCamelCase__				=    menu.run(default_choice=__a						)
     return convert_value(__a						) if convert_value is not None else result






def 						__magic_name__			(   __a      :	Tuple						):



     '''simple docstring'''




     UpperCamelCase__				=    int(__a						)
     return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]						)






def 						__magic_name__			(   __a      :	Dict						):



     '''simple docstring'''




     UpperCamelCase__				=    int(__a						)
     return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]						)






def 						__magic_name__			(   __a      :	Optional[Any]						):



     '''simple docstring'''




     UpperCamelCase__				=    int(__a						)
     return DynamoBackend(DYNAMO_BACKENDS[value]						).value






def 						__magic_name__			(   __a      :	Tuple						):



     '''simple docstring'''




     UpperCamelCase__				=    int(__a						)
     return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]						)






def 						__magic_name__			(   __a      :	List[str]						):



     '''simple docstring'''




     UpperCamelCase__				=    int(__a						)
     return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]						)






def 						__magic_name__			(   __a      :	int						):



     '''simple docstring'''




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




class      __A(    argparse.RawDescriptionHelpFormatter			):

  """simple docstring"""







  def 	UpperCAmelCase_ (self	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						):
       UpperCamelCase__				=    super()._format_usage(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    usage.replace("""<command> [<args>] """	,      """"""						)
       return usage







def 						__magic_name__			(   __a      :	int	,		__a      :	int						):



     '''simple docstring'''




     while a != 0:
          UpperCamelCase__		,	UpperCamelCase__				=    b % a, a
     return b






def 						__magic_name__			(   __a      :	int	,		__a      :	int						):



     '''simple docstring'''




     if gcd(__a	,		__a						) != 1:
          UpperCamelCase__				=    f"mod inverse of {a!r} and {m!r} does not exist"
          raise ValueError(__a						)
     UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__				=    1, 0, a
     UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__				=    0, 1, m
     while va != 0:
          UpperCamelCase__				=    ua // va
          UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__		,	UpperCamelCase__				=    (ua - q * va), (ua - q * va), (ua - q * va), va, va, va
     return ua % m





