





import unittest

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






def 					lowerCamelCase_						(    _UpperCamelCase			)		->						Optional[int]:






				"""simple docstring"""


				return x + 2





class  __lowerCAmelCase	(      unittest.TestCase					):






			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							snake_case_						:   List[str]           =  """x = 3"""
							snake_case_						:   str           =  {}
							snake_case_						:   List[str]           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							assert result == 3
							self.assertDictEqual(lowercase_ ,							{'''x''': 3}   )

							snake_case_						:   Tuple           =  """x = y"""
							snake_case_						:   str           =  {"""y""": 5}
							snake_case_						:   Dict           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							# evaluate returns the value of the last assignment.
							assert result == 5
							self.assertDictEqual(lowercase_ ,							{'''x''': 5, '''y''': 5}   )






			def       lowerCamelCase  (self   )					->       Tuple:


							'''simple docstring'''



							snake_case_						:   List[Any]           =  """y = add_two(x)"""
							snake_case_						:   int           =  {"""x""": 3}
							snake_case_						:   Optional[Any]           =  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:
											snake_case_						:   Optional[Any]           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							assert result is None
							assert "tried to execute add_two" in out.out






			def       lowerCamelCase  (self   )					->       Optional[Any]:


							'''simple docstring'''



							snake_case_						:   Any           =  """x = 3"""
							snake_case_						:   List[Any]           =  {}
							snake_case_						:   Any           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							assert result == 3
							self.assertDictEqual(lowercase_ ,							{'''x''': 3}   )






			def       lowerCamelCase  (self   )					->       Optional[Any]:


							'''simple docstring'''



							snake_case_						:   str           =  """test_dict = {'x': x, 'y': add_two(x)}"""
							snake_case_						:   Optional[int]           =  {"""x""": 3}
							snake_case_						:   str           =  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       lowerCamelCase  (self   )					->       int:


							'''simple docstring'''



							snake_case_						:   Optional[int]           =  """x = 3\ny = 5"""
							snake_case_						:   int           =  {}
							snake_case_						:   List[str]           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							# evaluate returns the value of the last assignment.
							assert result == 5
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''y''': 5}   )






			def       lowerCamelCase  (self   )					->       Union[str, Any]:


							'''simple docstring'''



							snake_case_						:   Optional[int]           =  """text = f'This is x: {x}.'"""
							snake_case_						:   Optional[Any]           =  {"""x""": 3}
							snake_case_						:   Optional[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       lowerCamelCase  (self   )					->       Optional[int]:


							'''simple docstring'''



							snake_case_						:   str           =  """if x <= 3:\n    y = 2\nelse:\n    y = 5"""
							snake_case_						:   List[Any]           =  {"""x""": 3}
							snake_case_						:   Tuple           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							# evaluate returns the value of the last assignment.
							assert result == 2
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''y''': 2}   )

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






			def       lowerCamelCase  (self   )					->       Any:


							'''simple docstring'''



							snake_case_						:   Optional[int]           =  """test_list = [x, add_two(x)]"""
							snake_case_						:   Dict           =  {"""x""": 3}
							snake_case_						:   Any           =  evaluate(lowercase_ ,							{'''add_two''': add_two} ,							state=lowercase_   )
							self.assertListEqual(lowercase_ ,							[3, 5]   )
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''test_list''': [3, 5]}   )






			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							snake_case_						:   str           =  """y = x"""
							snake_case_						:   str           =  {"""x""": 3}
							snake_case_						:   Dict           =  evaluate(lowercase_ ,							{} ,							state=lowercase_   )
							assert result == 3
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''y''': 3}   )






			def       lowerCamelCase  (self   )					->       Optional[int]:


							'''simple docstring'''



							snake_case_						:   Tuple           =  """test_list = [x, add_two(x)]\ntest_list[1]"""
							snake_case_						:   Union[str, Any]           =  {"""x""": 3}
							snake_case_						:   Any           =  evaluate(lowercase_ ,							{'''add_two''': add_two} ,							state=lowercase_   )
							assert result == 5
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''test_list''': [3, 5]}   )

							snake_case_						:   Dict           =  """test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"""
							snake_case_						:   Optional[int]           =  {"""x""": 3}
							snake_case_						:   Any           =  evaluate(lowercase_ ,							{'''add_two''': add_two} ,							state=lowercase_   )
							assert result == 5
							self.assertDictEqual(lowercase_ ,							{'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}   )






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							snake_case_						:   Optional[Any]           =  """x = 0\nfor i in range(3):\n    x = i"""
							snake_case_						:   Optional[int]           =  {}
							snake_case_						:   List[Any]           =  evaluate(lowercase_ ,							{'''range''': range} ,							state=lowercase_   )
							assert result == 2
							self.assertDictEqual(lowercase_ ,							{'''x''': 2, '''i''': 2}   )







import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
	import jax.numpy as jnp

	from transformers.models.albert.modeling_flax_albert import (
	    FlaxAlbertForMaskedLM,
	    FlaxAlbertForMultipleChoice,
	    FlaxAlbertForPreTraining,
	    FlaxAlbertForQuestionAnswering,
	    FlaxAlbertForSequenceClassification,
	    FlaxAlbertForTokenClassification,
	    FlaxAlbertModel,
	)



class  __lowerCAmelCase	(      unittest.TestCase					):






			def __init__(self ,							__magic_name__ ,							__magic_name__=13 ,							__magic_name__=7 ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=99 ,							__magic_name__=32 ,							__magic_name__=5 ,							__magic_name__=4 ,							__magic_name__=37 ,							__magic_name__="gelu" ,							__magic_name__=0.1 ,							__magic_name__=0.1 ,							__magic_name__=512 ,							__magic_name__=16 ,							__magic_name__=2 ,							__magic_name__=0.02 ,							__magic_name__=4 ,							)					->       Tuple:


							'''simple docstring'''



							snake_case_						:   Union[str, Any]           =  parent
							snake_case_						:   Optional[Any]           =  batch_size
							snake_case_						:   List[Any]           =  seq_length
							snake_case_						:   Tuple           =  is_training
							snake_case_						:   List[str]           =  use_attention_mask
							snake_case_						:   Any           =  use_token_type_ids
							snake_case_						:   Dict           =  use_labels
							snake_case_						:   Optional[Any]           =  vocab_size
							snake_case_						:   Dict           =  hidden_size
							snake_case_						:   List[Any]           =  num_hidden_layers
							snake_case_						:   Union[str, Any]           =  num_attention_heads
							snake_case_						:   Any           =  intermediate_size
							snake_case_						:   Optional[int]           =  hidden_act
							snake_case_						:   Optional[int]           =  hidden_dropout_prob
							snake_case_						:   Optional[Any]           =  attention_probs_dropout_prob
							snake_case_						:   Optional[int]           =  max_position_embeddings
							snake_case_						:   Optional[int]           =  type_vocab_size
							snake_case_						:   List[Any]           =  type_sequence_label_size
							snake_case_						:   Dict           =  initializer_range
							snake_case_						:   Dict           =  num_choices






			def       lowerCamelCase  (self   )					->       Tuple:


							'''simple docstring'''



							snake_case_						:   int           =  ids_tensor([self.batch_size, self.seq_length] ,							self.vocab_size   )

							snake_case_						:   Any           =  None
							if self.use_attention_mask:
											snake_case_						:   List[Any]           =  random_attention_mask([self.batch_size, self.seq_length]   )

							snake_case_						:   List[Any]           =  None
							if self.use_token_type_ids:
											snake_case_						:   Dict           =  ids_tensor([self.batch_size, self.seq_length] ,							self.type_vocab_size   )

							snake_case_						:   List[Any]           =  AlbertConfig(
							    vocab_size=self.vocab_size ,							hidden_size=self.hidden_size ,							num_hidden_layers=self.num_hidden_layers ,							num_attention_heads=self.num_attention_heads ,							intermediate_size=self.intermediate_size ,							hidden_act=self.hidden_act ,							hidden_dropout_prob=self.hidden_dropout_prob ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob ,							max_position_embeddings=self.max_position_embeddings ,							type_vocab_size=self.type_vocab_size ,							is_decoder=__magic_name__ ,							initializer_range=self.initializer_range ,							)

							return config, input_ids, token_type_ids, attention_mask






			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							snake_case_						:   Tuple           =  self.prepare_config_and_inputs()
							snake_case_      ,							snake_case_      ,							snake_case_      ,							snake_case_						:   Optional[int]           =  config_and_inputs
							snake_case_						:   int           =  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
							return config, inputs_dict




@require_flax
class  __lowerCAmelCase	(      _a,					unittest.TestCase					):
			lowerCamelCase_					:					Optional[int]	      =				(
			    (
			        FlaxAlbertModel,
			        FlaxAlbertForPreTraining,
			        FlaxAlbertForMaskedLM,
			        FlaxAlbertForMultipleChoice,
			        FlaxAlbertForQuestionAnswering,
			        FlaxAlbertForSequenceClassification,
			        FlaxAlbertForTokenClassification,
			        FlaxAlbertForQuestionAnswering,
			    )
			    if is_flax_available()
			    else ()
			)






			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							snake_case_						:   Optional[Any]           =  FlaxAlbertModelTester(self   )






			@slow
			def       lowerCamelCase  (self   )					->       Tuple:


							'''simple docstring'''



							for model_class_name in self.all_model_classes:
											snake_case_						:   Dict           =  model_class_name.from_pretrained('''albert-base-v2'''   )
											snake_case_						:   Union[str, Any]           =  model(np.ones((1, 1)   )   )
											self.assertIsNotNone(__magic_name__   )




@require_flax
class  __lowerCAmelCase	(      unittest.TestCase					):






			@slow
			def       lowerCamelCase  (self   )					->       Optional[Any]:


							'''simple docstring'''



							snake_case_						:   Optional[Any]           =  FlaxAlbertModel.from_pretrained('''albert-base-v2'''   )
							snake_case_						:   Optional[int]           =  np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]   )
							snake_case_						:   Dict           =  np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
							snake_case_						:   Union[str, Any]           =  model(__magic_name__ ,							attention_mask=__magic_name__   )[0]
							snake_case_						:   Tuple           =  (1, 11, 768)
							self.assertEqual(output.shape ,							__magic_name__   )
							snake_case_						:   str           =  np.array(
							    [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]   )

							self.assertTrue(jnp.allclose(output[:, 1:4, 1:4] ,							__magic_name__ ,							atol=1e-4   )   )
