


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



    """simple docstring"""






    UpperCAmelCase__						:		str              =  VQModel
    UpperCAmelCase__						:		Tuple              =  "sample"






    @property
    def _a (      self ,       A_=(32, 32)   )  ->	Union[str, Any]:
         __UpperCamelCase   							=4
         __UpperCamelCase   							=3

         __UpperCamelCase   							=floats_tensor((batch_size, num_channels) + sizes   ).to(A_   )

         return {"sample": image}






    @property
    def _a (      self   )  ->	List[str]:
         return (3, 32, 32)






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






    def _a (      self   )  ->	str:
         __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 _a (      self   )  ->	List[Any]:
         pass






    def _a (      self   )  ->	int:
         pass






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

         model.to(A_   )
         __UpperCamelCase   							=model(**self.dummy_input   )

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






    def _a (      self   )  ->	Union[str, Any]:
         __UpperCamelCase   							=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   )

         __UpperCamelCase   							=torch.randn(1 ,       model.config.in_channels ,       model.config.sample_size ,       model.config.sample_size   )
         __UpperCamelCase   							=image.to(A_   )
         with torch.no_grad():
              __UpperCamelCase   							=model(A_   ).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(A_ ,       A_ ,       atol=1E-3   )   )









import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812

def 						_UpperCAmelCase    (      ):
     print('Making key files...'    )
     make_key_files('rsa'      ,					10_24    )
     print('Key files generation successful.'    )

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int    ):
     print('Generating prime p...'    )
     __UpperCamelCase   							=rabinMiller.generate_large_prime(SCREAMING_SNAKE_CASE__    )
     print('Generating prime q...'    )
     __UpperCamelCase   							=rabinMiller.generate_large_prime(SCREAMING_SNAKE_CASE__    )
     __UpperCamelCase   							=p * q

     print('Generating e that is relatively prime to (p - 1) * (q - 1)...'    )
     while True:
          __UpperCamelCase   							=random.randrange(2 ** (key_size - 1)      ,					2 ** (key_size)    )
          if cryptoMath.gcd(SCREAMING_SNAKE_CASE__      ,					(p - 1) * (q - 1)    ) == 1:
               break

     print('Calculating d that is mod inverse of e...'    )
     __UpperCamelCase   							=cryptoMath.find_mod_inverse(SCREAMING_SNAKE_CASE__      ,					(p - 1) * (q - 1)    )

     __UpperCamelCase   							=(n, e)
     __UpperCamelCase   							=(n, d)
     return (public_key, private_key)

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : str      ,					SCREAMING_SNAKE_CASE__      : int    ):
     if os.path.exists(F'{name}_pubkey.txt'    ) or os.path.exists(F'{name}_privkey.txt'    ):
          print('\nWARNING:'    )
          print(
              F'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
              'Use a different name or delete these files and re-run this program.'    )
          sys.exit()

     __UpperCamelCase							,				__UpperCamelCase   							=generate_key(SCREAMING_SNAKE_CASE__    )
     print(F'\nWriting public key to file {name}_pubkey.txt...'    )
     with open(F'{name}_pubkey.txt'      ,					'w'    ) as out_file:
          out_file.write(F'{key_size},{public_key[0]},{public_key[1]}'    )

     print(F'Writing private key to file {name}_privkey.txt...'    )
     with open(F'{name}_privkey.txt'      ,					'w'    ) as out_file:
          out_file.write(F'{key_size},{private_key[0]},{private_key[1]}'    )


if __name__ == "__main__":
   main()





