





# 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 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase		,      _UpperCAmelCase=None		,      _UpperCAmelCase=None		,      _UpperCAmelCase=None					)     ->	List[str]:
    lowerCamelCase__       : Dict   					=						True
    while ask_again:
        lowerCamelCase__       : List[str]   					=						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 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase		,      _UpperCAmelCase=[]		,      _UpperCAmelCase=None		,      _UpperCAmelCase=0					)     ->	Dict:
    lowerCamelCase__       : str   					=						BulletMenu(_UpperCAmelCase		,      _UpperCAmelCase					)
    lowerCamelCase__       : Tuple   					=						menu.run(default_choice=_UpperCAmelCase					)
    return convert_value(_UpperCAmelCase					) if convert_value is not None else result


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	Union[str, Any]:
    lowerCamelCase__       : Optional[int]   					=						int(_UpperCAmelCase					)
    return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value]					)


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	Dict:
    lowerCamelCase__       : Any   					=						int(_UpperCAmelCase					)
    return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value]					)


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	Any:
    lowerCamelCase__       : Optional[Any]   					=						int(_UpperCAmelCase					)
    return DynamoBackend(DYNAMO_BACKENDS[value]					).value


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	List[Any]:
    lowerCamelCase__       : Tuple   					=						int(_UpperCAmelCase					)
    return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value]					)


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	Optional[Any]:
    lowerCamelCase__       : Tuple   					=						int(_UpperCAmelCase					)
    return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value]					)


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	Tuple:
    return {"yes": True, "no": False}[value.lower()]


class   lowerCAmelCase				(   argparse.RawDescriptionHelpFormatter     ):
 def 	A_      ( self    : List[Any]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : Union[str, Any]     ,	UpperCAmelCase    : Optional[int]      )     ->      Any:
     lowerCamelCase__       : List[str]   					=						super()._format_usage(UpperCAmelCase     ,	UpperCAmelCase     ,	UpperCAmelCase     ,	UpperCAmelCase      )
     lowerCamelCase__       : int   					=						usage.replace('<command> [<args>] '     ,	''      )
     return usage












def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase		,      _UpperCAmelCase					)     ->	Union[str, Any]:
    lowerCamelCase__       : List[Any]   					=						[1]
    for i in range(2		,      _UpperCAmelCase					):
        factorials.append(factorials[-1] * i					)
    assert 0 <= k < factorials[-1] * n, "k out of bounds"

    lowerCamelCase__       : str   					=						[]
    lowerCamelCase__       : Optional[Any]   					=						list(range(_UpperCAmelCase					)					)

    # Find permutation
    while factorials:
        lowerCamelCase__       : List[str]   					=						factorials.pop()
        lowerCamelCase__					,				lowerCamelCase__       : Tuple   					=						divmod(_UpperCAmelCase		,      _UpperCAmelCase					)
        permutation.append(elements[number]					)
        elements.remove(elements[number]					)
    permutation.append(elements[0]					)

    return permutation


if __name__ == "__main__":
    import doctest

    doctest.testmod()





