
import warnings

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


lowercase__		:List[Any]			  =   logging.get_logger(__name__)

lowercase__		: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     lowercase		( SCREAMING_SNAKE_CASE__		):
       lowercase_	:	List[Any]	 ='''xlnet'''
       lowercase_	:	int	 =['''mems''']
       lowercase_	:	Any	 ={
           '''n_token''': '''vocab_size''',  # Backward compatibility
           '''hidden_size''': '''d_model''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }




       def __init__(    self       ,A__=3_2_0_0_0       ,A__=1_0_2_4       ,A__=2_4       ,A__=1_6       ,A__=4_0_9_6       ,A__="gelu"       ,A__=True       ,A__="bi"       ,A__=0.02       ,A__=1E-12       ,A__=0.1       ,A__=5_1_2       ,A__=None       ,A__=True       ,A__=False       ,A__=False       ,A__=-1       ,A__=False       ,A__="last"       ,A__=True       ,A__="tanh"       ,A__=0.1       ,A__=5       ,A__=5       ,A__=5       ,A__=1       ,A__=2       ,**A__       ,):
            lowercase						     =						vocab_size
            lowercase						     =						d_model
            lowercase						     =						n_layer
            lowercase						     =						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})')
            lowercase						     =						d_model // n_head
            lowercase						     =						ff_activation
            lowercase						     =						d_inner
            lowercase						     =						untie_r
            lowercase						     =						attn_type

            lowercase						     =						initializer_range
            lowercase						     =						layer_norm_eps

            lowercase						     =						dropout
            lowercase						     =						mem_len
            lowercase						     =						reuse_len
            lowercase						     =						bi_data
            lowercase						     =						clamp_len
            lowercase						     =						same_length

            lowercase						     =						summary_type
            lowercase						     =						summary_use_proj
            lowercase						     =						summary_activation
            lowercase						     =						summary_last_dropout
            lowercase						     =						start_n_top
            lowercase						     =						end_n_top

            lowercase						     =						bos_token_id
            lowercase						     =						pad_token_id
            lowercase						     =						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__       ,)
                 lowercase						     =						kwargs['''use_cache''']

            lowercase						     =						use_mems_eval
            lowercase						     =						use_mems_train
            super().__init__(pad_token_id=A__       ,bos_token_id=A__       ,eos_token_id=A__       ,**A__)




       @property
       def 			A__				(    self):
            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       ,A__):
            # 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.')






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
							import numpy as np
							import tensorflow as tf

							from transformers import TFXLMRobertaModel







@require_tf
@require_sentencepiece
@require_tokenizers
class     lowercase		( unittest.TestCase		):




							@slow
							def 			A__				(    self):
												lowercase						     =						TFXLMRobertaModel.from_pretrained('''jplu/tf-xlm-roberta-base''')

												lowercase						     =						{
												    '''input_ids''': tf.convert_to_tensor([[0, 2_6_4_6, 1_0_2_6_9, 8_3, 9_9_9_4_2, 2]]       ,dtype=tf.intaa),  # "My dog is cute"
												    '''attention_mask''': tf.convert_to_tensor([[1, 1, 1, 1, 1, 1]]       ,dtype=tf.intaa),
												}

												lowercase						     =						model(A__)['''last_hidden_state''']
												lowercase						     =						tf.TensorShape((1, 6, 7_6_8))
												self.assertEqual(output.shape       ,A__)
												# compare the actual values for a slice.
												lowercase						     =						tf.convert_to_tensor(
												    [
												        [
												            [0.0681762, 0.10894451, 0.06772504],
												            [-0.06423668, 0.02366615, 0.04329344],
												            [-0.06057295, 0.09974135, -0.00070584],
												        ]
												    ]       ,dtype=tf.floataa       ,)

												self.assertTrue(np.allclose(output[:, :3, :3].numpy()       ,expected_slice.numpy()       ,atol=1E-4))




