





'''simple docstring'''

import unittest

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

def     __magic_name__							(				__UpperCAmelCase   )    ->       str:

   '''simple docstring'''







   return x + 2







class __a			( unittest.TestCase      ):





   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""x = 3"""
      __SCREAMING_SNAKE_CASE   				=							{}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{}					,state=lowerCamelCase     )
      assert result == 3
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3}     )

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





   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""y = add_two(x)"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{"""add_two""": add_two}					,state=lowerCamelCase     )
      assert result == 5
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """y""": 5}     )

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





   def   UpperCAmelCase__  (       self					:      Any     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""x = 3"""
      __SCREAMING_SNAKE_CASE   				=							{}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{}					,state=lowerCamelCase     )
      assert result == 3
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3}     )





   def   UpperCAmelCase__  (       self					:      Union[str, Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""test_dict = {'x': x, 'y': add_two(x)}"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{"""add_two""": add_two}					,state=lowerCamelCase     )
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """y""": 5}     )
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}     )





   def   UpperCAmelCase__  (       self					:      Dict     ):

      '''simple docstring'''

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





   def   UpperCAmelCase__  (       self					:      int     ):

      '''simple docstring'''

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





   def   UpperCAmelCase__  (       self					:      Union[str, Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""if x <= 3:\n    y = 2\nelse:\n    y = 5"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{}					,state=lowerCamelCase     )
      # evaluate returns the value of the last assignment.
      assert result == 2
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """y""": 2}     )

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





   def   UpperCAmelCase__  (       self					:      Dict     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""test_list = [x, add_two(x)]"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{"""add_two""": add_two}					,state=lowerCamelCase     )
      self.assertListEqual(lowerCamelCase					,[3, 5]     )
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """test_list""": [3, 5]}     )





   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""y = x"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{}					,state=lowerCamelCase     )
      assert result == 3
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """y""": 3}     )





   def   UpperCAmelCase__  (       self					:      Tuple     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""test_list = [x, add_two(x)]\ntest_list[1]"""
      __SCREAMING_SNAKE_CASE   				=							{"""x""": 3}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{"""add_two""": add_two}					,state=lowerCamelCase     )
      assert result == 5
      self.assertDictEqual(lowerCamelCase					,{"""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(lowerCamelCase					,{"""add_two""": add_two}					,state=lowerCamelCase     )
      assert result == 5
      self.assertDictEqual(lowerCamelCase					,{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}     )





   def   UpperCAmelCase__  (       self					:      Optional[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							"""x = 0\nfor i in range(3):\n    x = i"""
      __SCREAMING_SNAKE_CASE   				=							{}
      __SCREAMING_SNAKE_CASE   				=							evaluate(lowerCamelCase					,{"""range""": range}					,state=lowerCamelCase     )
      assert result == 2
      self.assertDictEqual(lowerCamelCase					,{"""x""": 2, """i""": 2}     )












import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()

class 							__SCREAMING_SNAKE_CASE       (  _a ,		_a ,		unittest.TestCase							):
							snake_case  :   List[str]      =							VQModel
							snake_case  :   Dict      =							"""sample"""






							@property
							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase=(32, 32)	):
														UpperCamelCase__					  =      4
														UpperCamelCase__					  =      3

														UpperCamelCase__					  =      floats_tensor((batch_size, num_channels) + sizes	).to(__lowerCAmelCase	)

														return {"sample": image}






							@property
							def 					_lowerCamelCase		(    self	):
														return (3, 32, 32)






							@property
							def 					_lowerCamelCase		(    self	):
														return (3, 32, 32)






							def 					_lowerCamelCase		(    self	):
														UpperCamelCase__					  =      {
														    """block_out_channels""": [32, 64],
														    """in_channels""": 3,
														    """out_channels""": 3,
														    """down_block_types""": ["""DownEncoderBlock2D""", """DownEncoderBlock2D"""],
														    """up_block_types""": ["""UpDecoderBlock2D""", """UpDecoderBlock2D"""],
														    """latent_channels""": 3,
														}
														UpperCamelCase__					  =      self.dummy_input
														return init_dict, inputs_dict






							def 					_lowerCamelCase		(    self	):
														pass






							def 					_lowerCamelCase		(    self	):
														pass






							def 					_lowerCamelCase		(    self	):
														UpperCamelCase__  ,  UpperCamelCase__					  =      VQModel.from_pretrained("""fusing/vqgan-dummy"""	,			output_loading_info=__lowerCAmelCase	)
														self.assertIsNotNone(__lowerCAmelCase	)
														self.assertEqual(len(loading_info["""missing_keys"""]	)	,			0	)

														model.to(__lowerCAmelCase	)
														UpperCamelCase__					  =      model(**self.dummy_input	)

														assert image is not None, "Make sure output is not None"







							def 					_lowerCamelCase		(    self	):
														UpperCamelCase__					  =      VQModel.from_pretrained("""fusing/vqgan-dummy"""	)
														model.to(__lowerCAmelCase	).eval()

														torch.manual_seed(0	)
														if torch.cuda.is_available():
																					torch.cuda.manual_seed_all(0	)

														UpperCamelCase__					  =      torch.randn(1	,			model.config.in_channels	,			model.config.sample_size	,			model.config.sample_size	)
														UpperCamelCase__					  =      image.to(__lowerCAmelCase	)
														with torch.no_grad():
																					UpperCamelCase__					  =      model(__lowerCAmelCase	).sample

														UpperCamelCase__					  =      output[0, -1, -3:, -3:].flatten().cpu()
														# fmt: off
														UpperCamelCase__					  =      torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]	)
														# fmt: on
														self.assertTrue(torch.allclose(__lowerCAmelCase	,			__lowerCAmelCase	,			atol=1E-3	)	)




