


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 lowerCAmelCase_						(			__SCREAMING_SNAKE_CASE ,						__SCREAMING_SNAKE_CASE ,						unittest.TestCase	):

 '''simple docstring'''

 __snake_case												=  VQModel
 __snake_case												=  'sample'



 @property
 def 						UpperCamelCase__					(     self		,				_UpperCAmelCase=(32, 32) ):
       snake_case_	=				4
       snake_case_	=				3

       snake_case_	=				floats_tensor((batch_size, num_channels) + sizes ).to(_a )

       return {"sample": image}



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



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



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



 def 						UpperCamelCase__					(     self ):
       pass



 def 						UpperCamelCase__					(     self ):
       pass



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

       model.to(_a )
       snake_case_	=				model(**self.dummy_input )

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





 def 						UpperCamelCase__					(     self ):
       snake_case_	=				VQModel.from_pretrained('''fusing/vqgan-dummy''' )
       model.to(_a ).eval()

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

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

       snake_case_	=				output[0, -1, -3:, -3:].flatten().cpu()
       # fmt: off
       snake_case_	=				torch.tensor([-0.0_153, -0.4_044, -0.1_880, -0.5_161, -0.2_418, -0.4_072, -0.1_612, -0.0_633, -0.0_143] )
       # fmt: on
       self.assertTrue(torch.allclose(_a		,				_a		,				atol=1E-3 ) )



def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE )->  int:




      """simple docstring"""

      if not isinstance(SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE ):
            snake_case_	=				f'''Input value of [number={number}] must be an integer'''
            raise TypeError(SCREAMING_SNAKE_CASE )

      if number < 1:
            snake_case_	=				f'''Input value of [number={number}] must be > 0'''
            raise ValueError(SCREAMING_SNAKE_CASE )

      snake_case_	=				1

      for i in range(1 , SCREAMING_SNAKE_CASE ):
            current_number *= 4 * i - 2
            current_number //= i + 1

      return current_number


if __name__ == "__main__":
   import doctest

   doctest.testmod()