





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







      @property
      def   _lowercase    (       self				)  ->		List[Any]:



        '''simple docstring'''




        return self.get_dummy_input()







      @property
      def   _lowercase    (       self				)  ->		str:



        '''simple docstring'''




        if self.block_type == "down":
          return (4, 3_2, 1_6, 1_6)
        elif self.block_type == "mid":
          return (4, 3_2, 3_2, 3_2)
        elif self.block_type == "up":
          return (4, 3_2, 6_4, 6_4)

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







      def   _lowercase    (       self						, lowerCAmelCase__=True						, lowerCAmelCase__=False						, lowerCAmelCase__=False						, lowerCAmelCase__=False						, )  ->		Any:



        '''simple docstring'''




        a__      :   Dict      =4
        a__      :   Union[str, Any]      =3_2
        a__      :   int      =(3_2, 3_2)

        a__      :   Tuple      =torch.manual_seed(0				)
        a__      :   Dict      =torch.device(_UpperCAmelCase				)
        a__      :   str      =(batch_size, num_channels) + sizes
        a__      :   Tuple      =randn_tensor(_UpperCAmelCase						, generator=_UpperCAmelCase						, device=_UpperCAmelCase				)
        a__      :   Optional[int]      ={'hidden_states': hidden_states}

        if include_temb:
          a__      :   Optional[int]      =1_2_8
          a__      :   Union[str, Any]      =randn_tensor((batch_size, temb_channels)						, generator=_UpperCAmelCase						, device=_UpperCAmelCase				)

        if include_res_hidden_states_tuple:
          a__      :   Optional[Any]      =torch.manual_seed(1				)
          a__      :   Optional[int]      =(randn_tensor(_UpperCAmelCase						, generator=_UpperCAmelCase						, device=_UpperCAmelCase				),)

        if include_encoder_hidden_states:
          a__      :   Dict      =floats_tensor((batch_size, 3_2, 3_2)				).to(_UpperCAmelCase				)

        if include_skip_sample:
          a__      :   Union[str, Any]      =randn_tensor(((batch_size, 3) + sizes)						, generator=_UpperCAmelCase						, device=_UpperCAmelCase				)

        return dummy_input







      def   _lowercase    (       self				)  ->		Optional[Any]:



        '''simple docstring'''




        a__      :   List[Any]      ={
            'in_channels': 3_2,
            'out_channels': 3_2,
            'temb_channels': 1_2_8,
        }
        if self.block_type == "up":
          a__      :   Dict      =3_2

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

        a__      :   Any      =self.dummy_input
        return init_dict, inputs_dict







      def   _lowercase    (       self						, lowerCAmelCase__				)  ->		Optional[int]:



        '''simple docstring'''




        a__      :   List[str]      =self.prepare_init_args_and_inputs_for_common()
        a__      :   Dict      =self.block_class(**_UpperCAmelCase				)
        unet_block.to(_UpperCAmelCase				)
        unet_block.eval()

        with torch.no_grad():
          a__      :   Dict      =unet_block(**_UpperCAmelCase				)

        if isinstance(_UpperCAmelCase						, _UpperCAmelCase				):
          a__      :   List[Any]      =output[0]

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

        a__      :   Dict      =output[0, -1, -3:, -3:]
        a__      :   Optional[Any]      =torch.tensor(_UpperCAmelCase				).to(_UpperCAmelCase				)
        assert torch_all_close(output_slice.flatten()						, _UpperCAmelCase						, atol=5E-3				)







      @unittest.skipIf(torch_device == "mps"						, "Training is not supported in mps"				)
      def   _lowercase    (       self				)  ->		List[str]:



        '''simple docstring'''




        a__      :   Optional[int]      =self.prepare_init_args_and_inputs_for_common()
        a__      :   Optional[Any]      =self.block_class(**_UpperCAmelCase				)
        model.to(_UpperCAmelCase				)
        model.train()
        a__      :   Any      =model(**_UpperCAmelCase				)

        if isinstance(_UpperCAmelCase						, _UpperCAmelCase				):
          a__      :   str      =output[0]

        a__      :   Any      =torch.device(_UpperCAmelCase				)
        a__      :   Union[str, Any]      =randn_tensor(output.shape						, device=_UpperCAmelCase				)
        a__      :   int      =torch.nn.functional.mse_loss(_UpperCAmelCase						, _UpperCAmelCase				)
        loss.backward()











'''simple docstring'''

def 	__lowerCamelCase	( )     -> Union[str, Any]:
		_a	: Optional[Any]								=				[]
		_a	: List[str]								=				1

		while len(lowerCAmelCase_    ) < 1E6:
				constant.append(str(lowerCAmelCase_    )    )
				i += 1

		_a	: Optional[Any]								=				''.join(lowerCAmelCase_    )

		return (
		    int(constant[0]    )
		    * int(constant[9]    )
		    * int(constant[99]    )
		    * int(constant[999]    )
		    * int(constant[9999]    )
		    * int(constant[99999]    )
		    * int(constant[999999]    )
		)


if __name__ == "__main__":
							print(solution())




