

"""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					:



	@property
	def     a   (   self			:    List[Any]		):
		return self.get_dummy_input()



	@property
	def     a   (   self			:    Union[str, Any]		):
		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     a   (   self			:    Optional[int]       ,  _lowercase			:    int=True       ,  _lowercase			:    Dict=False       ,  _lowercase			:    Union[str, Any]=False       ,  _lowercase			:    Tuple=False       ,  ):
		__UpperCAmelCase							=      4
		__UpperCAmelCase							=      32
		__UpperCAmelCase							=      (32, 32)

		__UpperCAmelCase							=      torch.manual_seed(0		)
		__UpperCAmelCase							=      torch.device(lowercase__		)
		__UpperCAmelCase							=      (batch_size, num_channels) + sizes
		__UpperCAmelCase							=      randn_tensor(lowercase__       ,  generator=lowercase__       ,  device=lowercase__		)
		__UpperCAmelCase							=      {'''hidden_states''': hidden_states}

		if include_temb:
			__UpperCAmelCase							=      1_28
			__UpperCAmelCase							=      randn_tensor((batch_size, temb_channels)       ,  generator=lowercase__       ,  device=lowercase__		)

		if include_res_hidden_states_tuple:
			__UpperCAmelCase							=      torch.manual_seed(1		)
			__UpperCAmelCase							=      (randn_tensor(lowercase__       ,  generator=lowercase__       ,  device=lowercase__		),)

		if include_encoder_hidden_states:
			__UpperCAmelCase							=      floats_tensor((batch_size, 32, 32)		).to(lowercase__		)

		if include_skip_sample:
			__UpperCAmelCase							=      randn_tensor(((batch_size, 3) + sizes)       ,  generator=lowercase__       ,  device=lowercase__		)

		return dummy_input



	def     a   (   self			:    Any		):
		__UpperCAmelCase							=      {
		    '''in_channels''': 32,
		    '''out_channels''': 32,
		    '''temb_channels''': 1_28,
		}
		if self.block_type == "up":
			__UpperCAmelCase							=      32

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

		__UpperCAmelCase							=      self.dummy_input
		return init_dict, inputs_dict



	def     a   (   self			:    Tuple       ,  _lowercase			:    Tuple		):
		__UpperCAmelCase						,				__UpperCAmelCase							=      self.prepare_init_args_and_inputs_for_common()
		__UpperCAmelCase							=      self.block_class(**lowercase__		)
		unet_block.to(lowercase__		)
		unet_block.eval()

		with torch.no_grad():
			__UpperCAmelCase							=      unet_block(**lowercase__		)

		if isinstance(lowercase__       ,  lowercase__		):
			__UpperCAmelCase							=      output[0]

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

		__UpperCAmelCase							=      output[0, -1, -3:, -3:]
		__UpperCAmelCase							=      torch.tensor(lowercase__		).to(lowercase__		)
		assert torch_all_close(output_slice.flatten()       ,  lowercase__       ,  atol=5E-3		)



	@unittest.skipIf(torch_device == '''mps'''       ,  '''Training is not supported in mps'''		)
	def     a   (   self			:    Dict		):
		__UpperCAmelCase						,				__UpperCAmelCase							=      self.prepare_init_args_and_inputs_for_common()
		__UpperCAmelCase							=      self.block_class(**lowercase__		)
		model.to(lowercase__		)
		model.train()
		__UpperCAmelCase							=      model(**lowercase__		)

		if isinstance(lowercase__       ,  lowercase__		):
			__UpperCAmelCase							=      output[0]

		__UpperCAmelCase							=      torch.device(lowercase__		)
		__UpperCAmelCase							=      randn_tensor(output.shape       ,  device=lowercase__		)
		__UpperCAmelCase							=      torch.nn.functional.mse_loss(lowercase__       ,  lowercase__		)
		loss.backward()



'''simple docstring'''






def 		_A     (    A__ = 10     ,				A__ = 22      ):






 """simple docstring"""



 __lowercase							  = range(1     ,				A__      )
 __lowercase							  = range(1     ,				A__      )
 return sum(
     1 for power in powers for base in bases if len(str(base**power      )      ) == power      )


if __name__ == "__main__":
 print(f'{solution(10, 22) = }')

