




'''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)

_SCREAMING_SNAKE_CASE							:       Any						=			logging.getLogger()


def 					UpperCamelCase_(     snake_case							:	Any					):

							'''simple docstring'''






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


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




@require_torch_tpu
class 			_snake_case		(     lowercase_							):




			def        lowerCAmelCase__    ( self							)    ->    Tuple:

										'''simple docstring'''




										import xla_spawn

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

																	snake_case_      =				get_results(a__							)
																	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        lowerCAmelCase__    ( self							)    ->    Optional[Any]:

										'''simple docstring'''




										import xla_spawn

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










'''simple docstring'''





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin




class 			_snake_case		(     unittest.TestCase						,						lowercase_							):




			def        lowerCAmelCase__    ( self							)    ->    Optional[int]:

										'''simple docstring'''




										snake_case_      =				load_tool("text-classification"							)
										self.tool.setup()
										snake_case_      =				load_tool("text-classification"    ,							remote=a__							)




			def        lowerCAmelCase__    ( self							)    ->    str:

										'''simple docstring'''




										snake_case_      =				self.tool("That's quite cool"    ,							["positive", "negative"]							)
										self.assertEqual(a__    ,							"positive"							)




			def        lowerCAmelCase__    ( self							)    ->    Optional[int]:

										'''simple docstring'''




										snake_case_      =				self.remote_tool("That's quite cool"    ,							["positive", "negative"]							)
										self.assertEqual(a__    ,							"positive"							)




			def        lowerCAmelCase__    ( self							)    ->    int:

										'''simple docstring'''




										snake_case_      =				self.tool(text="That's quite cool"    ,							labels=["positive", "negative"]							)
										self.assertEqual(a__    ,							"positive"							)




			def        lowerCAmelCase__    ( self							)    ->    Any:

										'''simple docstring'''




										snake_case_      =				self.remote_tool(text="That's quite cool"    ,							labels=["positive", "negative"]							)
										self.assertEqual(a__    ,							"positive"							)




