

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




				@property
				def    a							( self	):
											return self.get_dummy_input()




				@property
				def    a							( self	):
											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				,       snake_case=True				,       snake_case=False				,       snake_case=False				,       snake_case=False				,       ):
											snake_case_          =   4
											snake_case_          =   32
											snake_case_          =   (32, 32)

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

											if include_temb:
																		snake_case_          =   128
																		snake_case_          =   randn_tensor((batch_size, temb_channels)				,       generator=snake_case				,       device=snake_case	)

											if include_res_hidden_states_tuple:
																		snake_case_          =   torch.manual_seed(1	)
																		snake_case_          =   (randn_tensor(snake_case				,       generator=snake_case				,       device=snake_case	),)

											if include_encoder_hidden_states:
																		snake_case_          =   floats_tensor((batch_size, 32, 32)	).to(snake_case	)

											if include_skip_sample:
																		snake_case_          =   randn_tensor(((batch_size, 3) + sizes)				,       generator=snake_case				,       device=snake_case	)

											return dummy_input




				def    a							( self	):
											snake_case_          =   {
											    'in_channels': 32,
											    'out_channels': 32,
											    'temb_channels': 128,
											}
											if self.block_type == "up":
																		snake_case_          =   32

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

											snake_case_          =   self.dummy_input
											return init_dict, inputs_dict




				def    a							( self				,       snake_case	):
											snake_case_    ,   snake_case_          =   self.prepare_init_args_and_inputs_for_common()
											snake_case_          =   self.block_class(**snake_case	)
											unet_block.to(snake_case	)
											unet_block.eval()

											with torch.no_grad():
																		snake_case_          =   unet_block(**snake_case	)

											if isinstance(snake_case				,       snake_case	):
																		snake_case_          =   output[0]

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

											snake_case_          =   output[0, -1, -3:, -3:]
											snake_case_          =   torch.tensor(snake_case	).to(snake_case	)
											assert torch_all_close(output_slice.flatten()				,       snake_case				,       atol=5e-3	)




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

											if isinstance(snake_case				,       snake_case	):
																		snake_case_          =   output[0]

											snake_case_          =   torch.device(snake_case	)
											snake_case_          =   randn_tensor(output.shape				,       device=snake_case	)
											snake_case_          =   torch.nn.functional.mse_loss(snake_case				,       snake_case	)
											loss.backward()







def  __lowerCamelCase     (			UpperCamelCase__       ,							UpperCamelCase__				):







							'''simple docstring'''






							return int((input_a, input_a).count(0				) != 0				)





def  __lowerCamelCase     (			):







							'''simple docstring'''






							assert nand_gate(0       ,							0				) == 1
							assert nand_gate(0       ,							1				) == 1
							assert nand_gate(1       ,							0				) == 1
							assert nand_gate(1       ,							1				) == 0


if __name__ == "__main__":
					print(nand_gate(0, 0))
					print(nand_gate(0, 1))
					print(nand_gate(1, 0))
					print(nand_gate(1, 1))




