
"""simple docstring"""





import importlib.util
import os
import platform
from argparse import ArgumentParser

import huggingface_hub

from .. import __version__ as version
from ..utils import (
    is_accelerate_available,
    is_flax_available,
    is_safetensors_available,
    is_tf_available,
    is_torch_available,
)
from . import BaseTransformersCLICommand



def       lowerCamelCase__		(			__snake_case	)							->		Tuple:


					"""simple docstring"""





					return EnvironmentCommand()



def       lowerCamelCase__		(			__snake_case	)							->		List[str]:


					"""simple docstring"""





					return EnvironmentCommand(args.accelerate_config_file	)






class     _UpperCAmelCase(    lowerCamelCase	):



		@staticmethod
		def 						UpperCAmelCase							(					__a)       ->       List[str]:






							'''simple docstring'''
							_UpperCamelCase							 =  parser.add_parser('''env''')
							download_parser.set_defaults(func=__a)
							download_parser.add_argument(
							    '''--accelerate-config_file'''				,		default=__a				,		help='''The accelerate config file to use for the default values in the launching script.'''				,		)
							download_parser.set_defaults(func=__a)



		def __init__(					self				,		__a				,		*__a)       ->       None:






							'''simple docstring'''
							_UpperCamelCase							 =  accelerate_config_file



		def 						UpperCAmelCase							(					self)       ->       Optional[int]:






							'''simple docstring'''
							_UpperCamelCase							 =  '''not installed'''
							if is_safetensors_available():
												import safetensors

												_UpperCamelCase							 =  safetensors.__version__
							elif importlib.util.find_spec('''safetensors''') is not None:
												import safetensors

												_UpperCamelCase							 =  F'''{safetensors.__version__} but is ignored because of PyTorch version too old.'''

							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  _UpperCamelCase							 =  '''not found'''
							if is_accelerate_available():
												import accelerate
												from accelerate.commands.config import default_config_file, load_config_from_file

												_UpperCamelCase							 =  accelerate.__version__
												# Get the default from the config file.
												if self._accelerate_config_file is not None or os.path.isfile(__a):
																	_UpperCamelCase							 =  load_config_from_file(self._accelerate_config_file).to_dict()

												_UpperCamelCase							 =  (
												    '''\n'''.join([F'''\t- {prop}: {val}''' for prop, val in accelerate_config.items()])
												    if isinstance(__a				,		__a)
												    else F'''\t{accelerate_config}'''
												)

							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  '''NA'''
							if is_torch_available():
												import torch

												_UpperCamelCase							 =  torch.__version__
												_UpperCamelCase							 =  torch.cuda.is_available()

							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  '''NA'''
							if is_tf_available():
												import tensorflow as tf

												_UpperCamelCase							 =  tf.__version__
												try:
																	# deprecated in v2.1
																	_UpperCamelCase							 =  tf.test.is_gpu_available()
												except AttributeError:
																	# returns list of devices, convert to bool
																	_UpperCamelCase							 =  bool(tf.config.list_physical_devices('''GPU'''))

							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  '''not installed'''
							_UpperCamelCase							 =  '''NA'''
							if is_flax_available():
												import flax
												import jax
												import jaxlib

												_UpperCamelCase							 =  flax.__version__
												_UpperCamelCase							 =  jax.__version__
												_UpperCamelCase							 =  jaxlib.__version__
												_UpperCamelCase							 =  jax.lib.xla_bridge.get_backend().platform

							_UpperCamelCase							 =  {
							    '''`transformers` version''': version,
							    '''Platform''': platform.platform(),
							    '''Python version''': platform.python_version(),
							    '''Huggingface_hub version''': huggingface_hub.__version__,
							    '''Safetensors version''': F'''{safetensors_version}''',
							    '''Accelerate version''': F'''{accelerate_version}''',
							    '''Accelerate config''': F'''{accelerate_config_str}''',
							    '''PyTorch version (GPU?)''': F'''{pt_version} ({pt_cuda_available})''',
							    '''Tensorflow version (GPU?)''': F'''{tf_version} ({tf_cuda_available})''',
							    '''Flax version (CPU?/GPU?/TPU?)''': F'''{flax_version} ({jax_backend})''',
							    '''Jax version''': F'''{jax_version}''',
							    '''JaxLib version''': F'''{jaxlib_version}''',
							    '''Using GPU in script?''': '''<fill in>''',
							    '''Using distributed or parallel set-up in script?''': '''<fill in>''',
							}

							print('''\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n''')
							print(self.format_dict(__a))

							return info




		@staticmethod
		def 						UpperCAmelCase							(					__a)       ->       List[Any]:






							'''simple docstring'''
							return "\n".join([F'''- {prop}: {val}''' for prop, val in d.items()]) + "\n"








"""simple docstring"""





import datasets


_a														=		"""\
@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\",
}
"""

_a														=		"""\
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).
"""

_a														=		"""
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__		(			__snake_case,     __snake_case	)							->		str:


					"""simple docstring"""





					return (preds == labels).mean()






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



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''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 						UpperCAmelCase							(					self				,		__a				,		__a)       ->       Dict:






							'''simple docstring'''
							return {"accuracy": simple_accuracy(__a				,		__a)}






