



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      snake_case__   (     self):

              '''simple docstring'''

              return self.get_dummy_input()







       @property
       def      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      snake_case__   (     self,    __a=True,    __a=False,    __a=False,    __a=False,    ):

              '''simple docstring'''

              _lowerCAmelCase  :							Optional[Any]				     =					4
              _lowerCAmelCase  :							List[str]				     =					32
              _lowerCAmelCase  :							Any				     =					(32, 32)

              _lowerCAmelCase  :							str				     =					torch.manual_seed(0)
              _lowerCAmelCase  :							int				     =					torch.device(__lowerCamelCase)
              _lowerCAmelCase  :							List[str]				     =					(batch_size, num_channels) + sizes
              _lowerCAmelCase  :							Dict				     =					randn_tensor(__lowerCamelCase,    generator=__lowerCamelCase,    device=__lowerCamelCase)
              _lowerCAmelCase  :							int				     =					{"hidden_states": hidden_states}

              if include_temb:
                     _lowerCAmelCase  :							Any				     =					128
                     _lowerCAmelCase  :							List[str]				     =					randn_tensor((batch_size, temb_channels),    generator=__lowerCamelCase,    device=__lowerCamelCase)

              if include_res_hidden_states_tuple:
                     _lowerCAmelCase  :							str				     =					torch.manual_seed(1)
                     _lowerCAmelCase  :							Tuple				     =					(randn_tensor(__lowerCamelCase,    generator=__lowerCamelCase,    device=__lowerCamelCase),)

              if include_encoder_hidden_states:
                     _lowerCAmelCase  :							Dict				     =					floats_tensor((batch_size, 32, 32)).to(__lowerCamelCase)

              if include_skip_sample:
                     _lowerCAmelCase  :							Optional[int]				     =					randn_tensor(((batch_size, 3) + sizes),    generator=__lowerCamelCase,    device=__lowerCamelCase)

              return dummy_input







       def      snake_case__   (     self):

              '''simple docstring'''

              _lowerCAmelCase  :							Dict				     =					{
                  "in_channels": 32,
                  "out_channels": 32,
                  "temb_channels": 128,
              }
              if self.block_type == "up":
                     _lowerCAmelCase  :							Dict				     =					32

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

              _lowerCAmelCase  :							str				     =					self.dummy_input
              return init_dict, inputs_dict







       def      snake_case__   (     self,    __a):

              '''simple docstring'''

              _lowerCAmelCase  :							str				     =					self.prepare_init_args_and_inputs_for_common()
              _lowerCAmelCase  :							List[Any]				     =					self.block_class(**__lowerCamelCase)
              unet_block.to(__lowerCamelCase)
              unet_block.eval()

              with torch.no_grad():
                     _lowerCAmelCase  :							int				     =					unet_block(**__lowerCamelCase)

              if isinstance(__lowerCamelCase,    __lowerCamelCase):
                     _lowerCAmelCase  :							Union[str, Any]				     =					output[0]

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

              _lowerCAmelCase  :							Any				     =					output[0, -1, -3:, -3:]
              _lowerCAmelCase  :							Union[str, Any]				     =					torch.tensor(__lowerCamelCase).to(__lowerCamelCase)
              assert torch_all_close(output_slice.flatten(),    __lowerCamelCase,    atol=5E-3)







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

              '''simple docstring'''

              _lowerCAmelCase  :							Tuple				     =					self.prepare_init_args_and_inputs_for_common()
              _lowerCAmelCase  :							str				     =					self.block_class(**__lowerCamelCase)
              model.to(__lowerCamelCase)
              model.train()
              _lowerCAmelCase  :							Optional[int]				     =					model(**__lowerCamelCase)

              if isinstance(__lowerCamelCase,    __lowerCamelCase):
                     _lowerCAmelCase  :							Optional[Any]				     =					output[0]

              _lowerCAmelCase  :							List[str]				     =					torch.device(__lowerCamelCase)
              _lowerCAmelCase  :							List[str]				     =					randn_tensor(output.shape,    device=__lowerCamelCase)
              _lowerCAmelCase  :							Dict				     =					torch.nn.functional.mse_loss(__lowerCamelCase,    __lowerCamelCase)
              loss.backward()





import baseaa






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaaencode(string.encode("utf-8"						)						)






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaadecode(_lowerCamelCase						).decode("utf-8"						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
