






'''simple docstring'''

from __future__ import annotations

from typing import Dict

from ...configuration_utils import PretrainedConfig


SCREAMING_SNAKE_CASE__           =  {
    'susnato/ernie-m-base_pytorch': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/config.json',
    'susnato/ernie-m-large_pytorch': 'https://huggingface.co/susnato/ernie-m-large_pytorch/blob/main/config.json',
}






class 							a_		(     _UpperCamelCase							):
  lowercase							= 'ernie_m'
  lowercase							= {"dropout": "classifier_dropout", "num_classes": "num_labels"}

  def __init__( self     ,						_SCREAMING_SNAKE_CASE = 250002     ,						_SCREAMING_SNAKE_CASE = 768     ,						_SCREAMING_SNAKE_CASE = 12     ,						_SCREAMING_SNAKE_CASE = 12     ,						_SCREAMING_SNAKE_CASE = 3072     ,						_SCREAMING_SNAKE_CASE = "gelu"     ,						_SCREAMING_SNAKE_CASE = 0.1     ,						_SCREAMING_SNAKE_CASE = 0.1     ,						_SCREAMING_SNAKE_CASE = 514     ,						_SCREAMING_SNAKE_CASE = 0.0_2     ,						_SCREAMING_SNAKE_CASE = 1     ,						_SCREAMING_SNAKE_CASE = 1e-05     ,						_SCREAMING_SNAKE_CASE=None     ,						_SCREAMING_SNAKE_CASE=False     ,						_SCREAMING_SNAKE_CASE=0.0     ,						**_SCREAMING_SNAKE_CASE     ,						)    -> List[Any]:



        """simple docstring"""






        super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE     ,						**_SCREAMING_SNAKE_CASE )
        UpperCamelCase							    =   vocab_size
        UpperCamelCase							    =   hidden_size
        UpperCamelCase							    =   num_hidden_layers
        UpperCamelCase							    =   num_attention_heads
        UpperCamelCase							    =   intermediate_size
        UpperCamelCase							    =   hidden_act
        UpperCamelCase							    =   hidden_dropout_prob
        UpperCamelCase							    =   attention_probs_dropout_prob
        UpperCamelCase							    =   max_position_embeddings
        UpperCamelCase							    =   initializer_range
        UpperCamelCase							    =   layer_norm_eps
        UpperCamelCase							    =   classifier_dropout
        UpperCamelCase							    =   is_decoder
        UpperCamelCase							    =   act_dropout






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)

a__		     =     logging.getLogger()





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


a__		     =     logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)







@require_torch_tpu
class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	def 					lowerCamelCase__     (					self		:						Dict	)	->       Dict:







						"""simple docstring"""







						import xla_spawn

						__UpperCamelCase					:	Dict             =      self.get_auto_remove_tmp_dir()
						__UpperCamelCase					:	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(lowerCAmelCase					,     """argv"""					,     lowerCAmelCase	):
											__UpperCamelCase					:	Union[str, Any]             =      time()
											xla_spawn.main()
											__UpperCamelCase					:	List[str]             =      time()

											__UpperCamelCase					:	Optional[int]             =      get_results(lowerCAmelCase	)
											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		:						int	)	->       List[Any]:







						"""simple docstring"""







						import xla_spawn

						__UpperCamelCase					:	List[Any]             =      """
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            """.split()
						with patch.object(lowerCAmelCase					,     """argv"""					,     lowerCAmelCase	):
											xla_spawn.main()






