





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






				def        snake_case			(				self	:					str,				lowerCAmelCase__	:					bool = False							)			->   List[Any]:




										'''simple docstring'''



										_UpperCamelCase    :      Dict						     =					1_0

										if only_cross_attention:
																_UpperCamelCase    :      Optional[Any]						     =					1_2
										else:
																# when only cross attention is not set, the cross attention dim must be the same as the query dim
																_UpperCamelCase    :      Union[str, Any]						     =					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        snake_case			(				self	:					str,				lowerCAmelCase__	:					int,				lowerCAmelCase__	:					Tuple							)			->   Dict:




										'''simple docstring'''



										_UpperCamelCase    :      Optional[Any]						     =					2

										_UpperCamelCase    :      str						     =					torch.rand(lowerCAmelCase__,				lowerCAmelCase__,				3,				2							)
										_UpperCamelCase    :      Dict						     =					torch.rand(lowerCAmelCase__,				4,				lowerCAmelCase__							)
										_UpperCamelCase    :      Optional[Any]						     =					None

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






				def        snake_case			(				self	:					str							)			->   int:




										'''simple docstring'''



										torch.manual_seed(0							)

										_UpperCamelCase    :      str						     =					self.get_constructor_arguments(only_cross_attention=lowerCAmelCase__							)
										_UpperCamelCase    :      Tuple						     =					Attention(**lowerCAmelCase__							)

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

										_UpperCamelCase    :      Optional[int]						     =					self.get_forward_arguments(
										    query_dim=constructor_args['''query_dim'''],				added_kv_proj_dim=constructor_args['''added_kv_proj_dim''']							)

										_UpperCamelCase    :      Tuple						     =					attn(**lowerCAmelCase__							)

										# only self attention

										torch.manual_seed(0							)

										_UpperCamelCase    :      Optional[int]						     =					self.get_constructor_arguments(only_cross_attention=lowerCAmelCase__							)
										_UpperCamelCase    :      List[Any]						     =					Attention(**lowerCAmelCase__							)

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

										_UpperCamelCase    :      Optional[int]						     =					self.get_forward_arguments(
										    query_dim=constructor_args['''query_dim'''],				added_kv_proj_dim=constructor_args['''added_kv_proj_dim''']							)

										_UpperCamelCase    :      str						     =					attn(**lowerCAmelCase__							)

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




class 				_a		(   unittest.TestCase       ):






				def        snake_case			(				self	:					int							)			->   List[Any]:




										'''simple docstring'''



										_UpperCamelCase    :      Optional[Any]						     =					DiffusionPipeline.from_pretrained('''hf-internal-testing/tiny-stable-diffusion-pipe''',				safety_checker=lowerCAmelCase__							)

										_UpperCamelCase    :      Dict						     =					pipe(
										    '''foo''',				num_inference_steps=2,				generator=torch.Generator('''cpu'''							).manual_seed(0							),				output_type='''np''',				).images

										# the initial conversion succeeds
										_UpperCamelCase    :      Optional[int]						     =					DiffusionPipeline.from_pretrained(
										    '''hf-internal-testing/tiny-stable-diffusion-pipe''',				device_map='''sequential''',				safety_checker=lowerCAmelCase__							)

										_UpperCamelCase    :      Optional[Any]						     =					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
																_UpperCamelCase    :      str						     =					DiffusionPipeline.from_pretrained(lowerCAmelCase__,				device_map='''sequential''',				safety_checker=lowerCAmelCase__							)

										_UpperCamelCase    :      List[str]						     =					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  a_       (							_lowercase ,		_lowercase     ):
						sequence.append(_lowercase     )

						_UpperCamelCase    :      int						     =					0
						while sequence[index] != target:
												index += 1

						sequence.pop()

						if index == len(_lowercase     ):
												return None

						return index


if __name__ == "__main__":
						UpperCamelCase_     =input("""Enter numbers separated by comma:\n""").strip()
						UpperCamelCase_     =[int(item) for item in user_input.split(""",""")]

						UpperCamelCase_     =input("""Enter a single number to be found in the list:\n""")
						UpperCamelCase_     =int(target_input)
						UpperCamelCase_     =sentinel_linear_search(sequence, target)
						if result is not None:
												print(F"{target} found at positions: {result}")
						else:
												print("""Not found""")



