


import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin

class   A__							(						UpperCamelCase__				,       UpperCamelCase__				,       unittest.TestCase					):
						UpperCAmelCase     =  UNetaDModel
						UpperCAmelCase     =  "sample"




						@property
						def 							__UpperCamelCase			(    self   : List[Any]					)							->       Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					=4
										_SCREAMING_SNAKE_CASE     					=14
										_SCREAMING_SNAKE_CASE     					=16

										_SCREAMING_SNAKE_CASE     					=floats_tensor((batch_size, num_features, seq_len)					).to(_a					)
										_SCREAMING_SNAKE_CASE     					=torch.tensor([10] * batch_size					).to(_a					)

										return {"sample": noise, "timestep": time_step}




						@property
						def 							__UpperCamelCase			(    self   : Optional[Any]					)							->       Union[str, Any]:


										"""simple docstring"""





										return (4, 14, 16)




						@property
						def 							__UpperCamelCase			(    self   : Dict					)							->       Optional[Any]:


										"""simple docstring"""





										return (4, 14, 16)




						def 							__UpperCamelCase			(    self   : List[str]					)							->       int:


										"""simple docstring"""





										pass




						def 							__UpperCamelCase			(    self   : Dict					)							->       Dict:


										"""simple docstring"""





										pass




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Union[str, Any]					)							->       Union[str, Any]:


										"""simple docstring"""





										super().test_determinism()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Optional[Any]					)							->       Any:


										"""simple docstring"""





										super().test_outputs_equivalence()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Optional[int]					)							->       List[Any]:


										"""simple docstring"""





										super().test_from_save_pretrained()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Any					)							->       str:


										"""simple docstring"""





										super().test_from_save_pretrained_variant()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Optional[Any]					)							->       str:


										"""simple docstring"""





										super().test_model_from_pretrained()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : List[str]					)							->       int:


										"""simple docstring"""





										super().test_output()




						def 							__UpperCamelCase			(    self   : str					)							->       int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					={
										    '''block_out_channels''': (32, 64, 128, 256),
										    '''in_channels''': 14,
										    '''out_channels''': 14,
										    '''time_embedding_type''': '''positional''',
										    '''use_timestep_embedding''': True,
										    '''flip_sin_to_cos''': False,
										    '''freq_shift''': 1.0,
										    '''out_block_type''': '''OutConv1DBlock''',
										    '''mid_block_type''': '''MidResTemporalBlock1D''',
										    '''down_block_types''': ('''DownResnetBlock1D''', '''DownResnetBlock1D''', '''DownResnetBlock1D''', '''DownResnetBlock1D'''),
										    '''up_block_types''': ('''UpResnetBlock1D''', '''UpResnetBlock1D''', '''UpResnetBlock1D'''),
										    '''act_fn''': '''mish''',
										}
										_SCREAMING_SNAKE_CASE     					=self.dummy_input
										return init_dict, inputs_dict




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Any					)							->       List[str]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE     					=UNetaDModel.from_pretrained(
										    '''bglick13/hopper-medium-v2-value-function-hor32'''			,      output_loading_info=_a			,      subfolder='''unet'''					)
										self.assertIsNotNone(_a					)
										self.assertEqual(len(loading_info['''missing_keys''']					)			,      0					)

										model.to(_a					)
										_SCREAMING_SNAKE_CASE     					=model(**self.dummy_input					)

										assert image is not None, "Make sure output is not None"




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : str					)							->       Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					=UNetaDModel.from_pretrained('''bglick13/hopper-medium-v2-value-function-hor32'''			,      subfolder='''unet'''					)
										torch.manual_seed(0					)
										if torch.cuda.is_available():
														torch.cuda.manual_seed_all(0					)

										_SCREAMING_SNAKE_CASE     					=model.config.in_channels
										_SCREAMING_SNAKE_CASE     					=16
										_SCREAMING_SNAKE_CASE     					=torch.randn((1, seq_len, num_features)					).permute(
										    0			,      2			,      1					)  # match original, we can update values and remove
										_SCREAMING_SNAKE_CASE     					=torch.full((num_features,)			,      0					)

										with torch.no_grad():
														_SCREAMING_SNAKE_CASE     					=model(_a			,      _a					).sample.permute(0			,      2			,      1					)

										_SCREAMING_SNAKE_CASE     					=output[0, -3:, -3:].flatten()
										# fmt: off
										_SCREAMING_SNAKE_CASE     					=torch.tensor([-2.13_71_72, 1.1_42_60_16, 0.3_68_86_87, -0.76_69_22, 0.7_30_31_46, 0.11_03_88_64, -0.4_76_06_33, 0.13_27_01_72, 0.02_59_13_48]					)
										# fmt: on
										self.assertTrue(torch.allclose(_a			,      _a			,      rtol=1E-3					)					)




						def 							__UpperCamelCase			(    self   : Union[str, Any]					)							->       Tuple:


										"""simple docstring"""





										pass




						@slow
						def 							__UpperCamelCase			(    self   : Dict					)							->       Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					='''harmonai/maestro-150k'''
										_SCREAMING_SNAKE_CASE     					=UNetaDModel.from_pretrained(_a			,      subfolder='''unet'''					)
										model.to(_a					)

										_SCREAMING_SNAKE_CASE     					=6_5536
										_SCREAMING_SNAKE_CASE     					=torch.sin(torch.arange(_a					)[None, None, :].repeat(1			,      2			,      1					)					).to(_a					)
										_SCREAMING_SNAKE_CASE     					=torch.tensor([1]					).to(_a					)

										with torch.no_grad():
														_SCREAMING_SNAKE_CASE     					=model(_a			,      _a					).sample

										_SCREAMING_SNAKE_CASE     					=output.abs().sum()
										_SCREAMING_SNAKE_CASE     					=output.abs().max()

										assert (output_sum - 2_24.08_96).abs() < 0.5
										assert (output_max - 0.06_07).abs() < 4E-4

