

import gc
import inspect
import unittest

import torch
from parameterized import parameterized

from diffusers import PriorTransformer
from diffusers.utils import floats_tensor, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin


enable_full_determinism()







class 						__magic_name__			(							lowerCamelCase__		,       unittest.TestCase							):

   '''simple docstring'''




   lowerCamelCase__ :	Any    =   PriorTransformer
   lowerCamelCase__ :	Optional[int]    =   'hidden_states'



   @property
   def  _UpperCAmelCase (				self       )							->    List[Any]:






     """simple docstring"""






     a__  =4
     a__  =8
     a__  =7

     a__  =floats_tensor((batch_size, embedding_dim)       ).to(lowercase_       )

     a__  =floats_tensor((batch_size, embedding_dim)       ).to(lowercase_       )
     a__  =floats_tensor((batch_size, num_embeddings, embedding_dim)       ).to(lowercase_       )

     return {
         "hidden_states": hidden_states,
         "timestep": 2,
         "proj_embedding": proj_embedding,
         "encoder_hidden_states": encoder_hidden_states,
     }



   def  _UpperCAmelCase (				self,    lowercase_=0       )							->    int:






     """simple docstring"""






     torch.manual_seed(lowercase_       )
     a__  =4
     a__  =8
     a__  =7

     a__  =torch.randn((batch_size, embedding_dim)       ).to(lowercase_       )

     a__  =torch.randn((batch_size, embedding_dim)       ).to(lowercase_       )
     a__  =torch.randn((batch_size, num_embeddings, embedding_dim)       ).to(lowercase_       )

     return {
         "hidden_states": hidden_states,
         "timestep": 2,
         "proj_embedding": proj_embedding,
         "encoder_hidden_states": encoder_hidden_states,
     }



   @property
   def  _UpperCAmelCase (				self       )							->    Dict:






     """simple docstring"""






     return (4, 8)



   @property
   def  _UpperCAmelCase (				self       )							->    List[str]:






     """simple docstring"""






     return (4, 8)



   def  _UpperCAmelCase (				self       )							->    Any:






     """simple docstring"""






     a__  ={
         '''num_attention_heads''': 2,
         '''attention_head_dim''': 4,
         '''num_layers''': 2,
         '''embedding_dim''': 8,
         '''num_embeddings''': 7,
         '''additional_embeddings''': 4,
     }
     a__  =self.dummy_input
     return init_dict, inputs_dict



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






     """simple docstring"""






     a__,      a__  =PriorTransformer.from_pretrained(
         '''hf-internal-testing/prior-dummy''',    output_loading_info=lowercase_       )
     self.assertIsNotNone(lowercase_       )
     self.assertEqual(len(loading_info['''missing_keys''']       ),    0       )

     model.to(lowercase_       )
     a__  =model(**self.dummy_input       )[0]

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



   def  _UpperCAmelCase (				self       )							->    str:






     """simple docstring"""






     a__,      a__  =self.prepare_init_args_and_inputs_for_common()

     a__  =self.model_class(**lowercase_       )
     a__  =inspect.signature(model.forward       )
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     a__  =[*signature.parameters.keys()]

     a__  =['''hidden_states''', '''timestep''']
     self.assertListEqual(arg_names[:2],    lowercase_       )



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






     """simple docstring"""






     a__  =PriorTransformer.from_pretrained('''hf-internal-testing/prior-dummy'''       )
     a__  =model.to(lowercase_       )

     if hasattr(lowercase_,    '''set_default_attn_processor'''       ):
       model.set_default_attn_processor()

     a__  =self.get_dummy_seed_input()

     with torch.no_grad():
       a__  =model(**lowercase_       )[0]

     a__  =output[0, :5].flatten().cpu()
     print(lowercase_       )

     # Since the VAE Gaussian prior's generator is seeded on the appropriate device,
     # the expected output slices are not the same for CPU and GPU.
     a__  =torch.tensor([-1.3436, -0.2870, 0.7538, 0.4368, -0.0239]       )
     self.assertTrue(torch_all_close(lowercase_,    lowercase_,    rtol=1E-2       )       )







@slow
class 						__magic_name__			(							unittest.TestCase							):

   '''simple docstring'''




   def  _UpperCAmelCase (				self,    lowercase_=1,    lowercase_=768,    lowercase_=77,    lowercase_=0       )							->    int:






     """simple docstring"""






     torch.manual_seed(lowercase_       )
     a__  =batch_size
     a__  =embedding_dim
     a__  =num_embeddings

     a__  =torch.randn((batch_size, embedding_dim)       ).to(lowercase_       )

     a__  =torch.randn((batch_size, embedding_dim)       ).to(lowercase_       )
     a__  =torch.randn((batch_size, num_embeddings, embedding_dim)       ).to(lowercase_       )

     return {
         "hidden_states": hidden_states,
         "timestep": 2,
         "proj_embedding": proj_embedding,
         "encoder_hidden_states": encoder_hidden_states,
     }



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






     """simple docstring"""






     super().tearDown()
     gc.collect()
     torch.cuda.empty_cache()



   @parameterized.expand(
       [
           # fmt: off
           [13, [-0.5861,  0.1283, -0.0931,  0.0882,  0.4476,  0.1329, -0.0498,  0.0640]],
           [37, [-0.4913,  0.0110, -0.0483,  0.0541,  0.4954, -0.0170,  0.0354,  0.1651]],
           # fmt: on
       ]       )
   def  _UpperCAmelCase (				self,    lowercase_,    lowercase_       )							->    Any:






     """simple docstring"""






     a__  =PriorTransformer.from_pretrained('''kandinsky-community/kandinsky-2-1-prior''',    subfolder='''prior'''       )
     model.to(lowercase_       )
     a__  =self.get_dummy_seed_input(seed=lowercase_       )

     with torch.no_grad():
       a__  =model(**lowercase_       )[0]

     assert list(sample.shape       ) == [1, 768]

     a__  =sample[0, :8].flatten().cpu()
     print(lowercase_       )
     a__  =torch.tensor(lowercase_       )

     assert torch_all_close(lowercase_,    lowercase_,    atol=1E-3       )



from math import factorial




def 			UpperCAmelCase__				(			_A      : int = 1_00							):





  '''simple docstring'''







  return sum(int(_A							) for x in str(factorial(_A							)							)							)


if __name__ == "__main__":
       print(solution(int(input('''Enter the Number: ''').strip())))
