




"""simple docstring"""





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        _UpperCamelCase     (      UpperCamelCase				)      ->      str:


			"""simple docstring"""
			__UpperCAmelCase						:			Optional[int]												=       {}
			__UpperCAmelCase						:			str												=       os.path.join(UpperCamelCase					,							"all_results.json"				)
			if os.path.exists(UpperCamelCase				):
						with open(UpperCamelCase					,							"r"				) as f:
									__UpperCAmelCase						:			List[str]												=       json.load(UpperCamelCase				)
			else:
						raise ValueError(f"can't find {path}"				)
			return results


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





@require_torch_tpu
class   a__					(						__magic_name__ ):


			def    a_  (   self   :     Optional[int]):


						"""simple docstring"""




						import xla_spawn

						__UpperCAmelCase						:			Tuple												=       self.get_auto_remove_tmp_dir()
						__UpperCAmelCase						:			List[Any]												=       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(UpperCamelCase_   ,	"argv"   ,	UpperCamelCase_):
									__UpperCAmelCase						:			str												=       time()
									xla_spawn.main()
									__UpperCAmelCase						:			Tuple												=       time()

									__UpperCAmelCase						:			Optional[Any]												=       get_results(UpperCamelCase_)
									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    a_  (   self   :     Optional[int]):


						"""simple docstring"""




						import xla_spawn

						__UpperCAmelCase						:			Tuple												=       "\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            ".split()
						with patch.object(UpperCamelCase_   ,	"argv"   ,	UpperCamelCase_):
									xla_spawn.main()






import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


SCREAMING_SNAKE_CASE							    =							importlib.util.find_spec('s3fs') is not None

if _has_safs:
  from .safilesystem import SaFileSystem  # noqa: F401

SCREAMING_SNAKE_CASE							    =							[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
  if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
    warnings.warn(f'''A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.''')
  fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)




def  a   (lowerCAmelCase__   ):
   if "://" in dataset_path:
      __a					=  dataset_path.split("""://"""   )[1]
   return dataset_path




def  a   (lowerCAmelCase__   ):
   if fs is not None and fs.protocol != "file":
      return True
   else:
      return False




def  a   (lowerCAmelCase__		,				lowerCAmelCase__		,				lowerCAmelCase__   ):
   __a					=  not is_remote_filesystem(lowerCAmelCase__   )
   if is_local:
      # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
      shutil.move(fs._strip_protocol(lowerCAmelCase__   )		,				fs._strip_protocol(lowerCAmelCase__   )   )
   else:
      fs.mv(lowerCAmelCase__		,				lowerCAmelCase__		,				recursive=lowerCAmelCase__   )




def  a   ():
   if hasattr(fsspec.asyn		,				"""reset_lock"""   ):
      # for future fsspec>2022.05.0
      fsspec.asyn.reset_lock()
   else:
      __a					=  None
      __a					=  None
      __a					=  threading.Lock()



