




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




    """simple docstring"""

    snake_case__   = VQModel
    snake_case__   = "sample"


    @property
    def   a (			self	:	List[Any]  ,      SCREAMING_SNAKE_CASE__	:	Any=(32, 32)  ) ->			List[Any]:
         lowerCAmelCase__            =					4
         lowerCAmelCase__            =					3

         lowerCAmelCase__            =					floats_tensor((batch_size, num_channels) + sizes  ).to(SCREAMING_SNAKE_CASE__  )

         return {"sample": image}


    @property
    def   a (			self	:	Tuple  ) ->			Dict:
         return (3, 32, 32)


    @property
    def   a (			self	:	Optional[Any]  ) ->			List[Any]:
         return (3, 32, 32)


    def   a (			self	:	Dict  ) ->			Union[str, Any]:
         lowerCAmelCase__            =					{
             "block_out_channels": [32, 64],
             "in_channels": 3,
             "out_channels": 3,
             "down_block_types": ["DownEncoderBlock2D", "DownEncoderBlock2D"],
             "up_block_types": ["UpDecoderBlock2D", "UpDecoderBlock2D"],
             "latent_channels": 3,
         }
         lowerCAmelCase__            =					self.dummy_input
         return init_dict, inputs_dict


    def   a (			self	:	Union[str, Any]  ) ->			List[str]:
         pass


    def   a (			self	:	List[Any]  ) ->			Dict:
         pass


    def   a (			self	:	Union[str, Any]  ) ->			int:
         lowerCAmelCase__      ,						lowerCAmelCase__            =					VQModel.from_pretrained("fusing/vqgan-dummy"  ,      output_loading_info=SCREAMING_SNAKE_CASE__  )
         self.assertIsNotNone(SCREAMING_SNAKE_CASE__  )
         self.assertEqual(len(loading_info["missing_keys"]  )  ,      0  )

         model.to(SCREAMING_SNAKE_CASE__  )
         lowerCAmelCase__            =					model(**self.dummy_input  )

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


    def   a (			self	:	List[Any]  ) ->			str:
         lowerCAmelCase__            =					VQModel.from_pretrained("fusing/vqgan-dummy"  )
         model.to(SCREAMING_SNAKE_CASE__  ).eval()

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

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

         lowerCAmelCase__            =					output[0, -1, -3:, -3:].flatten().cpu()
         # fmt: off
         lowerCAmelCase__            =					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(SCREAMING_SNAKE_CASE__  ,      SCREAMING_SNAKE_CASE__  ,      atol=1e-3  )  )




"""simple docstring"""

def lowerCAmelCase_   (					UpperCamelCase__						:			int			):






 """simple docstring"""







 assert (
     isinstance(UpperCamelCase__					, UpperCamelCase__			) and number_of_steps > 0
 ), f'''number_of_steps needs to be positive integer, your input {number_of_steps}'''
 if number_of_steps == 1:
  return 1
 __lowercase				,		__lowercase						=						1, 1
 for _ in range(number_of_steps - 1			):
  __lowercase				,		__lowercase						=						current + previous, current
 return current


if __name__ == "__main__":
       import doctest

       doctest.testmod()