class   A__							(						UpperCamelCase__				,       UpperCamelCase__				,       unittest.TestCase					):
						UpperCAmelCase     =  UNetaDModel
						UpperCAmelCase     =  "sample"




						@property
						def 							__UpperCamelCase			(    self   : Any					)							->       Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					=4
										_SCREAMING_SNAKE_CASE     					=14
										_SCREAMING_SNAKE_CASE     					=16

										_SCREAMING_SNAKE_CASE     					=floats_tensor((batch_size, num_features, seq_len)					).to(_a					)
										_SCREAMING_SNAKE_CASE     					=torch.tensor([10] * batch_size					).to(_a					)

										return {"sample": noise, "timestep": time_step}




						@property
						def 							__UpperCamelCase			(    self   : int					)							->       Optional[int]:


										"""simple docstring"""





										return (4, 14, 16)




						@property
						def 							__UpperCamelCase			(    self   : Tuple					)							->       Union[str, Any]:


										"""simple docstring"""





										return (4, 14, 1)




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Union[str, Any]					)							->       int:


										"""simple docstring"""





										super().test_determinism()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : List[Any]					)							->       Union[str, Any]:


										"""simple docstring"""





										super().test_outputs_equivalence()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : List[Any]					)							->       Tuple:


										"""simple docstring"""





										super().test_from_save_pretrained()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : int					)							->       Optional[int]:


										"""simple docstring"""





										super().test_from_save_pretrained_variant()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Optional[Any]					)							->       int:


										"""simple docstring"""





										super().test_model_from_pretrained()




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Union[str, Any]					)							->       Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE     					=self.prepare_init_args_and_inputs_for_common()
										_SCREAMING_SNAKE_CASE     					=self.model_class(**_a					)
										model.to(_a					)
										model.eval()

										with torch.no_grad():
														_SCREAMING_SNAKE_CASE     					=model(**_a					)

														if isinstance(_a			,      _a					):
																		_SCREAMING_SNAKE_CASE     					=output.sample

										self.assertIsNotNone(_a					)
										_SCREAMING_SNAKE_CASE     					=torch.Size((inputs_dict['''sample'''].shape[0], 1)					)
										self.assertEqual(output.shape			,      _a			,      '''Input and output shapes do not match'''					)




						def 							__UpperCamelCase			(    self   : int					)							->       Union[str, Any]:


										"""simple docstring"""





										pass




						def 							__UpperCamelCase			(    self   : Optional[int]					)							->       Optional[Any]:


										"""simple docstring"""





										pass




						def 							__UpperCamelCase			(    self   : int					)							->       Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					={
										    '''in_channels''': 14,
										    '''out_channels''': 14,
										    '''down_block_types''': ['''DownResnetBlock1D''', '''DownResnetBlock1D''', '''DownResnetBlock1D''', '''DownResnetBlock1D'''],
										    '''up_block_types''': [],
										    '''out_block_type''': '''ValueFunction''',
										    '''mid_block_type''': '''ValueFunctionMidBlock1D''',
										    '''block_out_channels''': [32, 64, 128, 256],
										    '''layers_per_block''': 1,
										    '''downsample_each_block''': True,
										    '''use_timestep_embedding''': True,
										    '''freq_shift''': 1.0,
										    '''flip_sin_to_cos''': False,
										    '''time_embedding_type''': '''positional''',
										    '''act_fn''': '''mish''',
										}
										_SCREAMING_SNAKE_CASE     					=self.dummy_input
										return init_dict, inputs_dict




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : Dict					)							->       Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE     					=UNetaDModel.from_pretrained(
										    '''bglick13/hopper-medium-v2-value-function-hor32'''			,      output_loading_info=_a			,      subfolder='''value_function'''					)
										self.assertIsNotNone(_a					)
										self.assertEqual(len(vf_loading_info['''missing_keys''']					)			,      0					)

										value_function.to(_a					)
										_SCREAMING_SNAKE_CASE     					=value_function(**self.dummy_input					)

										assert image is not None, "Make sure output is not None"




						@unittest.skipIf(torch_device == '''mps'''			,      '''mish op not supported in MPS'''					)
						def 							__UpperCamelCase			(    self   : str					)							->       Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE     					=UNetaDModel.from_pretrained(
										    '''bglick13/hopper-medium-v2-value-function-hor32'''			,      output_loading_info=_a			,      subfolder='''value_function'''					)
										torch.manual_seed(0					)
										if torch.cuda.is_available():
														torch.cuda.manual_seed_all(0					)

										_SCREAMING_SNAKE_CASE     					=value_function.config.in_channels
										_SCREAMING_SNAKE_CASE     					=14
										_SCREAMING_SNAKE_CASE     					=torch.randn((1, seq_len, num_features)					).permute(
										    0			,      2			,      1					)  # match original, we can update values and remove
										_SCREAMING_SNAKE_CASE     					=torch.full((num_features,)			,      0					)

										with torch.no_grad():
														_SCREAMING_SNAKE_CASE     					=value_function(_a			,      _a					).sample

										# fmt: off
										_SCREAMING_SNAKE_CASE     					=torch.tensor([1_65.25] * seq_len					)
										# fmt: on
										self.assertTrue(torch.allclose(_a			,      _a			,      rtol=1E-3					)					)




						def 							__UpperCamelCase			(    self   : Optional[int]					)							->       Dict:


										"""simple docstring"""





										pass



import math

class   A__							:




						def __init__(    self   : Optional[int]			,      _a   : int			,      _a   : List[Any]			,      _a   : int					)							->       Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE     					=x
										_SCREAMING_SNAKE_CASE     					=y
										_SCREAMING_SNAKE_CASE     					=z




						def __repr__(    self   : List[str]					)							->       str:


										"""simple docstring"""





										return f"Point({self.x}, {self.y}, {self.z})"







def   lowerCamelCase(				a__		,a__):
				return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2))


if __name__ == "__main__":
							import doctest

							doctest.testmod()