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


SCREAMING_SNAKE_CASE_            =    [
    '''EAGER''',
    '''AOT_EAGER''',
    '''INDUCTOR''',
    '''NVFUSER''',
    '''AOT_NVFUSER''',
    '''AOT_CUDAGRAPHS''',
    '''OFI''',
    '''FX2TRT''',
    '''ONNXRT''',
    '''IPEX''',
]




def      lowercase__    (       lowerCAmelCase					:       List[Any]			,					lowerCAmelCase					:       Any=None			,					lowerCAmelCase					:       List[str]=None			,					lowerCAmelCase					:       Union[str, Any]=None			)			->   Tuple:






    """simple docstring"""




    UpperCAmelCase          =       True
    while ask_again:
        UpperCAmelCase          =       input(lowerCAmelCase			)
        try:
            if default is not None and len(lowerCAmelCase			) == 0:
                return default
            return convert_value(lowerCAmelCase			) if convert_value is not None else result
        except Exception:
            if error_message is not None:
                print(lowerCAmelCase			)




def      lowercase__    (       lowerCAmelCase					:       Union[str, Any]			,					lowerCAmelCase					:       Any=[]			,					lowerCAmelCase					:       Optional[Any]=None			,					lowerCAmelCase					:       Tuple=0			)			->   str:






    """simple docstring"""




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




def      lowercase__    (       lowerCAmelCase					:       Union[str, Any]			)			->   Optional[Any]:






    """simple docstring"""




    UpperCAmelCase          =       int(lowerCAmelCase			)
    return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value]			)




def      lowercase__    (       lowerCAmelCase					:       List[str]			)			->   int:






    """simple docstring"""




    UpperCAmelCase          =       int(lowerCAmelCase			)
    return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value]			)




def      lowercase__    (       lowerCAmelCase					:       Tuple			)			->   List[Any]:






    """simple docstring"""




    UpperCAmelCase          =       int(lowerCAmelCase			)
    return DynamoBackend(DYNAMO_BACKENDS[value]			).value




def      lowercase__    (       lowerCAmelCase					:       List[Any]			)			->   str:






    """simple docstring"""




    UpperCAmelCase          =       int(lowerCAmelCase			)
    return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value]			)




def      lowercase__    (       lowerCAmelCase					:       Optional[int]			)			->   List[str]:






    """simple docstring"""




    UpperCAmelCase          =       int(lowerCAmelCase			)
    return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value]			)




def      lowercase__    (       lowerCAmelCase					:       Optional[int]			)			->   Dict:






    """simple docstring"""




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







class   _UpperCAmelCase				(		argparse.RawDescriptionHelpFormatter				):




      def      a_   (				self ,							lowercase_ ,							lowercase_ ,							lowercase_ ,							lowercase_				)    ->       Optional[int]:
          UpperCAmelCase          =       super()._format_usage(lowercase_ ,							lowercase_ ,							lowercase_ ,							lowercase_				)
          UpperCAmelCase          =       usage.replace('<command> [<args>] ' ,							''				)
          return usage





"""simple docstring"""

import importlib
import os
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Union

import torch

from ..utils import BaseOutput


SCREAMING_SNAKE_CASE_            =    '''scheduler_config.json'''
class   _UpperCAmelCase				(		SCREAMING_SNAKE_CASE_				):
      __SCREAMING_SNAKE_CASE :				List[Any]				   =						1
      __SCREAMING_SNAKE_CASE :				Dict				   =						2
      __SCREAMING_SNAKE_CASE :				List[Any]				   =						3
      __SCREAMING_SNAKE_CASE :				Any				   =						4
      __SCREAMING_SNAKE_CASE :				Any				   =						5
      __SCREAMING_SNAKE_CASE :				Union[str, Any]				   =						6
      __SCREAMING_SNAKE_CASE :				str				   =						7
      __SCREAMING_SNAKE_CASE :				Any				   =						8
      __SCREAMING_SNAKE_CASE :				Tuple				   =						9
      __SCREAMING_SNAKE_CASE :				int				   =						1_0
      __SCREAMING_SNAKE_CASE :				Union[str, Any]				   =						1_1
      __SCREAMING_SNAKE_CASE :				Union[str, Any]				   =						1_2
      __SCREAMING_SNAKE_CASE :				Dict				   =						1_3
      __SCREAMING_SNAKE_CASE :				Optional[Any]				   =						1_4

@dataclass
class   _UpperCAmelCase				(		SCREAMING_SNAKE_CASE_				):
      __SCREAMING_SNAKE_CASE :				torch.FloatTensor

class   _UpperCAmelCase				:
      __SCREAMING_SNAKE_CASE :				str				   =						SCHEDULER_CONFIG_NAME
      __SCREAMING_SNAKE_CASE :				Dict				   =						[]
      __SCREAMING_SNAKE_CASE :				Union[str, Any]				   =						True




      @classmethod
      def      a_   (				cls ,							lowercase_ = None ,							lowercase_ = None ,							lowercase_=False ,							**lowercase_ ,							)    ->       List[Any]:
          UpperCAmelCase      ,				UpperCAmelCase      ,				UpperCAmelCase          =       cls.load_config(
              pretrained_model_name_or_path=lowercase_ ,							subfolder=lowercase_ ,							return_unused_kwargs=lowercase_ ,							return_commit_hash=lowercase_ ,							**lowercase_ ,							)
          return cls.from_config(lowercase_ ,							return_unused_kwargs=lowercase_ ,							**lowercase_				)




      def      a_   (				self ,							lowercase_ ,							lowercase_ = False ,							**lowercase_				)    ->       str:
          self.save_config(save_directory=lowercase_ ,							push_to_hub=lowercase_ ,							**lowercase_				)




      @property
      def      a_   (				self				)    ->       Union[str, Any]:
          return self._get_compatibles()




      @classmethod
      def      a_   (				cls				)    ->       Any:
          UpperCAmelCase          =       list(set([cls.__name__] + cls._compatibles				)				)
          UpperCAmelCase          =       importlib.import_module(__name__.split('.'				)[0]				)
          UpperCAmelCase          =       [
              getattr(lowercase_ ,							lowercase_				) for c in compatible_classes_str if hasattr(lowercase_ ,							lowercase_				)
          ]
          return compatible_classes



