




"""simple docstring"""







import warnings

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


__A   :  str					=      logging.get_logger(__name__)

__A   :  Optional[int]					=      {
    '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       lowerCAmelCase__       (			lowerCAmelCase_    ):


				"""simple docstring"""





				__UpperCAmelCase :     Any       =      "xlnet"
				__UpperCAmelCase :     List[str]       =      ["mems"]
				__UpperCAmelCase :     str       =      {
				    "n_token": "vocab_size",  # Backward compatibility
				    "hidden_size": "d_model",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}



				def __init__(     self					:	Tuple    ,   lowercase__					:	Optional[int]=3_2_0_0_0    ,   lowercase__					:	str=1_0_2_4    ,   lowercase__					:	List[str]=2_4    ,   lowercase__					:	int=1_6    ,   lowercase__					:	Dict=4_0_9_6    ,   lowercase__					:	Union[str, Any]="gelu"    ,   lowercase__					:	Dict=True    ,   lowercase__					:	Optional[int]="bi"    ,   lowercase__					:	List[Any]=0.0_2    ,   lowercase__					:	List[Any]=1e-12    ,   lowercase__					:	Optional[Any]=0.1    ,   lowercase__					:	Optional[int]=5_1_2    ,   lowercase__					:	List[Any]=None    ,   lowercase__					:	Optional[int]=True    ,   lowercase__					:	List[str]=False    ,   lowercase__					:	str=False    ,   lowercase__					:	Any=-1    ,   lowercase__					:	int=False    ,   lowercase__					:	str="last"    ,   lowercase__					:	Any=True    ,   lowercase__					:	List[str]="tanh"    ,   lowercase__					:	Tuple=0.1    ,   lowercase__					:	Any=5    ,   lowercase__					:	str=5    ,   lowercase__					:	Optional[Any]=5    ,   lowercase__					:	Any=1    ,   lowercase__					:	str=2    ,   **lowercase__					:	Tuple    ,   ):
						__lowercase				:		Optional[int]												=				vocab_size
						__lowercase				:		Any												=				d_model
						__lowercase				:		Tuple												=				n_layer
						__lowercase				:		str												=				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				:		Tuple												=				d_model // n_head
						__lowercase				:		List[str]												=				ff_activation
						__lowercase				:		List[str]												=				d_inner
						__lowercase				:		Union[str, Any]												=				untie_r
						__lowercase				:		List[Any]												=				attn_type

						__lowercase				:		Any												=				initializer_range
						__lowercase				:		Optional[Any]												=				layer_norm_eps

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

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

						__lowercase				:		List[Any]												=				bos_token_id
						__lowercase				:		Dict												=				pad_token_id
						__lowercase				:		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."    ,   lowercase__    ,   )
								__lowercase				:		Tuple												=				kwargs["use_cache"]

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



				@property
				def       snake_case    (     self					:	str						):
						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					:	Dict    ,   lowercase__					:	Dict						):
						# 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 unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate

def 						snake_case__       (					_lowerCamelCase				)			->Dict:






		"""simple docstring"""


		return x + 2





