






import math




def    __A    (   _lowercase       ):

					'''simple docstring'''







					if number == 0:
										_A									=       '''Zero'''
										return words
					else:
										_A									=       math.logaa(_lowercase       )
										_A									=       digits + 1
										_A									=       {}
										_A									=       ''''''
										_A									=       '''One'''
										_A									=       '''Two'''
										_A									=       '''Three'''
										_A									=       '''Four'''
										_A									=       '''Five'''
										_A									=       '''Six'''
										_A									=       '''Seven'''
										_A									=       '''Eight'''
										_A									=       '''Nine'''

										_A									=       {}
										_A									=       ''''''
										_A									=       '''Twenty'''
										_A									=       '''Thirty'''
										_A									=       '''Forty'''
										_A									=       '''Fifty'''
										_A									=       '''Sixty'''
										_A									=       '''Seventy'''
										_A									=       '''Eighty'''
										_A									=       '''Ninety'''

										_A									=       {}
										_A									=       '''Ten'''
										_A									=       '''Eleven'''
										_A									=       '''Twelve'''
										_A									=       '''Thirteen'''
										_A									=       '''Fourteen'''
										_A									=       '''Fifteen'''
										_A									=       '''Sixteen'''
										_A									=       '''Seventeen'''
										_A									=       '''Eighteen'''
										_A									=       '''Nineteen'''

										_A									=       {}
										_A									=       '''Hundred,'''
										_A									=       '''Thousand,'''
										_A									=       '''Lakh,'''
										_A									=       '''Crore,'''

										_A									=       number
										_A									=       ''''''
										_A									=       0
										_A									=       int(_lowercase       )
										while counter < digits:
															_A									=       temp_num % 10
															if counter % 2 == 0:
																				_A									=       ''''''
																				if counter in placevalue and current != 0:
																									_A									=       placevalue[counter]
																				if counter == 2:
																									_A									=       singles[current] + addition + words
																				elif counter == 0:
																									if ((temp_num % 1_00) // 10) == 1:
																														_A									=       teens[current] + addition + words
																														_A									=       temp_num // 10
																														counter += 1
																									else:
																														_A									=       singles[current] + addition + words

																				else:
																									_A									=       doubles[current] + addition + words

															else:
																				if counter == 1:
																									if current == 1:
																														_A									=       teens[number % 10] + words
																									else:
																														_A									=       ''''''
																														if counter in placevalue:
																																			_A									=       placevalue[counter]
																														_A									=       doubles[current] + addition + words
																				else:
																									_A									=       ''''''
																									if counter in placevalue:
																														if current == 0 and ((temp_num % 1_00) // 10) == 0:
																																			_A									=       ''''''
																														else:
																																			_A									=       placevalue[counter]
																									if ((temp_num % 1_00) // 10) == 1:
																														_A									=       teens[current] + addition + words
																														_A									=       temp_num // 10
																														counter += 1
																									else:
																														_A									=       singles[current] + addition + words
															counter += 1
															_A									=       temp_num // 10
					return words


if __name__ == "__main__":
				import doctest

				doctest.testmod()











import tempfile
import unittest

import numpy as np
import torch

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





class   SCREAMING_SNAKE_CASE (       unittest.TestCase    ):





							"""simple docstring"""

							def 					__A       (     self:      Optional[Any]						,   __A:      bool = False      )			-> Union[str, Any]:
												_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:      List[Any]						,   __A:      str						,   __A:      Union[str, Any]      )			-> Union[str, Any]:
												_A									=       2

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

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



							def 					__A       (     self:      Optional[int]      )			-> Any:
												# self and cross attention

												torch.manual_seed(0      )

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

												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(**__A      )

												# only self attention

												torch.manual_seed(0      )

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

												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(**__A      )

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





class   SCREAMING_SNAKE_CASE (       unittest.TestCase    ):





							"""simple docstring"""

							def 					__A       (     self:      Any      )			-> Dict:
												_A									=       DiffusionPipeline.from_pretrained('''hf-internal-testing/tiny-stable-diffusion-pipe'''						,   safety_checker=__A      )

												_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=__A      )

												_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(__A      )

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

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

												self.assertTrue(np.allclose(__A						,   __A						,   atol=1e-5      )      )
												self.assertTrue(np.allclose(__A						,   __A						,   atol=1e-5      )      )



