



'''simple docstring'''





import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A__    :   Optional[Any]           =					logging.get_logger(__name__)

A__    :   List[Any]           =					{
    '''xlnet-base-cased''': '''https://huggingface.co/xlnet-base-cased/resolve/main/config.json''',
    '''xlnet-large-cased''': '''https://huggingface.co/xlnet-large-cased/resolve/main/config.json''',
}



class  snake_case__						(    SCREAMING_SNAKE_CASE_				):
 A__				= '''xlnet'''
 A__				= ['''mems''']
 A__				= {
     '''n_token''': '''vocab_size''',  # Backward compatibility
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''n_head''',
     '''num_hidden_layers''': '''n_layer''',
 }
 def __init__(   self						:							Union[str, Any]      ,     __a						:							Union[str, Any]=32000      ,     __a						:							int=1024      ,     __a						:							List[Any]=24      ,     __a						:							Optional[Any]=16      ,     __a						:							Union[str, Any]=4096      ,     __a						:							List[str]="gelu"      ,     __a						:							Union[str, Any]=True      ,     __a						:							int="bi"      ,     __a						:							List[Any]=0.0_2      ,     __a						:							Union[str, Any]=1e-12      ,     __a						:							Optional[int]=0.1      ,     __a						:							Any=512      ,     __a						:							Dict=None      ,     __a						:							Tuple=True      ,     __a						:							Union[str, Any]=False      ,     __a						:							int=False      ,     __a						:							int=-1      ,     __a						:							List[str]=False      ,     __a						:							Any="last"      ,     __a						:							Any=True      ,     __a						:							Dict="tanh"      ,     __a						:							str=0.1      ,     __a						:							List[str]=5      ,     __a						:							List[Any]=5      ,     __a						:							Dict=5      ,     __a						:							List[Any]=1      ,     __a						:							int=2      ,     **__a						:							Union[str, Any]      ,     )      ->   int:







       '''simple docstring'''
       __snake_case :   List[str]													=    vocab_size
       __snake_case :   Optional[Any]													=    d_model
       __snake_case :   Dict													=    n_layer
       __snake_case :   Optional[Any]													=    n_head
       if d_model % n_head != 0:
             raise ValueError(f'''\'d_model % n_head\' ({d_model % n_head}) should be equal to 0'''  )
       if "d_head" in kwargs:
             if kwargs["d_head"] != d_model // n_head:
                   raise ValueError(
                       f'''`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})'''  )
       __snake_case :   Tuple													=    d_model // n_head
       __snake_case :   Optional[int]													=    ff_activation
       __snake_case :   Tuple													=    d_inner
       __snake_case :   Tuple													=    untie_r
       __snake_case :   List[Any]													=    attn_type

       __snake_case :   Any													=    initializer_range
       __snake_case :   Dict													=    layer_norm_eps

       __snake_case :   int													=    dropout
       __snake_case :   str													=    mem_len
       __snake_case :   Union[str, Any]													=    reuse_len
       __snake_case :   Optional[int]													=    bi_data
       __snake_case :   Dict													=    clamp_len
       __snake_case :   str													=    same_length

       __snake_case :   Dict													=    summary_type
       __snake_case :   Union[str, Any]													=    summary_use_proj
       __snake_case :   str													=    summary_activation
       __snake_case :   str													=    summary_last_dropout
       __snake_case :   Dict													=    start_n_top
       __snake_case :   int													=    end_n_top

       __snake_case :   Optional[int]													=    bos_token_id
       __snake_case :   int													=    pad_token_id
       __snake_case :   Dict													=    eos_token_id

       if "use_cache" in kwargs:
             warnings.warn(
                 'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
                 ' instead.'      ,     __a      ,     )
             __snake_case :   List[str]													=    kwargs['use_cache']

       __snake_case :   Tuple													=    use_mems_eval
       __snake_case :   List[str]													=    use_mems_train
       super().__init__(pad_token_id=__a      ,     bos_token_id=__a      ,     eos_token_id=__a      ,     **__a  )
 @property
 def A_   (   self						:							List[Any]  )      ->   Union[str, Any]:







       '''simple docstring'''
       logger.info(f'''The model {self.model_type} is one of the few models that has no sequence length limit.'''  )
       return -1





 @max_position_embeddings.setter
 def A_   (   self						:							Dict      ,     __a						:							Any  )      ->   List[Any]:







       '''simple docstring'''
       # Message copied from Transformer-XL documentation
       raise NotImplementedError(
           f'''The model {self.model_type} is one of the few models that has no sequence length limit.'''  )








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

A__    :   List[str]           =					logging.getLogger()





def   a_   (		_UpperCAmelCase    :      int				)    ->  Optional[int]:
      __snake_case :   List[str]													=    {}
      __snake_case :   List[str]													=    os.path.join(_UpperCAmelCase ,'all_results.json'				)
      if os.path.exists(_UpperCAmelCase				):
            with open(_UpperCAmelCase ,'r'				) as f:
                  __snake_case :   Dict													=    json.load(_UpperCAmelCase				)
      else:
            raise ValueError(f'''can\'t find {path}'''				)
      return results


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





@require_torch_tpu
class  snake_case__						(    SCREAMING_SNAKE_CASE_				):
 def A_   (   self						:							Optional[Any]  )      ->   List[str]:







       '''simple docstring'''
       import xla_spawn

       __snake_case :   int													=    self.get_auto_remove_tmp_dir()
       __snake_case :   Tuple													=    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(__a      ,     'argv'      ,     __a  ):
             __snake_case :   Tuple													=    time()
             xla_spawn.main()
             __snake_case :   Optional[int]													=    time()

             __snake_case :   List[Any]													=    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      ,     500  )





 def A_   (   self						:							List[str]  )      ->   Optional[int]:







       '''simple docstring'''
       import xla_spawn

       __snake_case :   Optional[Any]													=    '\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()



