'''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       __lowerCAmelCase      (						A_   : Optional[int]					)    ->  List[Any]:
  __UpperCAmelCase						    =       {}
  __UpperCAmelCase						    =       os.path.join(A_						,	"all_results.json"					)
  if os.path.exists(A_					):
    with open(A_						,	"r"					) as f:
      __UpperCAmelCase						    =       json.load(A_					)
  else:
    raise ValueError(F'''can\'t find {path}'''					)
  return results


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





@require_torch_tpu
class 			UpperCAmelCase__    (		snake_case					):



  """simple docstring"""






  def 	_UpperCAmelCase				(				self:			Tuple   ) -> Union[str, Any]:




    '''simple docstring'''




    import xla_spawn

    __UpperCAmelCase						    =       self.get_auto_remove_tmp_dir()
    __UpperCAmelCase						    =       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						    =       time()
      xla_spawn.main()
      __UpperCAmelCase						    =       time()

      __UpperCAmelCase						    =       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 	_UpperCAmelCase				(				self:			str   ) -> List[str]:




    '''simple docstring'''




    import xla_spawn

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




from ..utils import DummyObject, requires_backends


class 			UpperCAmelCase__    (		metaclass=snake_case					):



  """simple docstring"""






  lowerCAmelCase__		:	List[str]    		= ['transformers', 'torch', 'note_seq']






  def __init__(				self:			List[str]				,				*__lowerCAmelCase:			Optional[int]				,				**__lowerCAmelCase:			List[Any]   ) -> Optional[int]:




    '''simple docstring'''




    requires_backends(self				,				["transformers", "torch", "note_seq"]   )






  @classmethod
  def 	_UpperCAmelCase				(				cls:			Optional[int]				,				*__lowerCAmelCase:			Any				,				**__lowerCAmelCase:			List[str]   ) -> Dict:




    '''simple docstring'''




    requires_backends(cls				,				["transformers", "torch", "note_seq"]   )






  @classmethod
  def 	_UpperCAmelCase				(				cls:			Union[str, Any]				,				*__lowerCAmelCase:			Optional[Any]				,				**__lowerCAmelCase:			Optional[Any]   ) -> Any:




    '''simple docstring'''




    requires_backends(cls				,				["transformers", "torch", "note_seq"]   )



