'''simple docstring'''




import tempfile
import unittest

import numpy as np
import torch

from diffusers import DiffusionPipeline
from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor





class        __magic_name__		(       unittest.TestCase):







			def       SCREAMING_SNAKE_CASE_	(      self							:    Tuple							,     lowercase_							:    List[Any] = False       ):
										lowercase_   :     Optional[Any]									=			10

										if only_cross_attention:
																	lowercase_   :     str									=			12
										else:
																	# when only cross attention is not set, the cross attention dim must be the same as the query dim
																	lowercase_   :     Optional[int]									=			query_dim

										return {
										    "query_dim": query_dim,
										    "cross_attention_dim": cross_attention_dim,
										    "heads": 2,
										    "dim_head": 4,
										    "added_kv_proj_dim": 6,
										    "norm_num_groups": 1,
										    "only_cross_attention": only_cross_attention,
										    "processor": AttnAddedKVProcessor(),
										}







			def       SCREAMING_SNAKE_CASE_	(      self							:    Union[str, Any]							,     lowercase_							:    Tuple							,     lowercase_							:    Dict       ):
										lowercase_   :     List[Any]									=			2

										lowercase_   :     Any									=			torch.rand(lowercase_							,     lowercase_							,     3							,     2       )
										lowercase_   :     str									=			torch.rand(lowercase_							,     4							,     lowercase_       )
										lowercase_   :     List[str]									=			None

										return {
										    "hidden_states": hidden_states,
										    "encoder_hidden_states": encoder_hidden_states,
										    "attention_mask": attention_mask,
										}







			def       SCREAMING_SNAKE_CASE_	(      self							:    List[str]       ):
										# self and cross attention

										torch.manual_seed(0       )

										lowercase_   :     Tuple									=			self.get_constructor_arguments(only_cross_attention=lowercase_       )
										lowercase_   :     int									=			Attention(**lowercase_       )

										self.assertTrue(attn.to_k is not None       )
										self.assertTrue(attn.to_v is not None       )

										lowercase_   :     Union[str, Any]									=			self.get_forward_arguments(
										    query_dim=constructor_args["""query_dim"""]							,     added_kv_proj_dim=constructor_args["""added_kv_proj_dim"""]       )

										lowercase_   :     Tuple									=			attn(**lowercase_       )

										# only self attention

										torch.manual_seed(0       )

										lowercase_   :     int									=			self.get_constructor_arguments(only_cross_attention=lowercase_       )
										lowercase_   :     Union[str, Any]									=			Attention(**lowercase_       )

										self.assertTrue(attn.to_k is None       )
										self.assertTrue(attn.to_v is None       )

										lowercase_   :     Dict									=			self.get_forward_arguments(
										    query_dim=constructor_args["""query_dim"""]							,     added_kv_proj_dim=constructor_args["""added_kv_proj_dim"""]       )

										lowercase_   :     Optional[Any]									=			attn(**lowercase_       )

										self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()       )





class        __magic_name__		(       unittest.TestCase):







			def       SCREAMING_SNAKE_CASE_	(      self							:    Union[str, Any]       ):
										lowercase_   :     Any									=			DiffusionPipeline.from_pretrained("""hf-internal-testing/tiny-stable-diffusion-pipe"""							,     safety_checker=lowercase_       )

										lowercase_   :     Any									=			pipe(
										    """foo"""							,     num_inference_steps=2							,     generator=torch.Generator("""cpu"""       ).manual_seed(0       )							,     output_type="""np"""							,     ).images

										# the initial conversion succeeds
										lowercase_   :     Dict									=			DiffusionPipeline.from_pretrained(
										    """hf-internal-testing/tiny-stable-diffusion-pipe"""							,     device_map="""sequential"""							,     safety_checker=lowercase_       )

										lowercase_   :     str									=			pipe(
										    """foo"""							,     num_inference_steps=2							,     generator=torch.Generator("""cpu"""       ).manual_seed(0       )							,     output_type="""np"""							,     ).images

										with tempfile.TemporaryDirectory() as tmpdir:
																	# save the converted model
																	pipe.save_pretrained(lowercase_       )

																	# can also load the converted weights
																	lowercase_   :     Union[str, Any]									=			DiffusionPipeline.from_pretrained(lowercase_							,     device_map="""sequential"""							,     safety_checker=lowercase_       )

										lowercase_   :     Union[str, Any]									=			pipe(
										    """foo"""							,     num_inference_steps=2							,     generator=torch.Generator("""cpu"""       ).manual_seed(0       )							,     output_type="""np"""							,     ).images

										self.assertTrue(np.allclose(lowercase_							,     lowercase_							,     atol=1E-5       )       )
										self.assertTrue(np.allclose(lowercase_							,     lowercase_							,     atol=1E-5       )       )









import math
def 							UpperCAmelCase_   (				__snake_case		)	->     int:







 """simple docstring"""


 return sum(int(__snake_case		) for digit in str(__snake_case		)		)
def 							UpperCAmelCase_   (				__snake_case = 30		)	->     int:







 """simple docstring"""


 _lowercase				 =[]
 for digit in range(2	,		100		):
  for power in range(2	,		100		):
   _lowercase				 =int(math.pow(__snake_case	,		__snake_case		)		)
   if digit == digit_sum(__snake_case		):
    digit_to_powers.append(__snake_case		)

 digit_to_powers.sort()
 return digit_to_powers[n - 1]


if __name__ == "__main__":
  print(solution())

