
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)

__lowerCAmelCase     :	List[Any]       			=  logging.getLogger()

def a__       (			A_   ):






  '''simple docstring'''





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


__lowerCAmelCase     :	str       			=  logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)





@require_torch_tpu
class 			UpperCAmelCase_     (					_A	):


  '''simple docstring'''







  def 				_lowercase				(					self     :					Any       )     ->      Tuple:







    """simple docstring"""






    import xla_spawn

    __magic_name__								=			self.get_auto_remove_tmp_dir()
    __magic_name__								=			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(UpperCamelCase__     ,				"""argv"""     ,				UpperCamelCase__       ):
      __magic_name__								=			time()
      xla_spawn.main()
      __magic_name__								=			time()

      __magic_name__								=			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 				_lowercase				(					self     :					int       )     ->      int:







    """simple docstring"""






    import xla_spawn

    __magic_name__								=			"""
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            """.split()
    with patch.object(UpperCamelCase__     ,				"""argv"""     ,				UpperCamelCase__       ):
      xla_spawn.main()



from __future__ import annotations

def a__       (			A_,	A_   ):






  '''simple docstring'''





  if b == 0:
    return (1, 0)
  ((__magic_name__)	,       (__magic_name__))								=			extended_euclid(A_,	a % b   )
  __magic_name__								=			a // b
  return (y, x - k * y)

def a__       (			A_,	A_,	A_,	A_   ):






  '''simple docstring'''





  ((__magic_name__)	,       (__magic_name__))								=			extended_euclid(A_,	A_   )
  __magic_name__								=			na * na
  __magic_name__								=			ra * x * na + ra * y * na
  return (n % m + m) % m

def a__       (			A_,	A_   ):






  '''simple docstring'''





  ((__magic_name__)	,       (__magic_name__))								=			extended_euclid(A_,	A_   )
  if b < 0:
    __magic_name__								=			(b % n + n) % n
  return b

def a__       (			A_,	A_,	A_,	A_   ):






  '''simple docstring'''





  __magic_name__	,       __magic_name__								=			invert_modulo(A_,	A_   ), invert_modulo(A_,	A_   )
  __magic_name__								=			na * na
  __magic_name__								=			ra * x * na + ra * y * na
  return (n % m + m) % m


if __name__ == "__main__":
    from doctest import testmod

    testmod(name='chinese_remainder_theorem', verbose=True)
    testmod(name='chinese_remainder_theorem2', verbose=True)
    testmod(name='invert_modulo', verbose=True)
    testmod(name='extended_euclid', verbose=True)

