



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_		:     Optional[int]        =     logging.getLogger()


def 	UpperCAmelCase__      (      UpperCAmelCase__ :Union[str, Any]					)     ->   str:






 '''simple docstring'''

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


A_		:     Any        =     logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)




@require_torch_tpu
class 		_lowercase		(       UpperCAmelCase__	):

   def 		A							(      self			:       Any							)       ->				Tuple:


    """simple docstring"""






    import xla_spawn

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

     a						=		get_results(__lowerCAmelCase							)
     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							,   500							)




   def 		A							(      self			:       Tuple							)       ->				Tuple:


    """simple docstring"""






    import xla_spawn

    a						=		"\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()






def 	UpperCAmelCase__      (      UpperCAmelCase__ :Any					):






 '''simple docstring'''

 if not head:
  return True
 # split the list to two parts
 a		,  a						=		head.next, head
 while fast and fast.next:
  a						=		fast.next.next
  a						=		slow.next
 a						=		slow.next
 a						=		None  # Don't forget here! But forget still works!
 # reverse the second part
 a						=		None
 while second:
  a						=		second.next
  a						=		node
  a						=		second
  a						=		nxt
 # compare two parts
 # second part has the same or one less node
 while node:
  if node.val != head.val:
   return False
  a						=		node.next
  a						=		head.next
 return True


def 	UpperCAmelCase__      (      UpperCAmelCase__ :str					):






 '''simple docstring'''

 if not head or not head.next:
  return True

 # 1. Get the midpoint (slow)
 a						=		a						=		a						=		head
 while fast and fast.next:
  a		,  a						=		fast.next.next, slow.next

 # 2. Push the second half into the stack
 a						=		[slow.val]
 while slow.next:
  a						=		slow.next
  stack.append(slow.val					)

 # 3. Comparison
 while stack:
  if stack.pop() != cur.val:
   return False
  a						=		cur.next

 return True




def 	UpperCAmelCase__      (      UpperCAmelCase__ :Any					):






 '''simple docstring'''

 if not head or not head.next:
  return True
 a						=		{}
 a						=		0
 while head:
  if head.val in d:
   d[head.val].append(UpperCAmelCase__					)
  else:
   a						=		[pos]
  a						=		head.next
  pos += 1
 a						=		pos - 1
 a						=		0
 for v in d.values():
  if len(UpperCAmelCase__					) % 2 != 0:
   middle += 1
  else:
   a						=		0
   for i in range(0 ,					len(UpperCAmelCase__					)					):
    if v[i] + v[len(UpperCAmelCase__					) - 1 - step] != checksum:
     return False
    step += 1
  if middle > 1:
   return False
 return True

