



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)

UpperCAmelCase__       =	logging.getLogger()





def 							A     (					_UpperCAmelCase    :       List[str]   )    ->			Optional[Any]:







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


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







@require_torch_tpu
class       __lowerCAmelCase   (      A						):



			def    _lowerCamelCase	(						self       :  str)       ->   List[str]:



						"""simple docstring"""






						import xla_spawn

						_UpperCAmelCase			=       self.get_auto_remove_tmp_dir()
						_UpperCAmelCase			=       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):
									_UpperCAmelCase			=       time()
									xla_spawn.main()
									_UpperCAmelCase			=       time()

									_UpperCAmelCase			=       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			,		5_00)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[Any]:



						"""simple docstring"""






						import xla_spawn

						_UpperCAmelCase			=       '\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()





from collections import OrderedDict
from typing import Mapping

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


UpperCAmelCase__       =	logging.get_logger(__name__)

UpperCAmelCase__       =	{
    "facebook/xmod-base": "https://huggingface.co/facebook/xmod-base/resolve/main/config.json",
    "facebook/xmod-large-prenorm": "https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json",
    "facebook/xmod-base-13-125k": "https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json",
    "facebook/xmod-base-30-125k": "https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json",
    "facebook/xmod-base-30-195k": "https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json",
    "facebook/xmod-base-60-125k": "https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json",
    "facebook/xmod-base-60-265k": "https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json",
    "facebook/xmod-base-75-125k": "https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json",
    "facebook/xmod-base-75-269k": "https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json",
}







class       __lowerCAmelCase   (      A						):
			UpperCamelCase        =					'''xmod'''



			def __init__(						self       :  Optional[int]			,		A       :  int=3_05_22			,		A       :  Tuple=7_68			,		A       :  Optional[Any]=12			,		A       :  Tuple=12			,		A       :  str=30_72			,		A       :  List[str]="gelu"			,		A       :  Any=0.1			,		A       :  int=0.1			,		A       :  Dict=5_12			,		A       :  Optional[Any]=2			,		A       :  Optional[Any]=0.0_2			,		A       :  List[Any]=1E-12			,		A       :  int=1			,		A       :  Tuple=0			,		A       :  Optional[Any]=2			,		A       :  int="absolute"			,		A       :  Union[str, Any]=True			,		A       :  List[Any]=None			,		A       :  Optional[Any]=False			,		A       :  List[str]=2			,		A       :  int=False			,		A       :  str=True			,		A       :  Optional[Any]=True			,		A       :  Tuple=("en_XX",)			,		A       :  Optional[int]=None			,		**A       :  List[str]			,		)       ->   Dict:



						"""simple docstring"""






						super().__init__(pad_token_id=A			,		bos_token_id=A			,		eos_token_id=A			,		**A)

						_UpperCAmelCase			=       vocab_size
						_UpperCAmelCase			=       hidden_size
						_UpperCAmelCase			=       num_hidden_layers
						_UpperCAmelCase			=       num_attention_heads
						_UpperCAmelCase			=       hidden_act
						_UpperCAmelCase			=       intermediate_size
						_UpperCAmelCase			=       hidden_dropout_prob
						_UpperCAmelCase			=       attention_probs_dropout_prob
						_UpperCAmelCase			=       max_position_embeddings
						_UpperCAmelCase			=       type_vocab_size
						_UpperCAmelCase			=       initializer_range
						_UpperCAmelCase			=       layer_norm_eps
						_UpperCAmelCase			=       position_embedding_type
						_UpperCAmelCase			=       use_cache
						_UpperCAmelCase			=       classifier_dropout
						_UpperCAmelCase			=       pre_norm
						_UpperCAmelCase			=       adapter_reduction_factor
						_UpperCAmelCase			=       adapter_layer_norm
						_UpperCAmelCase			=       adapter_reuse_layer_norm
						_UpperCAmelCase			=       ln_before_adapter
						_UpperCAmelCase			=       list(A)
						_UpperCAmelCase			=       default_language







class       __lowerCAmelCase   (      A						):



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



						"""simple docstring"""






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