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







def 		A_(     A						:		str		,     A						:		Tuple=None		,     A						:		int=None		,     A						:		Union[str, Any]=None):
							UpperCamelCase   			=     True
							while ask_again:
														UpperCamelCase   			=     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 		A_(     A						:		Any		,     A						:		Union[str, Any]=[]		,     A						:		Dict=None		,     A						:		List[str]=0):
							UpperCamelCase   			=     BulletMenu(A		,     A)
							UpperCamelCase   			=     menu.run(default_choice=A)
							return convert_value(A) if convert_value is not None else result







def 		A_(     A						:		Tuple):
							UpperCamelCase   			=     int(A)
							return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value])







def 		A_(     A						:		List[str]):
							UpperCamelCase   			=     int(A)
							return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value])







def 		A_(     A						:		str):
							UpperCamelCase   			=     int(A)
							return DynamoBackend(DYNAMO_BACKENDS[value]).value







def 		A_(     A						:		Any):
							UpperCamelCase   			=     int(A)
							return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value])







def 		A_(     A						:		Optional[Any]):
							UpperCamelCase   			=     int(A)
							return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value])







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





class 			SCREAMING_SNAKE_CASE__      (     argparse.RawDescriptionHelpFormatter):







				def 						UpperCAmelCase_    (       self						,				A_						,				A_						,				A_						,				A_     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     super()._format_usage(A_						,				A_						,				A_						,				A_     )
											UpperCamelCase   			=     usage.replace('<command> [<args>] '						,				''     )
											return usage






from argparse import ArgumentParser

from datasets.commands.convert import ConvertCommand
from datasets.commands.dummy_data import DummyDataCommand
from datasets.commands.env import EnvironmentCommand
from datasets.commands.run_beam import RunBeamCommand
from datasets.commands.test import TestCommand
from datasets.utils.logging import set_verbosity_info




def 	UpperCamelCase__  (     SCREAMING_SNAKE_CASE_	:	List[Any]       )  ->     Optional[int]:
						return {key.lstrip("""-"""       ): value for key, value in zip(unknown_args[::2]		,   unknown_args[1::2]       )}




def 	UpperCamelCase__  (     )  ->     Dict:
						_lowercase					       =					ArgumentParser(
						    """HuggingFace Datasets CLI tool"""		,   usage="""datasets-cli <command> [<args>]"""		,   allow_abbrev=SCREAMING_SNAKE_CASE_       )
						_lowercase					       =					parser.add_subparsers(help="""datasets-cli command helpers"""       )
						set_verbosity_info()

						# Register commands
						ConvertCommand.register_subcommand(SCREAMING_SNAKE_CASE_       )
						EnvironmentCommand.register_subcommand(SCREAMING_SNAKE_CASE_       )
						TestCommand.register_subcommand(SCREAMING_SNAKE_CASE_       )
						RunBeamCommand.register_subcommand(SCREAMING_SNAKE_CASE_       )
						DummyDataCommand.register_subcommand(SCREAMING_SNAKE_CASE_       )

						# Parse args
						_lowercase       ,						_lowercase					       =					parser.parse_known_args()
						if not hasattr(SCREAMING_SNAKE_CASE_		,   """func"""       ):
												parser.print_help()
												exit(1       )
						_lowercase					       =					parse_unknown_args(SCREAMING_SNAKE_CASE_       )

						# Run
						_lowercase					       =					args.func(SCREAMING_SNAKE_CASE_		,   **SCREAMING_SNAKE_CASE_       )
						service.run()


if __name__ == "__main__":
		main()