


"""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 snake_case   (	unittest.TestCase):







		def 			a_			(       self   :							List[Any]     , a__   :							bool = False		)							->    Any:





						'''simple docstring'''







						_A       	=      10

						if only_cross_attention:
										_A       	=      12
						else:
										# when only cross attention is not set, the cross attention dim must be the same as the query dim
										_A       	=      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 			a_			(       self   :							Dict     , a__   :							List[str]     , a__   :							Union[str, Any]		)							->    Optional[int]:





						'''simple docstring'''







						_A       	=      2

						_A       	=      torch.rand(_lowerCamelCase     , _lowerCamelCase     , 3     , 2		)
						_A       	=      torch.rand(_lowerCamelCase     , 4     , _lowerCamelCase		)
						_A       	=      None

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







		def 			a_			(       self   :							str		)							->    Tuple:





						'''simple docstring'''







						torch.manual_seed(0		)

						_A       	=      self.get_constructor_arguments(only_cross_attention=_lowerCamelCase		)
						_A       	=      Attention(**_lowerCamelCase		)

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

						_A       	=      self.get_forward_arguments(
						    query_dim=constructor_args["query_dim"]     , added_kv_proj_dim=constructor_args["added_kv_proj_dim"]		)

						_A       	=      attn(**_lowerCamelCase		)

						# only self attention

						torch.manual_seed(0		)

						_A       	=      self.get_constructor_arguments(only_cross_attention=_lowerCamelCase		)
						_A       	=      Attention(**_lowerCamelCase		)

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

						_A       	=      self.get_forward_arguments(
						    query_dim=constructor_args["query_dim"]     , added_kv_proj_dim=constructor_args["added_kv_proj_dim"]		)

						_A       	=      attn(**_lowerCamelCase		)

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





class snake_case   (	unittest.TestCase):







		def 			a_			(       self   :							Optional[int]		)							->    Optional[Any]:





						'''simple docstring'''







						_A       	=      DiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-pipe"     , safety_checker=_lowerCamelCase		)

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

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

						_A       	=      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(_lowerCamelCase		)

										# can also load the converted weights
										_A       	=      DiffusionPipeline.from_pretrained(_lowerCamelCase     , device_map="sequential"     , safety_checker=_lowerCamelCase		)

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

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





"""simple docstring"""

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	return a + b


if __name__ == "__main__":
		_lowerCamelCase	:      Tuple   =							5
		_lowerCamelCase	:      Union[str, Any]   =							6
		print(f'The sum of {a} + {b} is {add(a, b)}')





