


"""simple docstring"""







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


a__				:							Any						=     logging.get_logger(__name__)

a__				:							Union[str, Any]						=     {
    '''transfo-xl-wt103''': '''https://huggingface.co/transfo-xl-wt103/resolve/main/config.json''',
}




class  UpperCamelCase_	( UpperCamelCase):

	"""simple docstring"""





	snake_case__				:  Optional[int]    					=			"transfo-xl"
	snake_case__				:  Optional[Any]    					=			["mems"]
	snake_case__				:  List[Any]    					=			{
	    "n_token": "vocab_size",
	    "hidden_size": "d_model",
	    "num_attention_heads": "n_head",
	    "num_hidden_layers": "n_layer",
	}




	def __init__( self			:				List[Any]			,			UpperCAmelCase__			:				Union[str, Any]=2_6_7_7_3_5			,			UpperCAmelCase__			:				str=[2_0_0_0_0, 4_0_0_0_0, 2_0_0_0_0_0]			,			UpperCAmelCase__			:				int=1_0_2_4			,			UpperCAmelCase__			:				Optional[int]=1_0_2_4			,			UpperCAmelCase__			:				Union[str, Any]=1_6			,			UpperCAmelCase__			:				Union[str, Any]=6_4			,			UpperCAmelCase__			:				List[Any]=4_0_9_6			,			UpperCAmelCase__			:				Any=4			,			UpperCAmelCase__			:				Any=False			,			UpperCAmelCase__			:				List[str]=1_8			,			UpperCAmelCase__			:				Dict=1_6_0_0			,			UpperCAmelCase__			:				Optional[Any]=1_0_0_0			,			UpperCAmelCase__			:				List[str]=True			,			UpperCAmelCase__			:				Dict=True			,			UpperCAmelCase__			:				Union[str, Any]=0			,			UpperCAmelCase__			:				str=-1			,			UpperCAmelCase__			:				str=True			,			UpperCAmelCase__			:				Optional[int]=0.1			,			UpperCAmelCase__			:				Any=0.0			,			UpperCAmelCase__			:				Any=True			,			UpperCAmelCase__			:				List[Any]="normal"			,			UpperCAmelCase__			:				Any=0.01			,			UpperCAmelCase__			:				str=0.01			,			UpperCAmelCase__			:				Any=0.02			,			UpperCAmelCase__			:				Tuple=1E-5			,			UpperCAmelCase__			:				Optional[int]=0			,			**UpperCAmelCase__			:				Optional[Any]			,			)       ->	List[Any]:
						__SCREAMING_SNAKE_CASE						   =				vocab_size
						__SCREAMING_SNAKE_CASE						   =				[]
						self.cutoffs.extend(UpperCAmelCase__   )
						if proj_share_all_but_first:
											__SCREAMING_SNAKE_CASE						   =				[False] + [True] * len(self.cutoffs   )
						else:
											__SCREAMING_SNAKE_CASE						   =				[False] + [False] * len(self.cutoffs   )
						__SCREAMING_SNAKE_CASE						   =				d_model
						__SCREAMING_SNAKE_CASE						   =				d_embed
						__SCREAMING_SNAKE_CASE						   =				d_head
						__SCREAMING_SNAKE_CASE						   =				d_inner
						__SCREAMING_SNAKE_CASE						   =				div_val
						__SCREAMING_SNAKE_CASE						   =				pre_lnorm
						__SCREAMING_SNAKE_CASE						   =				n_layer
						__SCREAMING_SNAKE_CASE						   =				n_head
						__SCREAMING_SNAKE_CASE						   =				mem_len
						__SCREAMING_SNAKE_CASE						   =				same_length
						__SCREAMING_SNAKE_CASE						   =				attn_type
						__SCREAMING_SNAKE_CASE						   =				clamp_len
						__SCREAMING_SNAKE_CASE						   =				sample_softmax
						__SCREAMING_SNAKE_CASE						   =				adaptive
						__SCREAMING_SNAKE_CASE						   =				dropout
						__SCREAMING_SNAKE_CASE						   =				dropatt
						__SCREAMING_SNAKE_CASE						   =				untie_r
						__SCREAMING_SNAKE_CASE						   =				init
						__SCREAMING_SNAKE_CASE						   =				init_range
						__SCREAMING_SNAKE_CASE						   =				proj_init_std
						__SCREAMING_SNAKE_CASE						   =				init_std
						__SCREAMING_SNAKE_CASE						   =				layer_norm_epsilon
						super().__init__(eos_token_id=UpperCAmelCase__			,			**UpperCAmelCase__   )




	@property
	def   UpperCAmelCase_      ( self			:				Union[str, Any]   )       ->	str:
						# Message copied from Transformer-XL documentation
						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   UpperCAmelCase_      ( self			:				str			,			UpperCAmelCase__			:				str   )       ->	Optional[int]:
						# 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    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					return x + 2




class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Any   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"x = 3"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3}   )

						__SCREAMING_SNAKE_CASE						   =				"x = y"
						__SCREAMING_SNAKE_CASE						   =				{"y": 5}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 5, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Dict   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"y = add_two(x)"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )

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




	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	List[Any]:
						__SCREAMING_SNAKE_CASE						   =				"x = 3"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3}   )




	def   UpperCAmelCase_      ( self			:				str   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"test_dict = {'x': x, 'y': add_two(x)}"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_dict": {"x": 3, "y": 5}}   )




	def   UpperCAmelCase_      ( self			:				int   )       ->	Optional[Any]:
						__SCREAMING_SNAKE_CASE						   =				"x = 3\ny = 5"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"text = f'This is x: {x}.'"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == "This is x: 3."
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "text": "This is x: 3."}   )




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

						__SCREAMING_SNAKE_CASE						   =				{"x": 8}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 8, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Tuple   )       ->	str:
						__SCREAMING_SNAKE_CASE						   =				"test_list = [x, add_two(x)]"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						self.assertListEqual(UpperCAmelCase__			,			[3, 5]   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_list": [3, 5]}   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				"y = x"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 3}   )




	def   UpperCAmelCase_      ( self			:				Tuple   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				"test_list = [x, add_two(x)]\ntest_list[1]"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_list": [3, 5]}   )

						__SCREAMING_SNAKE_CASE						   =				"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_dict": {"x": 3, "y": 5}}   )




	def   UpperCAmelCase_      ( self			:				List[str]   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"x = 0\nfor i in range(3):\n    x = i"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"range": range}			,			state=UpperCAmelCase__   )
						assert result == 2
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 2, "i": 2}   )
