





'''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      _snake_case      (		self			,					UpperCamelCase_ = False		)			->		Optional[int]:
		snake_case__  					=      10

		if only_cross_attention:
			snake_case__  					=      12
		else:
			# when only cross attention is not set, the cross attention dim must be the same as the query dim
			snake_case__  					=      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			,					UpperCamelCase_			,					UpperCamelCase_		)			->		Union[str, Any]:
		snake_case__  					=      2

		snake_case__  					=      torch.rand(UpperCamelCase_			,					UpperCamelCase_			,					3			,					2		)
		snake_case__  					=      torch.rand(UpperCamelCase_			,					4			,					UpperCamelCase_		)
		snake_case__  					=      None

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





	def      _snake_case      (		self		)			->		List[Any]:
		# self and cross attention

		torch.manual_seed(0		)

		snake_case__  					=      self.get_constructor_arguments(only_cross_attention=UpperCamelCase_		)
		snake_case__  					=      Attention(**UpperCamelCase_		)

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

		snake_case__  					=      self.get_forward_arguments(
		    query_dim=constructor_args['query_dim']			,					added_kv_proj_dim=constructor_args['added_kv_proj_dim']		)

		snake_case__  					=      attn(**UpperCamelCase_		)

		# only self attention

		torch.manual_seed(0		)

		snake_case__  					=      self.get_constructor_arguments(only_cross_attention=UpperCamelCase_		)
		snake_case__  					=      Attention(**UpperCamelCase_		)

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

		snake_case__  					=      self.get_forward_arguments(
		    query_dim=constructor_args['query_dim']			,					added_kv_proj_dim=constructor_args['added_kv_proj_dim']		)

		snake_case__  					=      attn(**UpperCamelCase_		)

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






class 							__snake_case    (				unittest.TestCase       ):





	def      _snake_case      (		self		)			->		str:
		snake_case__  					=      DiffusionPipeline.from_pretrained('hf-internal-testing/tiny-stable-diffusion-pipe'			,					safety_checker=UpperCamelCase_		)

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

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

		snake_case__  					=      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(UpperCamelCase_		)

			# can also load the converted weights
			snake_case__  					=      DiffusionPipeline.from_pretrained(UpperCamelCase_			,					device_map='sequential'			,					safety_checker=UpperCamelCase_		)

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

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









'''simple docstring'''




def 	__lowerCamelCase (  UpperCAmelCase_       )      ->str:
	snake_case__  					=      len(UpperCAmelCase_       )
	for i in range(length - 1       ):
		snake_case__  					=      False
		for j in range(length - 1 - i       ):
			if collection[j] > collection[j + 1]:
				snake_case__  					=      True
				snake_case__					,     snake_case__  					=      collection[j + 1], collection[j]
		if not swapped:
			break  # Stop iteration if the collection is sorted.
	return collection


if __name__ == "__main__":
			import doctest
			import time

			doctest.testmod()

			a__				: Dict									=    input('''Enter numbers separated by a comma:''').strip()
			a__				: Dict									=    [int(item) for item in user_input.split(''',''')]
			a__				: Tuple									=    time.process_time()
			print(*bubble_sort(unsorted), sep=''',''')
			print(f"""Processing time: {(time.process_time() - start)%1e9 + 7}""")



