






import warnings

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


A        =			logging.get_logger(__name__)

A        =			{
    '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 							__a							(  UpperCAmelCase__						):





		'''simple docstring'''



		UpperCAmelCase__      :				Optional[int]				    =						'xlnet'
		UpperCAmelCase__      :				List[str]				    =						['mems']
		UpperCAmelCase__      :				int				    =						{
		    'n_token': 'vocab_size',  # Backward compatibility
		    'hidden_size': 'd_model',
		    'num_attention_heads': 'n_head',
		    'num_hidden_layers': 'n_layer',
		}


		def __init__(						self ,    UpperCamelCase__=32000 ,    UpperCamelCase__=1024 ,    UpperCamelCase__=24 ,    UpperCamelCase__=16 ,    UpperCamelCase__=4096 ,    UpperCamelCase__="gelu" ,    UpperCamelCase__=True ,    UpperCamelCase__="bi" ,    UpperCamelCase__=0.02 ,    UpperCamelCase__=1E-12 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=512 ,    UpperCamelCase__=None ,    UpperCamelCase__=True ,    UpperCamelCase__=False ,    UpperCamelCase__=False ,    UpperCamelCase__=-1 ,    UpperCamelCase__=False ,    UpperCamelCase__="last" ,    UpperCamelCase__=True ,    UpperCamelCase__="tanh" ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=5 ,    UpperCamelCase__=5 ,    UpperCamelCase__=5 ,    UpperCamelCase__=1 ,    UpperCamelCase__=2 ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   vocab_size
						SCREAMING_SNAKE_CASE_   :	Tuple													=   d_model
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   n_layer
						SCREAMING_SNAKE_CASE_   :	int													=   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})'''       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   d_model // n_head
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   ff_activation
						SCREAMING_SNAKE_CASE_   :	Any													=   d_inner
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   untie_r
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   attn_type

						SCREAMING_SNAKE_CASE_   :	int													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	Dict													=   layer_norm_eps

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   dropout
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   mem_len
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   reuse_len
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   bi_data
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   clamp_len
						SCREAMING_SNAKE_CASE_   :	Tuple													=   same_length

						SCREAMING_SNAKE_CASE_   :	int													=   summary_type
						SCREAMING_SNAKE_CASE_   :	List[str]													=   summary_use_proj
						SCREAMING_SNAKE_CASE_   :	str													=   summary_activation
						SCREAMING_SNAKE_CASE_   :	Tuple													=   summary_last_dropout
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   start_n_top
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   end_n_top

						SCREAMING_SNAKE_CASE_   :	int													=   bos_token_id
						SCREAMING_SNAKE_CASE_   :	Any													=   pad_token_id
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   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.' ,    UpperCamelCase__ ,    )
										SCREAMING_SNAKE_CASE_   :	List[Any]													=   kwargs["""use_cache"""]

						SCREAMING_SNAKE_CASE_   :	str													=   use_mems_eval
						SCREAMING_SNAKE_CASE_   :	List[str]													=   use_mems_train
						super().__init__(pad_token_id=UpperCamelCase__ ,    bos_token_id=UpperCamelCase__ ,    eos_token_id=UpperCamelCase__ ,    **UpperCamelCase__       )


		@property
		def   __snake_case			(						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   __snake_case			(						self ,    UpperCamelCase__       ):
						raise NotImplementedError(
						    F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''       )







from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class 							__a							(  __A						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   SMALL_MODEL_IDENTIFIER
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   'pt'
						SCREAMING_SNAKE_CASE_   :	Tuple													=   'tf'


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   AutoModel.from_pretrained(self.test_model       )
						model_pt.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   TFAutoModel.from_pretrained(self.test_model ,    from_pt=UpperCamelCase__       )
						model_tf.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   'mock_framework'

						# Framework provided - return whatever the user provides
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model ,    UpperCamelCase__       )
						self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# Local checkpoint and framework provided - return provided framework
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Dict													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	List[str]													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Invalid local checkpoint
						with TemporaryDirectory() as local_invalid_ckpt:
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Any													=   FeaturesManager.determine_framework(UpperCamelCase__       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	str													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# PyTorch not in environment -> use TensorFlow
						SCREAMING_SNAKE_CASE_   :	List[str]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Both in environment -> use PyTorch
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# Both not in environment -> raise error
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Optional[int]													=   FeaturesManager.determine_framework(self.test_model       )