


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			:			Dict												=					logging.getLogger()


def 		lowercase_	(  _UpperCamelCase	):


			'''simple docstring'''







			__lowercase			       = {}
			__lowercase			       = os.path.join(_UpperCamelCase							,      '''all_results.json'''	)
			if os.path.exists(_UpperCamelCase	):
						with open(_UpperCamelCase							,      '''r'''	) as f:
									__lowercase			       = json.load(_UpperCamelCase	)
			else:
						raise ValueError(F'can\'t find {path}'	)
			return results


a			:			Optional[int]												=					logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)





@require_torch_tpu
class 						lowerCamelCase_							(					lowerCAmelCase__					):



					'''simple docstring'''







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







								'''simple docstring'''

								import xla_spawn

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

								with patch.object(snake_case_			,							'''argv'''			,							snake_case_    ):
											__lowercase			       = time()
											xla_spawn.main()
											__lowercase			       = time()

											__lowercase			       = get_results(snake_case_    )
											self.assertGreaterEqual(result['''eval_accuracy''']			,							0.7_5    )

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






					def A   (					self    ) ->      List[str]:







								'''simple docstring'''

								import xla_spawn

								__lowercase			       = '''
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            '''.split()
								with patch.object(snake_case_			,							'''argv'''			,							snake_case_    ):
											xla_spawn.main()






from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader
class 						lowerCamelCase_							(					lowerCAmelCase__					):



					'''simple docstring'''







					def __init__(					self			,							snake_case_			,							snake_case_ = None			,							snake_case_ = None			,							snake_case_ = None			,							snake_case_ = False			,							snake_case_ = False			,							snake_case_ = None			,							**snake_case_			,							) ->      Dict:







								'''simple docstring'''

								super().__init__(
								    snake_case_			,							split=snake_case_			,							features=snake_case_			,							cache_dir=snake_case_			,							keep_in_memory=snake_case_			,							streaming=snake_case_			,							num_proc=snake_case_			,							**snake_case_			,							)
								__lowercase			       = path_or_paths if isinstance(snake_case_			,							snake_case_    ) else {self.split: path_or_paths}
								__lowercase			       = Text(
								    cache_dir=snake_case_			,							data_files=snake_case_			,							features=snake_case_			,							**snake_case_			,							)






					def A   (					self    ) ->      int:







								'''simple docstring'''

								if self.streaming:
											__lowercase			       = self.builder.as_streaming_dataset(split=self.split    )
								# Build regular (map-style) dataset
								else:
											__lowercase			       = None
											__lowercase			       = None
											__lowercase			       = None
											__lowercase			       = None

											self.builder.download_and_prepare(
											    download_config=snake_case_			,							download_mode=snake_case_			,							verification_mode=snake_case_			,							base_path=snake_case_			,							num_proc=self.num_proc			,							)
											__lowercase			       = self.builder.as_dataset(
											    split=self.split			,							verification_mode=snake_case_			,							in_memory=self.keep_in_memory    )
								return dataset


