

import unittest

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







def 			A_      (    _UpperCAmelCase    ):
						return x + 2



class   __lowercase				( unittest.TestCase	):




			"""simple docstring"""







			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       """x = 3"""
									SCREAMING_SNAKE_CASE_: int  		=       {}
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       evaluate(A__   ,						{}   ,						state=A__)
									assert result == 3
									self.assertDictEqual(A__   ,						{"x": 3})

									SCREAMING_SNAKE_CASE_: Any  		=       """x = y"""
									SCREAMING_SNAKE_CASE_: int  		=       {"""y""": 5}
									SCREAMING_SNAKE_CASE_: List[Any]  		=       evaluate(A__   ,						{}   ,						state=A__)
									# evaluate returns the value of the last assignment.
									assert result == 5
									self.assertDictEqual(A__   ,						{"x": 5, "y": 5})



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Any  		=       """y = add_two(x)"""
									SCREAMING_SNAKE_CASE_: List[str]  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       evaluate(A__   ,						{"add_two": add_two}   ,						state=A__)
									assert result == 5
									self.assertDictEqual(A__   ,						{"x": 3, "y": 5})

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



			def        _SCREAMING_SNAKE_CASE			( self  :     List[Any]):
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       """x = 3"""
									SCREAMING_SNAKE_CASE_: List[Any]  		=       {}
									SCREAMING_SNAKE_CASE_: List[Any]  		=       evaluate(A__   ,						{}   ,						state=A__)
									assert result == 3
									self.assertDictEqual(A__   ,						{"x": 3})



			def        _SCREAMING_SNAKE_CASE			( self  :     str):
									SCREAMING_SNAKE_CASE_: List[str]  		=       """test_dict = {'x': x, 'y': add_two(x)}"""
									SCREAMING_SNAKE_CASE_: Dict  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: List[Any]  		=       evaluate(A__   ,						{"add_two": add_two}   ,						state=A__)
									self.assertDictEqual(A__   ,						{"x": 3, "y": 5})
									self.assertDictEqual(A__   ,						{"x": 3, "test_dict": {"x": 3, "y": 5}})



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									SCREAMING_SNAKE_CASE_: Dict  		=       """x = 3\ny = 5"""
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       {}
									SCREAMING_SNAKE_CASE_: Tuple  		=       evaluate(A__   ,						{}   ,						state=A__)
									# evaluate returns the value of the last assignment.
									assert result == 5
									self.assertDictEqual(A__   ,						{"x": 3, "y": 5})



			def        _SCREAMING_SNAKE_CASE			( self  :     str):
									SCREAMING_SNAKE_CASE_: Any  		=       """text = f'This is x: {x}.'"""
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: int  		=       evaluate(A__   ,						{}   ,						state=A__)
									# evaluate returns the value of the last assignment.
									assert result == "This is x: 3."
									self.assertDictEqual(A__   ,						{"x": 3, "text": "This is x: 3."})



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

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



			def        _SCREAMING_SNAKE_CASE			( self  :     Tuple):
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       """test_list = [x, add_two(x)]"""
									SCREAMING_SNAKE_CASE_: List[Any]  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       evaluate(A__   ,						{"add_two": add_two}   ,						state=A__)
									self.assertListEqual(A__   ,						[3, 5])
									self.assertDictEqual(A__   ,						{"x": 3, "test_list": [3, 5]})



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									SCREAMING_SNAKE_CASE_: Tuple  		=       """y = x"""
									SCREAMING_SNAKE_CASE_: List[Any]  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: List[Any]  		=       evaluate(A__   ,						{}   ,						state=A__)
									assert result == 3
									self.assertDictEqual(A__   ,						{"x": 3, "y": 3})



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									SCREAMING_SNAKE_CASE_: List[Any]  		=       """test_list = [x, add_two(x)]\ntest_list[1]"""
									SCREAMING_SNAKE_CASE_: str  		=       {"""x""": 3}
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       evaluate(A__   ,						{"add_two": add_two}   ,						state=A__)
									assert result == 5
									self.assertDictEqual(A__   ,						{"x": 3, "test_list": [3, 5]})

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




			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       """x = 0\nfor i in range(3):\n    x = i"""
									SCREAMING_SNAKE_CASE_: List[str]  		=       {}
									SCREAMING_SNAKE_CASE_: List[str]  		=       evaluate(A__   ,						{"range": range}   ,						state=A__)
									assert result == 2
									self.assertDictEqual(A__   ,						{"x": 2, "i": 2})









import argparse

import torch

from ...utils import logging
from . import AlbertConfig, AlbertForPreTraining, load_tf_weights_in_albert


logging.set_verbosity_info()

def 						UpperCamelCase					(lowercase_: Optional[int]    ,      lowercase_: Union[str, Any]    ,      lowercase_: Optional[Any]					)     ->      Tuple:
	# Initialise PyTorch model
	A__							:    str        =		AlbertConfig.from_json_file(lowercase_					)
	print(f"""Building PyTorch model from configuration: {config}"""					)
	A__							:    List[Any]        =		AlbertForPreTraining(lowercase_					)

	# Load weights from tf checkpoint
	load_tf_weights_in_albert(lowercase_    ,      lowercase_    ,      lowercase_					)

	# Save pytorch-model
	print(f"""Save PyTorch model to {pytorch_dump_path}"""					)
	torch.save(model.state_dict()    ,      lowercase_					)


if __name__ == "__main__":
	A_       : int         =			argparse.ArgumentParser()
	# Required parameters
	parser.add_argument(
	    '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
	)
	parser.add_argument(
	    '--albert_config_file',
	    default=None,
	    type=str,
	    required=True,
	    help=(
	        'The config json file corresponding to the pre-trained ALBERT model. \n'
	        'This specifies the model architecture.'
	    ),
	)
	parser.add_argument(
	    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
	)
	A_       : int         =			parser.parse_args()
	convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)



