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

lowerCamelCase__ :       str						     =			logging.getLogger()





def __A						(   a_ :							Tuple     )->							Optional[int]:




		'''simple docstring'''






		SCREAMING_SNAKE_CASE       :     int				= {}
		SCREAMING_SNAKE_CASE       :     Union[str, Any]				= os.path.join(_snake_case		,		'''all_results.json'''     )
		if os.path.exists(_snake_case     ):
				with open(_snake_case		,		'''r'''     ) as f:
						SCREAMING_SNAKE_CASE       :     Optional[int]				= json.load(_snake_case     )
		else:
				raise ValueError(F"can\'t find {path}"     )
		return results


lowerCamelCase__ :       Optional[int]						     =			logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)




@require_torch_tpu
class 				lowercase__(				_UpperCAmelCase   ):
	'''simple docstring'''

	def   __lowerCAmelCase (						self    :Any					)							->			Any:







			'''simple docstring'''




			import xla_spawn

			SCREAMING_SNAKE_CASE       :     int				= self.get_auto_remove_tmp_dir()
			SCREAMING_SNAKE_CASE       :     Optional[Any]				= 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(lowerCamelCase_		, '''argv'''		, lowerCamelCase_					):
					SCREAMING_SNAKE_CASE       :     Dict				= time()
					xla_spawn.main()
					SCREAMING_SNAKE_CASE       :     str				= time()

					SCREAMING_SNAKE_CASE       :     Any				= get_results(lowerCamelCase_					)
					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		, 5_00					)







	def   __lowerCAmelCase (						self    :int					)							->			Any:







			'''simple docstring'''




			import xla_spawn

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







"""simple docstring"""






import os
import sys

lowerCamelCase__ :       List[Any]						     =			os.path.join(os.path.dirname(__file__), "src")
sys.path.append(SRC_DIR)


from transformers import (
    AutoConfig,
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForMaskedLM,
    AutoModelForQuestionAnswering,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    add_start_docstrings,
)


lowerCamelCase__ :       str						     =			[
    "torch",
    "numpy",
    "tokenizers",
    "filelock",
    "requests",
    "tqdm",
    "regex",
    "sentencepiece",
    "sacremoses",
    "importlib_metadata",
    "huggingface_hub",
]





@add_start_docstrings(AutoConfig.__doc__     )
def __A						(   *a_ :							Any		,		**a_ :							Union[str, Any]     )->							Dict:




		'''simple docstring'''






		return AutoConfig.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoTokenizer.__doc__     )
def __A						(   *a_ :							str		,		**a_ :							Union[str, Any]     )->							Union[str, Any]:




		'''simple docstring'''






		return AutoTokenizer.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModel.__doc__     )
def __A						(   *a_ :							List[str]		,		**a_ :							int     )->							Dict:




		'''simple docstring'''






		return AutoModel.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForCausalLM.__doc__     )
def __A						(   *a_ :							Any		,		**a_ :							Tuple     )->							Dict:




		'''simple docstring'''






		return AutoModelForCausalLM.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForMaskedLM.__doc__     )
def __A						(   *a_ :							Dict		,		**a_ :							Optional[Any]     )->							Optional[int]:




		'''simple docstring'''






		return AutoModelForMaskedLM.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForSequenceClassification.__doc__     )
def __A						(   *a_ :							Optional[int]		,		**a_ :							str     )->							Optional[int]:




		'''simple docstring'''






		return AutoModelForSequenceClassification.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForQuestionAnswering.__doc__     )
def __A						(   *a_ :							List[str]		,		**a_ :							int     )->							List[Any]:




		'''simple docstring'''






		return AutoModelForQuestionAnswering.from_pretrained(*a_		,		**a_     )





