


"""simple docstring"""
import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch



@require_torch
class 			_UpperCAmelCase :






		'''simple docstring'''

		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return self.get_dummy_input()



		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			if self.block_type == "down":
				return (4, 32, 16, 16)
			elif self.block_type == "mid":
				return (4, 32, 32, 32)
			elif self.block_type == "up":
				return (4, 32, 64, 64)

			raise ValueError(f"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."""					)



		def 				SCREAMING_SNAKE_CASE  (self				,       a_=True				,       a_=False				,       a_=False				,       a_=False				,       ):





			'''simple docstring'''

			__snake_case	:						str						=				4
			__snake_case	:						List[Any]						=				32
			__snake_case	:						Union[str, Any]						=				(32, 32)

			__snake_case	:						Dict						=				torch.manual_seed(0					)
			__snake_case	:						int						=				torch.device(a_					)
			__snake_case	:						str						=				(batch_size, num_channels) + sizes
			__snake_case	:						List[Any]						=				randn_tensor(a_				,       generator=a_				,       device=a_					)
			__snake_case	:						List[str]						=				{'''hidden_states''': hidden_states}

			if include_temb:
				__snake_case	:						Any						=				1_28
				__snake_case	:						Optional[int]						=				randn_tensor((batch_size, temb_channels)				,       generator=a_				,       device=a_					)

			if include_res_hidden_states_tuple:
				__snake_case	:						Any						=				torch.manual_seed(1					)
				__snake_case	:						int						=				(randn_tensor(a_				,       generator=a_				,       device=a_					),)

			if include_encoder_hidden_states:
				__snake_case	:						Optional[Any]						=				floats_tensor((batch_size, 32, 32)					).to(a_					)

			if include_skip_sample:
				__snake_case	:						Optional[Any]						=				randn_tensor(((batch_size, 3) + sizes)				,       generator=a_				,       device=a_					)

			return dummy_input



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Any						=				{
			    '''in_channels''': 32,
			    '''out_channels''': 32,
			    '''temb_channels''': 1_28,
			}
			if self.block_type == "up":
				__snake_case	:						Optional[int]						=				32

			if self.block_type == "mid":
				init_dict.pop('''out_channels'''					)

			__snake_case	:						int						=				self.dummy_input
			return init_dict, inputs_dict



		def 				SCREAMING_SNAKE_CASE  (self				,       a_					):





			'''simple docstring'''

			__snake_case	,							__snake_case	:						List[Any]						=				self.prepare_init_args_and_inputs_for_common()
			__snake_case	:						List[Any]						=				self.block_class(**a_					)
			unet_block.to(a_					)
			unet_block.eval()

			with torch.no_grad():
				__snake_case	:						Union[str, Any]						=				unet_block(**a_					)

			if isinstance(a_				,       a_					):
				__snake_case	:						Tuple						=				output[0]

			self.assertEqual(output.shape				,       self.output_shape					)

			__snake_case	:						Dict						=				output[0, -1, -3:, -3:]
			__snake_case	:						int						=				torch.tensor(a_					).to(a_					)
			assert torch_all_close(output_slice.flatten()				,       a_				,       atol=5E-3					)



		@unittest.skipIf(torch_device == '''mps'''				,       '''Training is not supported in mps'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	,							__snake_case	:						str						=				self.prepare_init_args_and_inputs_for_common()
			__snake_case	:						Optional[int]						=				self.block_class(**a_					)
			model.to(a_					)
			model.train()
			__snake_case	:						int						=				model(**a_					)

			if isinstance(a_				,       a_					):
				__snake_case	:						List[Any]						=				output[0]

			__snake_case	:						Optional[Any]						=				torch.device(a_					)
			__snake_case	:						Tuple						=				randn_tensor(output.shape				,       device=a_					)
			__snake_case	:						str						=				torch.nn.functional.mse_loss(a_				,       a_					)
			loss.backward()










'''simple docstring'''




def 				lowerCAmelCase_   (	_lowerCamelCase:   int					):
		__SCREAMING_SNAKE_CASE       :		str           =		int(_lowerCamelCase					)
		if n_element < 1:
				__SCREAMING_SNAKE_CASE       :		List[str]           =		ValueError("""a should be a positive number"""					)
				raise my_error

		__SCREAMING_SNAKE_CASE       :		List[Any]           =		[1]
		__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       :		Optional[int]           =		(0, 0, 0)
		__SCREAMING_SNAKE_CASE       :		List[str]           =		1
		while index < n_element:
				while hamming_list[i] * 2 <= hamming_list[-1]:
						i += 1
				while hamming_list[j] * 3 <= hamming_list[-1]:
						j += 1
				while hamming_list[k] * 5 <= hamming_list[-1]:
						k += 1
				hamming_list.append(
				    min(hamming_list[i] * 2       ,      hamming_list[j] * 3       ,      hamming_list[k] * 5					)					)
				index += 1
		return hamming_list


if __name__ == "__main__":
						UpperCamelCase__       :	Optional[Any]    = input('''Enter the last number (nth term) of the Hamming Number Series: ''')
						print('''Formula of Hamming Number Series => 2^i * 3^j * 5^k''')
						UpperCamelCase__       :	List[str]    = hamming(int(n))
						print('''-----------------------------------------------------''')
						print(f"The list with nth numbers is: {hamming_numbers}")
						print('''-----------------------------------------------------''')