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







def        A__					(						lowerCamelCase						)  ->	Tuple:
				UpperCamelCase_:							Any	=						{}
				UpperCamelCase_:							Dict	=						os.path.join(lowerCamelCase     ,    """all_results.json"""						)
				if os.path.exists(lowerCamelCase						):
								with open(lowerCamelCase     ,    """r"""						) as f:
												UpperCamelCase_:							Any	=						json.load(lowerCamelCase						)
				else:
								raise ValueError(F'''can\'t find {path}'''						)
				return results


lowerCamelCase_						: Dict         =  logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)





@require_torch_tpu
class        _UpperCamelCase				(					_A  ):






			'''simple docstring'''

			def       lowerCAmelCase__	(       self :       Dict      ):
							import xla_spawn

							UpperCamelCase_:							List[str]	=						self.get_auto_remove_tmp_dir()
							UpperCamelCase_:							List[str]	=						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(snake_case_						,	"""argv"""						,	snake_case_      ):
											UpperCamelCase_:							Tuple	=						time()
											xla_spawn.main()
											UpperCamelCase_:							Dict	=						time()

											UpperCamelCase_:							List[Any]	=						get_results(snake_case_      )
											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       lowerCAmelCase__	(       self :       Tuple      ):
							import xla_spawn

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








lowerCamelCase_						: Optional[Any]         =  """
# Transformers installation
! pip install transformers datasets
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/transformers.git
"""

lowerCamelCase_						: Union[str, Any]         =  [{"""type""": """code""", """content""": INSTALL_CONTENT}]
lowerCamelCase_						: Optional[Any]         =  {
    """{processor_class}""": """FakeProcessorClass""",
    """{model_class}""": """FakeModelClass""",
    """{object_class}""": """FakeObjectClass""",
}






