



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


lowerCamelCase				:str							       =   [
    "EAGER",
    "AOT_EAGER",
    "INDUCTOR",
    "NVFUSER",
    "AOT_NVFUSER",
    "AOT_CUDAGRAPHS",
    "OFI",
    "FX2TRT",
    "ONNXRT",
    "IPEX",
]



def       a     (					lowerCamelCase__		, lowerCamelCase__=None		, lowerCamelCase__=None		, lowerCamelCase__=None       ):
			'''simple docstring'''





			A_      :		Union[str, Any]      =	True
			while ask_again:
						A_      :		Dict      =	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       a     (					lowerCamelCase__		, lowerCamelCase__=[]		, lowerCamelCase__=None		, lowerCamelCase__=0       ):
			'''simple docstring'''





			A_      :		Any      =	BulletMenu(_UpperCamelCase		, _UpperCamelCase       )
			A_      :		Union[str, Any]      =	menu.run(default_choice=_UpperCamelCase       )
			return convert_value(_UpperCamelCase       ) if convert_value is not None else result



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





			A_      :		Optional[int]      =	int(_UpperCamelCase       )
			return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]       )



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





			A_      :		int      =	int(_UpperCamelCase       )
			return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]       )



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





			A_      :		Optional[Any]      =	int(_UpperCamelCase       )
			return DynamoBackend(DYNAMO_BACKENDS[value]       ).value



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





			A_      :		Tuple      =	int(_UpperCamelCase       )
			return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]       )



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





			A_      :		List[str]      =	int(_UpperCamelCase       )
			return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]       )



def       a     (					lowerCamelCase__       ):
			'''simple docstring'''





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







class       _lowerCAmelCase				(     argparse.RawDescriptionHelpFormatter					):


	def        _a      (self			, lowercase			, lowercase			, lowercase			, lowercase				):
				A_      :		int      =	super()._format_usage(snake_case__			, snake_case__			, snake_case__			, snake_case__				)
				A_      :		List[Any]      =	usage.replace("""<command> [<args>] """			, """"""				)
				return usage


import re

from filelock import FileLock


try:
      import nltk

      a_     :    Optional[Any]     		=   True
except (ImportError, ModuleNotFoundError):
      a_     :    Union[str, Any]     		=   False

if NLTK_AVAILABLE:
      with FileLock(".lock") as lock:
            nltk.download("punkt", quiet=True)


def 							__lowerCAmelCase     (							_UpperCamelCase		:	str						)		->				str:
 '''simple docstring'''


 re.sub('<n>'		,				''		,				_UpperCamelCase						)  # remove pegasus newline char
 assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
 return "\n".join(nltk.sent_tokenize(_UpperCamelCase						)						)

