






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)

__magic_name__   :  Any        =							logging.getLogger()
def 		lowercase__  (				_UpperCamelCase) ->			Dict:
      """simple docstring"""

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


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





@require_torch_tpu
class 					A__     (     __snake_case ):

     '''simple docstring'''






     def   _SCREAMING_SNAKE_CASE     ( self      :    Any ):






           """simple docstring"""




           import xla_spawn

           UpperCamelCase					       =  self.get_auto_remove_tmp_dir()
           UpperCamelCase					       =  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(_SCREAMING_SNAKE_CASE   ,						'argv'   ,						_SCREAMING_SNAKE_CASE ):
                 UpperCamelCase					       =  time()
                 xla_spawn.main()
                 UpperCamelCase					       =  time()

                 UpperCamelCase					       =  get_results(_SCREAMING_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   ,						500 )







     def   _SCREAMING_SNAKE_CASE     ( self      :    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(_SCREAMING_SNAKE_CASE   ,						'argv'   ,						_SCREAMING_SNAKE_CASE ):
                 xla_spawn.main()











def 		lowercase__  (				_UpperCamelCase) ->			list:
      """simple docstring"""

      if bit_count < 0:
            raise ValueError('The given input must be positive')

      # get the generated string sequence
      UpperCamelCase					       =  gray_code_sequence_string(_UpperCamelCase)
      #
      # convert them to integers
      for i in range(len(_UpperCamelCase)):
            UpperCamelCase					       =  int(sequence[i]       ,							2)

      return sequence
def 		lowercase__  (				_UpperCamelCase) ->			list:
      """simple docstring"""

      if bit_count == 0:
            return ["0"]

      if bit_count == 1:
            return ["0", "1"]

      UpperCamelCase					       =  1 << bit_count  # defines the length of the sequence
      # 1<< n is equivalent to 2^n

      # recursive answer will generate answer for n-1 bits
      UpperCamelCase					       =  gray_code_sequence_string(bit_count - 1)

      UpperCamelCase					       =  []

      # append 0 to first half of the smaller sequence generated
      for i in range(seq_len // 2):
            UpperCamelCase					       =  '0' + smaller_sequence[i]
            sequence.append(_UpperCamelCase)

      # append 1 to second half ... start from the end of the list
      for i in reversed(range(seq_len // 2)):
            UpperCamelCase					       =  '1' + smaller_sequence[i]
            sequence.append(_UpperCamelCase)

      return sequence


if __name__ == "__main__":
       import doctest

       doctest.testmod()



