




import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


a__		     =     {
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

a__		     =     logging.WARNING





def 				A__ ()     ->						Any:
					__UpperCamelCase					:	Union[str, Any]             =      os.getenv("""DATASETS_VERBOSITY"""		,	snake_case				)
					if env_level_str:
										if env_level_str in log_levels:
															return log_levels[env_level_str]
										else:
															logging.getLogger().warning(
															    F'''Unknown option DATASETS_VERBOSITY={env_level_str}, '''
															    F'''has to be one of: { ", ".join(log_levels.keys()				) }'''				)
					return _default_log_level





def 				A__ ()     ->						str:
					return __name__.split("""."""				)[0]





def 				A__ ()     ->						logging.Logger:
					return logging.getLogger(_get_library_name()				)





def 				A__ ()     ->						None:
					# Apply our default configuration to the library root logger.
					__UpperCamelCase					:	Any             =      _get_library_root_logger()
					library_root_logger.setLevel(_get_default_logging_level()				)





def 				A__ ()     ->						None:
					__UpperCamelCase					:	List[Any]             =      _get_library_root_logger()
					library_root_logger.setLevel(logging.NOTSET				)





def 				A__ (snake_case   :		Optional[str] = None				)     ->						logging.Logger:
					if name is None:
										__UpperCamelCase					:	Optional[int]             =      _get_library_name()
					return logging.getLogger(snake_case				)





def 				A__ ()     ->						int:
					return _get_library_root_logger().getEffectiveLevel()





def 				A__ (snake_case   :		int				)     ->						None:
					_get_library_root_logger().setLevel(snake_case				)





def 				A__ ()     ->						Dict:
					return set_verbosity(snake_case				)





def 				A__ ()     ->						Any:
					return set_verbosity(snake_case				)





def 				A__ ()     ->						Dict:
					return set_verbosity(snake_case				)





def 				A__ ()     ->						str:
					return set_verbosity(snake_case				)





def 				A__ ()     ->						None:
					__UpperCamelCase					:	str             =      False





def 				A__ ()     ->						None:
					__UpperCamelCase					:	List[str]             =      True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()


class    SCREAMING_SNAKE_CASE_				:



	"""simple docstring"""


	def __init__(					self		:						Optional[int]					,     *lowerCAmelCase		:						str					,     **lowerCAmelCase		:						List[str]	)	->       Union[str, Any]:  # pylint: disable=unused-argument







						"""simple docstring"""







						__UpperCamelCase					:	List[str]             =      args[0] if args else None






	def __iter__(					self		:						List[Any]	)	->       List[Any]:







						"""simple docstring"""







						return iter(self._iterator	)






	def __getattr__(					self		:						int					,     lowerCAmelCase		:						List[str]	)	->       Dict:







						"""simple docstring"""







						def empty_fn(*lowerCAmelCase		:						List[Any]					,     **lowerCAmelCase		:						Dict	):  # pylint: disable=unused-argument
											return

						return empty_fn






	def __enter__(					self		:						Tuple	)	->       Any:







						"""simple docstring"""







						return self






	def __exit__(					self		:						str					,     lowerCAmelCase		:						Dict					,     lowerCAmelCase		:						Dict					,     lowerCAmelCase		:						List[str]	)	->       Tuple:







						"""simple docstring"""







						return






a__		     =     True


class    SCREAMING_SNAKE_CASE_				:



	"""simple docstring"""


	def __call__(					self		:						str					,     *lowerCAmelCase		:						List[Any]					,     lowerCAmelCase		:						Dict=False					,     **lowerCAmelCase		:						Tuple	)	->       Optional[Any]:







						"""simple docstring"""







						if _tqdm_active and not disable:
											return tqdm_lib.tqdm(*lowerCAmelCase					,     **lowerCAmelCase	)
						else:
											return EmptyTqdm(*lowerCAmelCase					,     **lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Any					,     *lowerCAmelCase		:						List[str]					,     **lowerCAmelCase		:						str	)	->       Dict:







						"""simple docstring"""







						__UpperCamelCase					:	Any             =      None
						if _tqdm_active:
											return tqdm_lib.tqdm.set_lock(*lowerCAmelCase					,     **lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Dict	)	->       Union[str, Any]:







						"""simple docstring"""







						if _tqdm_active:
											return tqdm_lib.tqdm.get_lock()






a__		     =     _tqdm_cls()





def 				A__ ()     ->						bool:
					global _tqdm_active
					return bool(_tqdm_active				)





def 				A__ ()     ->						List[str]:
					global _tqdm_active
					__UpperCamelCase					:	Tuple             =      True







def 				A__ ()     ->						int:
					global _tqdm_active
					__UpperCamelCase					:	Any             =      False












import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

a__		     =     logging.getLogger()





def 				A__ (snake_case   :		Tuple				)     ->						Dict:
					__UpperCamelCase					:	Dict             =      {}
					__UpperCamelCase					:	Dict             =      os.path.join(snake_case		,	"""all_results.json"""				)
					if os.path.exists(snake_case				):
										with open(snake_case		,	"""r"""				) as f:
															__UpperCamelCase					:	List[Any]             =      json.load(snake_case				)
					else:
										raise ValueError(F'''can\'t find {path}'''				)
					return results


a__		     =     logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)







@require_torch_tpu
class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def 					lowerCamelCase__     (					self		:						Dict	)	->       Dict:







						"""simple docstring"""







						import xla_spawn

						__UpperCamelCase					:	Dict             =      self.get_auto_remove_tmp_dir()
						__UpperCamelCase					:	str             =      F'''
            ./examples/pytorch/text-classification/run_glue.py
            --num_cores=8
            ./examples/pytorch/text-classification/run_glue.py
            --model_name_or_path distilbert-base-uncased
            --output_dir {tmp_dir}
            --overwrite_output_dir
            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv
            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv
            --do_train
            --do_eval
            --debug tpu_metrics_debug
            --per_device_train_batch_size=2
            --per_device_eval_batch_size=1
            --learning_rate=1e-4
            --max_steps=10
            --warmup_steps=2
            --seed=42
            --max_seq_length=128
            '''.split()

						with patch.object(lowerCAmelCase					,     """argv"""					,     lowerCAmelCase	):
											__UpperCamelCase					:	Union[str, Any]             =      time()
											xla_spawn.main()
											__UpperCamelCase					:	List[str]             =      time()

											__UpperCamelCase					:	Optional[int]             =      get_results(lowerCAmelCase	)
											self.assertGreaterEqual(result["""eval_accuracy"""]					,     0.75	)

											# Assert that the script takes less than 500 seconds to make sure it doesn't hang.
											self.assertLess(end - start					,     500	)






	def 					lowerCamelCase__     (					self		:						int	)	->       List[Any]:







						"""simple docstring"""







						import xla_spawn

						__UpperCamelCase					:	List[Any]             =      """
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            """.split()
						with patch.object(lowerCAmelCase					,     """argv"""					,     lowerCAmelCase	):
											xla_spawn.main()






