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


def 						UpperCAmelCase      (     a_		,       a_=None		,       a_=None		,       a_=None						)		->     Tuple:







				"""simple docstring"""



				__A             =			True
				while ask_again:
								__A             =			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 						UpperCAmelCase      (     a_		,       a_=[]		,       a_=None		,       a_=0						)		->     List[str]:







				"""simple docstring"""



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


def 						UpperCAmelCase      (     a_						)		->     Union[str, Any]:







				"""simple docstring"""



				__A             =			int(a_						)
				return ComputeEnvironment(["LOCAL_MACHINE", "AMAZON_SAGEMAKER"][value]						)


def 						UpperCAmelCase      (     a_						)		->     List[str]:







				"""simple docstring"""



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


def 						UpperCAmelCase      (     a_						)		->     Any:







				"""simple docstring"""



				__A             =			int(a_						)
				return DynamoBackend(DYNAMO_BACKENDS[value]						).value


def 						UpperCAmelCase      (     a_						)		->     Tuple:







				"""simple docstring"""



				__A             =			int(a_						)
				return PrecisionType(["no", "fp16", "bf16", "fp8"][value]						)


def 						UpperCAmelCase      (     a_						)		->     str:







				"""simple docstring"""



				__A             =			int(a_						)
				return SageMakerDistributedType(["NO", "DATA_PARALLEL", "MODEL_PARALLEL"][value]						)


def 						UpperCAmelCase      (     a_						)		->     str:







				"""simple docstring"""



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





class 							UpperCAmelCase				(  argparse.RawDescriptionHelpFormatter  ):




	'''simple docstring'''





	def     UpperCamelCase_  (	self :			Optional[int]							,A :			Any							,A :			Optional[int]							,A :			List[str]							,A :			str			):
					__A             =			super()._format_usage(A							,A							,A							,A			)
					__A             =			usage.replace("<command> [<args>] "							,""			)
					return usage


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE							:int										=    {'configuration_encoder_decoder': ['EncoderDecoderConfig']}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE							:Dict										=    ['EncoderDecoderModel']

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE							:int										=    ['TFEncoderDecoderModel']

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE							:Optional[int]										=    ['FlaxEncoderDecoderModel']

if TYPE_CHECKING:
					from .configuration_encoder_decoder import EncoderDecoderConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_encoder_decoder import EncoderDecoderModel

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_encoder_decoder import TFEncoderDecoderModel

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_encoder_decoder import FlaxEncoderDecoderModel

else:
					import sys

					SCREAMING_SNAKE_CASE							:int										=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
