





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)

lowercase    : Dict    	=  logging.getLogger()


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


lowercase    : List[Any]    	=  logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)

@require_torch_tpu
class  __A(						__UpperCAmelCase ):

					def 	_UpperCamelCase     (      self      ):





												"""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(A,       '''argv''',       A      ):
																			_UpperCamelCase              =						time()
																			xla_spawn.main()
																			_UpperCamelCase              =						time()

																			_UpperCamelCase              =						get_results(A      )
																			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      ):





												"""simple docstring"""

												import xla_spawn

												_UpperCamelCase              =						'''
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            '''.split()
												with patch.object(A,       '''argv''',       A      ):
																			xla_spawn.main()













def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase					):
       _UpperCamelCase              =						[]
       if len(lowerCAmelCase					) == 1:
              return [nums.copy()]
       for _ in range(len(lowerCAmelCase					)					):
              _UpperCamelCase              =						nums.pop(0					)
              _UpperCamelCase              =						permute(lowerCAmelCase					)
              for perm in permutations:
                     perm.append(lowerCAmelCase					)
              result.extend(lowerCAmelCase					)
              nums.append(lowerCAmelCase					)
       return result


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase					):

       def backtrack(lowerCAmelCase					):
              if start == len(lowerCAmelCase					) - 1:
                     output.append(nums[:]					)
              else:
                     for i in range(lowerCAmelCase    ,       len(lowerCAmelCase					)					):
                            _UpperCamelCase       ,		_UpperCamelCase              =						nums[i], nums[start]
                            backtrack(start + 1					)
                            _UpperCamelCase       ,		_UpperCamelCase              =						nums[i], nums[start]  # backtrack

       _UpperCamelCase              =						[]
       backtrack(0					)
       return output


if __name__ == "__main__":
       import doctest

       # use res to print the data in permute2 function
       lowercase    : Optional[Any]    	=  permutea([1, 2, 3])
       print(res)
       doctest.testmod()






