

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

from accelerate.test_utils import execute_subprocess_async






def 				_lowerCAmelCase			(   __magic_name__						:     Union[str, Any]=None						)				->  Dict:
						if subparsers is not None:
												lowercase :							List[Any]    		=subparsers.add_parser('''test'''						)
						else:
												lowercase :							Dict    		=argparse.ArgumentParser('''Accelerate test command'''						)

						parser.add_argument(
						    '''--config_file'''   , default=__magic_name__   , 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=__magic_name__						)
						return parser






def 				_lowerCAmelCase			(   __magic_name__						:     int						)				->  Tuple:
						lowercase :							Optional[Any]    		=os.path.sep.join(__file__.split(os.path.sep						)[:-2] + ['''test_utils''', '''scripts''', '''test_script.py''']						)

						if args.config_file is None:
												lowercase :							str    		=script_name
						else:
												lowercase :							List[str]    		=f'''--config_file={args.config_file} {script_name}'''

						lowercase :							str    		=['''accelerate-launch'''] + test_args.split()
						lowercase :							Optional[int]    		=execute_subprocess_async(__magic_name__   , env=os.environ.copy()						)
						if result.returncode == 0:
												print('''Test is a success! You are ready for your distributed training!'''						)






def 				_lowerCAmelCase			(   )				->  List[Any]:
						lowercase :							Any    		=test_command_parser()
						lowercase :							Optional[Any]    		=parser.parse_args()
						test_command(__magic_name__						)


if __name__ == "__main__":
							main()








'''simple docstring'''





import datasets


UpperCamelCase_    						=       """\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

UpperCamelCase_    						=       """\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

UpperCamelCase_    						=       """
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""






def 				_lowerCAmelCase			(   __magic_name__						:     Dict   , __magic_name__						:     Union[str, Any]						)				->  Union[str, Any]:
						return (preds == labels).mean()







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,							_KWARGS_DESCRIPTION      )
class 		__SCREAMING_SNAKE_CASE							(			datasets.Metric      ):







				def  lowerCamelCase_	(       self     :		str   ):
										'''simple docstring'''
										return datasets.MetricInfo(
										    description=_DESCRIPTION		,					citation=_CITATION		,					inputs_description=_KWARGS_DESCRIPTION		,					features=datasets.Features(
										        {
										            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''   ),
										            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''   ),
										        }   )		,					codebase_urls=[]		,					reference_urls=[]		,					format='''numpy'''		,					)







				def  lowerCamelCase_	(       self     :		int		,					UpperCAmelCase__     :		Dict		,					UpperCAmelCase__     :		Optional[Any]   ):
										'''simple docstring'''
										return {"accuracy": simple_accuracy(UpperCAmelCase__		,					UpperCAmelCase__   )}





