




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a__		     =     logging.get_logger(__name__)

a__		     =     {
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}


class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	__magic_name__   :       Dict      	=		'xlm'
	__magic_name__   :       Optional[int]      	=		{
	    'hidden_size': 'emb_dim',
	    'num_attention_heads': 'n_heads',
	    'num_hidden_layers': 'n_layers',
	    'n_words': 'vocab_size',  # For backward compatibility
	}






	def __init__(					self		:						List[str]					,     lowerCAmelCase		:						Tuple=30145					,     lowerCAmelCase		:						str=2048					,     lowerCAmelCase		:						List[str]=12					,     lowerCAmelCase		:						Optional[Any]=16					,     lowerCAmelCase		:						Union[str, Any]=0.1					,     lowerCAmelCase		:						List[str]=0.1					,     lowerCAmelCase		:						Dict=True					,     lowerCAmelCase		:						Optional[Any]=False					,     lowerCAmelCase		:						Optional[Any]=False					,     lowerCAmelCase		:						Dict=False					,     lowerCAmelCase		:						str=1					,     lowerCAmelCase		:						Optional[Any]=True					,     lowerCAmelCase		:						Dict=512					,     lowerCAmelCase		:						List[Any]=2048**-0.5					,     lowerCAmelCase		:						List[str]=1E-12					,     lowerCAmelCase		:						Tuple=0.02					,     lowerCAmelCase		:						List[str]=0					,     lowerCAmelCase		:						Optional[Any]=1					,     lowerCAmelCase		:						Optional[int]=2					,     lowerCAmelCase		:						str=3					,     lowerCAmelCase		:						Union[str, Any]=5					,     lowerCAmelCase		:						int=True					,     lowerCAmelCase		:						Optional[Any]="first"					,     lowerCAmelCase		:						str=True					,     lowerCAmelCase		:						str=None					,     lowerCAmelCase		:						List[Any]=True					,     lowerCAmelCase		:						List[Any]=0.1					,     lowerCAmelCase		:						Union[str, Any]=5					,     lowerCAmelCase		:						Any=5					,     lowerCAmelCase		:						int=0					,     lowerCAmelCase		:						Optional[int]=0					,     lowerCAmelCase		:						int=2					,     lowerCAmelCase		:						List[Any]=0					,     **lowerCAmelCase		:						Union[str, Any]					,     )	->       Any:







						"""simple docstring"""







						__UpperCamelCase					:	Union[str, Any]             =      vocab_size
						__UpperCamelCase					:	Tuple             =      emb_dim
						__UpperCamelCase					:	Any             =      n_layers
						__UpperCamelCase					:	Dict             =      n_heads
						__UpperCamelCase					:	Optional[Any]             =      dropout
						__UpperCamelCase					:	Optional[int]             =      attention_dropout
						__UpperCamelCase					:	str             =      gelu_activation
						__UpperCamelCase					:	List[str]             =      sinusoidal_embeddings
						__UpperCamelCase					:	Any             =      causal
						__UpperCamelCase					:	Dict             =      asm
						__UpperCamelCase					:	Any             =      n_langs
						__UpperCamelCase					:	Any             =      use_lang_emb
						__UpperCamelCase					:	Optional[Any]             =      layer_norm_eps
						__UpperCamelCase					:	List[str]             =      bos_index
						__UpperCamelCase					:	Union[str, Any]             =      eos_index
						__UpperCamelCase					:	List[str]             =      pad_index
						__UpperCamelCase					:	int             =      unk_index
						__UpperCamelCase					:	Dict             =      mask_index
						__UpperCamelCase					:	Dict             =      is_encoder
						__UpperCamelCase					:	str             =      max_position_embeddings
						__UpperCamelCase					:	Union[str, Any]             =      embed_init_std
						__UpperCamelCase					:	Dict             =      init_std
						__UpperCamelCase					:	str             =      summary_type
						__UpperCamelCase					:	Tuple             =      summary_use_proj
						__UpperCamelCase					:	List[Any]             =      summary_activation
						__UpperCamelCase					:	Tuple             =      summary_proj_to_labels
						__UpperCamelCase					:	List[Any]             =      summary_first_dropout
						__UpperCamelCase					:	Any             =      start_n_top
						__UpperCamelCase					:	Tuple             =      end_n_top
						__UpperCamelCase					:	Tuple             =      mask_token_id
						__UpperCamelCase					:	List[str]             =      lang_id

						if "n_words" in kwargs:
											__UpperCamelCase					:	Union[str, Any]             =      kwargs["""n_words"""]

						super().__init__(pad_token_id=lowerCAmelCase					,     bos_token_id=lowerCAmelCase					,     **lowerCAmelCase	)






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


	@property
	def 					lowerCamelCase__     (					self		:						Union[str, Any]	)	->       Mapping[str, Mapping[int, str]]:







						"""simple docstring"""







						if self.task == "multiple-choice":
											__UpperCamelCase					:	Any             =      {0: """batch""", 1: """choice""", 2: """sequence"""}
						else:
											__UpperCamelCase					:	Any             =      {0: """batch""", 1: """sequence"""}
						return OrderedDict(
						    [
						        ("""input_ids""", dynamic_axis),
						        ("""attention_mask""", dynamic_axis),
						        ("""token_type_ids""", dynamic_axis),
						    ]	)












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






