"""simple docstring"""
import argparse
import os

from accelerate.utils import ComputeEnvironment

from .cluster import get_cluster_input
from .config_args import cache_dir, default_config_file, default_yaml_config_file, load_config_from_file  # noqa: F401
from .config_utils import _ask_field, _ask_options, _convert_compute_environment  # noqa: F401
from .sagemaker import get_sagemaker_input


SCREAMING_SNAKE_CASE__					  =     'Launches a series of prompts to create and save a `default_config.yaml` configuration file for your training system. Should always be ran first on your machine'





def       lowerCAmelCase__			(	)    -> Optional[Any]:





						"""simple docstring"""






						snake_case	    =	_ask_options(
						    'In which compute environment are you running?'       ,	['This machine', 'AWS (Amazon SageMaker)']       ,	_convert_compute_environment       ,	)
						if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
												snake_case	    =	get_sagemaker_input()
						else:
												snake_case	    =	get_cluster_input()
						return config





def       lowerCAmelCase__			(	_UpperCamelCase				: Dict=None    )    -> Union[str, Any]:





						"""simple docstring"""






						if subparsers is not None:
												snake_case	    =	subparsers.add_parser('config'       ,	description=snake_case_    )
						else:
												snake_case	    =	argparse.ArgumentParser('Accelerate config command'       ,	description=snake_case_    )

						parser.add_argument(
						    '--config_file'       ,	default=snake_case_       ,	help=(
						        'The path to use to store the config file. Will default to a file named default_config.yaml in the cache '
						        'location, which is the content of the environment `HF_HOME` suffixed with \'accelerate\', or if you don\'t have '
						        'such an environment variable, your cache directory (\'~/.cache\' or the content of `XDG_CACHE_HOME`) suffixed '
						        'with \'huggingface\'.'
						    )       ,	)

						if subparsers is not None:
												parser.set_defaults(func=snake_case_    )
						return parser





def       lowerCAmelCase__			(	_UpperCamelCase				: int    )    -> Any:





						"""simple docstring"""






						snake_case	    =	get_user_input()
						if args.config_file is not None:
												snake_case	    =	args.config_file
						else:
												if not os.path.isdir(snake_case_    ):
																		os.makedirs(snake_case_    )
												snake_case	    =	default_yaml_config_file

						if config_file.endswith('.json'    ):
												config.to_json_file(snake_case_    )
						else:
												config.to_yaml_file(snake_case_    )
						print(f"""accelerate configuration saved at {config_file}"""    )





def       lowerCAmelCase__			(	)    -> Optional[int]:





						"""simple docstring"""






						snake_case	    =	config_command_parser()
						snake_case	    =	parser.parse_args()
						config_command(snake_case_    )


if __name__ == "__main__":
					main()



'''simple docstring'''





import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


SCREAMING_SNAKE_CASE_:     Optional[Any]  ='\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n'


SCREAMING_SNAKE_CASE_:     Union[str, Any]  ='\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting "1/2" to "\\frac{1}{2}") and then computes accuracy.\n'


SCREAMING_SNAKE_CASE_:     List[Any]  =r'\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting "1/2" to "\\frac{1}{2}")\n\nExamples:\n    >>> metric = datasets.load_metric("competition_math")\n    >>> results = metric.compute(references=["\\frac{1}{2}"], predictions=["1/2"])\n    >>> print(results)\n    {\'accuracy\': 1.0}\n'




@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION		,	_KWARGS_DESCRIPTION	)
class        __A      ( datasets.Metric	):



    def 					_lowercase						(self    :    Optional[Any] ):
         return datasets.MetricInfo(
             description=_DESCRIPTION   ,			citation=_CITATION   ,			inputs_description=_KWARGS_DESCRIPTION   ,			features=datasets.Features(
                 {
                     "predictions": datasets.Value("string" ),
                     "references": datasets.Value("string" ),
                 } )   ,			homepage="https://github.com/hendrycks/math"   ,			codebase_urls=["https://github.com/hendrycks/math"]   ,			)






    def 					_lowercase						(self    :    Tuple   ,			__a    :    Optional[int]   ,			__a    :    List[Any] ):
         UpperCAmelCase_           =   0.0
         for i, j in zip(__a   ,			__a ):
              n_correct += 1.0 if math_equivalence.is_equiv(__a   ,			__a ) else 0.0
         UpperCAmelCase_           =   n_correct / len(__a )
         return {
             "accuracy": accuracy,
         }




