


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



def       _lowerCAmelCase    (				lowerCAmelCase_				:str		,    lowerCAmelCase_				:str=None		,    lowerCAmelCase_				:Union[str, Any]=None		,    lowerCAmelCase_				:List[str]=None				)->List[Any]:
   '''simple docstring'''






   snake_case_            =       True
   while ask_again:
      snake_case_            =       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       _lowerCAmelCase    (				lowerCAmelCase_				:Dict		,    lowerCAmelCase_				:str=[]		,    lowerCAmelCase_				:List[Any]=None		,    lowerCAmelCase_				:int=0				)->Dict:
   '''simple docstring'''






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



def       _lowerCAmelCase    (				lowerCAmelCase_				:Dict				)->Union[str, Any]:
   '''simple docstring'''






   snake_case_            =       int(lowerCAmelCase_				)
   return ComputeEnvironment(["LOCAL_MACHINE", "AMAZON_SAGEMAKER"][value]				)



def       _lowerCAmelCase    (				lowerCAmelCase_				:Dict				)->Dict:
   '''simple docstring'''






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



def       _lowerCAmelCase    (				lowerCAmelCase_				:List[str]				)->Dict:
   '''simple docstring'''






   snake_case_            =       int(lowerCAmelCase_				)
   return DynamoBackend(DYNAMO_BACKENDS[value]				).value



def       _lowerCAmelCase    (				lowerCAmelCase_				:int				)->str:
   '''simple docstring'''






   snake_case_            =       int(lowerCAmelCase_				)
   return PrecisionType(["no", "fp16", "bf16", "fp8"][value]				)



def       _lowerCAmelCase    (				lowerCAmelCase_				:List[Any]				)->List[str]:
   '''simple docstring'''






   snake_case_            =       int(lowerCAmelCase_				)
   return SageMakerDistributedType(["NO", "DATA_PARALLEL", "MODEL_PARALLEL"][value]				)



def       _lowerCAmelCase    (				lowerCAmelCase_				:int				)->Dict:
   '''simple docstring'''






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



class      __lowerCAmelCase  (			argparse.RawDescriptionHelpFormatter       ):






  """simple docstring"""





  def        lowerCAmelCase__	(  self							:							Union[str, Any]     ,					_lowerCAmelCase							:							Union[str, Any]     ,					_lowerCAmelCase							:							List[str]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							Dict	) ->			str:




     """simple docstring"""
     snake_case_            =       super()._format_usage(_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       usage.replace("<command> [<args>] "     ,					""	)
     return usage








from collections import deque

from .hash_table import HashTable


class      __lowerCAmelCase  (			a       ):






  """simple docstring"""





  def __init__(  self							:							int     ,					*_lowerCAmelCase							:							List[Any]     ,					**_lowerCAmelCase							:							Any	) ->			Union[str, Any]:




     """simple docstring"""
     super().__init__(*_lowerCAmelCase     ,					**_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Tuple     ,					_lowerCAmelCase							:							Optional[int]     ,					_lowerCAmelCase							:							List[Any]	) ->			List[Any]:




     """simple docstring"""
     snake_case_            =       deque([]	) if self.values[key] is None else self.values[key]
     self.values[key].appendleft(_lowerCAmelCase	)
     snake_case_            =       self.values[key]



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			List[Any]:




     """simple docstring"""
     return (
         sum(self.charge_factor - len(_lowerCAmelCase	) for slot in self.values	)
         / self.size_table
         * self.charge_factor
     )



  def        lowerCAmelCase__	(  self							:							List[str]     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							List[str]=None	) ->			int:




     """simple docstring"""
     if not (
         len(self.values[key]	) == self.charge_factor and self.values.count(_lowerCAmelCase	) == 0
     ):
        return key
     return super()._collision_resolution(_lowerCAmelCase     ,					_lowerCAmelCase	)