class       lowerCAmelCase__       (			unittest.TestCase    ):


				"""simple docstring"""





				def       snake_case    (     self					:	List[str]						):
						__lowercase				:		List[Any]												=				"x = 3"
						__lowercase				:		Optional[int]												=				{}
						__lowercase				:		List[Any]												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						assert result == 3
						self.assertDictEqual(lowercase__    ,   {"x": 3}						)

						__lowercase				:		Optional[int]												=				"x = y"
						__lowercase				:		Union[str, Any]												=				{"y": 5}
						__lowercase				:		str												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 5, "y": 5}						)



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		Dict												=				"y = add_two(x)"
						__lowercase				:		List[Any]												=				{"x": 3}
						__lowercase				:		Optional[int]												=				evaluate(lowercase__    ,   {"add_two": add_two}    ,   state=lowercase__						)
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 3, "y": 5}						)

						# Won't work without the tool
						with CaptureStdout() as out:
								__lowercase				:		Any												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						assert result is None
						assert "tried to execute add_two" in out.out



				def       snake_case    (     self					:	Any						):
						__lowercase				:		Optional[Any]												=				"x = 3"
						__lowercase				:		List[Any]												=				{}
						__lowercase				:		Dict												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						assert result == 3
						self.assertDictEqual(lowercase__    ,   {"x": 3}						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		Optional[int]												=				"test_dict = {'x': x, 'y': add_two(x)}"
						__lowercase				:		List[str]												=				{"x": 3}
						__lowercase				:		Tuple												=				evaluate(lowercase__    ,   {"add_two": add_two}    ,   state=lowercase__						)
						self.assertDictEqual(lowercase__    ,   {"x": 3, "y": 5}						)
						self.assertDictEqual(lowercase__    ,   {"x": 3, "test_dict": {"x": 3, "y": 5}}						)



				def       snake_case    (     self					:	int						):
						__lowercase				:		Tuple												=				"x = 3\ny = 5"
						__lowercase				:		Optional[Any]												=				{}
						__lowercase				:		List[Any]												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 3, "y": 5}						)



				def       snake_case    (     self					:	Any						):
						__lowercase				:		str												=				"text = f'This is x: {x}.'"
						__lowercase				:		Any												=				{"x": 3}
						__lowercase				:		List[Any]												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						# evaluate returns the value of the last assignment.
						assert result == "This is x: 3."
						self.assertDictEqual(lowercase__    ,   {"x": 3, "text": "This is x: 3."}						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		Optional[Any]												=				"if x <= 3:\n    y = 2\nelse:\n    y = 5"
						__lowercase				:		int												=				{"x": 3}
						__lowercase				:		Optional[int]												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						# evaluate returns the value of the last assignment.
						assert result == 2
						self.assertDictEqual(lowercase__    ,   {"x": 3, "y": 2}						)

						__lowercase				:		Optional[int]												=				{"x": 8}
						__lowercase				:		Union[str, Any]												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 8, "y": 5}						)



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		Optional[Any]												=				"test_list = [x, add_two(x)]"
						__lowercase				:		str												=				{"x": 3}
						__lowercase				:		Any												=				evaluate(lowercase__    ,   {"add_two": add_two}    ,   state=lowercase__						)
						self.assertListEqual(lowercase__    ,   [3, 5]						)
						self.assertDictEqual(lowercase__    ,   {"x": 3, "test_list": [3, 5]}						)



				def       snake_case    (     self					:	Optional[int]						):
						__lowercase				:		str												=				"y = x"
						__lowercase				:		str												=				{"x": 3}
						__lowercase				:		int												=				evaluate(lowercase__    ,   {}    ,   state=lowercase__						)
						assert result == 3
						self.assertDictEqual(lowercase__    ,   {"x": 3, "y": 3}						)



				def       snake_case    (     self					:	Optional[int]						):
						__lowercase				:		str												=				"test_list = [x, add_two(x)]\ntest_list[1]"
						__lowercase				:		Optional[Any]												=				{"x": 3}
						__lowercase				:		Any												=				evaluate(lowercase__    ,   {"add_two": add_two}    ,   state=lowercase__						)
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 3, "test_list": [3, 5]}						)

						__lowercase				:		Tuple												=				"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
						__lowercase				:		Union[str, Any]												=				{"x": 3}
						__lowercase				:		Tuple												=				evaluate(lowercase__    ,   {"add_two": add_two}    ,   state=lowercase__						)
						assert result == 5
						self.assertDictEqual(lowercase__    ,   {"x": 3, "test_dict": {"x": 3, "y": 5}}						)



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		Dict												=				"x = 0\nfor i in range(3):\n    x = i"
						__lowercase				:		str												=				{}
						__lowercase				:		int												=				evaluate(lowercase__    ,   {"range": range}    ,   state=lowercase__						)
						assert result == 2
						self.assertDictEqual(lowercase__    ,   {"x": 2, "i": 2}						)
