
'''simple docstring'''







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 				lowerCAmelCase__     (						snake_case__					,		snake_case__					,		unittest.TestCase  ):
					lowerCAmelCase_       =  UNetaDModel
					lowerCAmelCase_       =  'sample'






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  str									= 4
											lowercase_			:  Tuple									= 14
											lowercase_			:  int									= 16

											lowercase_			:  Optional[Any]									= floats_tensor((batch_size, num_features, seq_len)	).to(__SCREAMING_SNAKE_CASE	)
											lowercase_			:  List[Any]									= torch.tensor([10] * batch_size	).to(__SCREAMING_SNAKE_CASE	)

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






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											return (4, 14, 16)






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											return (4, 14, 16)






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_determinism()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_outputs_equivalence()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_from_save_pretrained()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_from_save_pretrained_variant()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_model_from_pretrained()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_output()






					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  List[Any]									= {
											    'block_out_channels': (32, 64, 1_28, 2_56),
											    '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',
											}
											lowercase_			:  Tuple									= self.dummy_input
											return init_dict, inputs_dict






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





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

											model.to(__SCREAMING_SNAKE_CASE	)
											lowercase_			:  int									= 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 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  Optional[int]									= 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	)

											lowercase_			:  Tuple									= model.config.in_channels
											lowercase_			:  Tuple									= 16
											lowercase_			:  Any									= torch.randn((1, seq_len, num_features)	).permute(
											    0       ,							2       ,							1	)  # match original, we can update values and remove
											lowercase_			:  Optional[Any]									= torch.full((num_features,)       ,							0	)

											with torch.no_grad():
																	lowercase_			:  Optional[int]									= model(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE	).sample.permute(0       ,							2       ,							1	)

											lowercase_			:  List[Any]									= output[0, -3:, -3:].flatten()
											# fmt: off
											lowercase_			:  Tuple									= torch.tensor([-2.137_172, 1.1_426_016, 0.3_688_687, -0.766_922, 0.7_303_146, 0.11_038_864, -0.4_760_633, 0.13_270_172, 0.02_591_348]	)
											# fmt: on
											self.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE       ,							rtol=1E-3	)	)






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass






					@slow
					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  Optional[int]									= 'harmonai/maestro-150k'
											lowercase_			:  int									= UNetaDModel.from_pretrained(__SCREAMING_SNAKE_CASE       ,							subfolder='''unet'''	)
											model.to(__SCREAMING_SNAKE_CASE	)

											lowercase_			:  Any									= 6_55_36
											lowercase_			:  Dict									= torch.sin(torch.arange(__SCREAMING_SNAKE_CASE	)[None, None, :].repeat(1       ,							2       ,							1	)	).to(__SCREAMING_SNAKE_CASE	)
											lowercase_			:  Union[str, Any]									= torch.tensor([1]	).to(__SCREAMING_SNAKE_CASE	)

											with torch.no_grad():
																	lowercase_			:  Dict									= model(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE	).sample

											lowercase_			:  Optional[int]									= output.abs().sum()
											lowercase_			:  Union[str, Any]									= output.abs().max()

											assert (output_sum - 224.0_896).abs() < 0.5
											assert (output_max - 0.0_607).abs() < 4E-4







class 				lowerCAmelCase__     (						snake_case__					,		snake_case__					,		unittest.TestCase  ):
					lowerCAmelCase_       =  UNetaDModel
					lowerCAmelCase_       =  'sample'






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  Optional[Any]									= 4
											lowercase_			:  Dict									= 14
											lowercase_			:  List[Any]									= 16

											lowercase_			:  List[Any]									= floats_tensor((batch_size, num_features, seq_len)	).to(__SCREAMING_SNAKE_CASE	)
											lowercase_			:  List[Any]									= torch.tensor([10] * batch_size	).to(__SCREAMING_SNAKE_CASE	)

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






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											return (4, 14, 16)






					@property
					def 			_snake_case					(     self	):


											"""simple docstring"""





											return (4, 14, 1)






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_determinism()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_outputs_equivalence()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_from_save_pretrained()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_from_save_pretrained_variant()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											super().test_model_from_pretrained()






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  Union[str, Any]									= self.prepare_init_args_and_inputs_for_common()
											lowercase_			:  Dict									= self.model_class(**__SCREAMING_SNAKE_CASE	)
											model.to(__SCREAMING_SNAKE_CASE	)
											model.eval()

											with torch.no_grad():
																	lowercase_			:  int									= model(**__SCREAMING_SNAKE_CASE	)

																	if isinstance(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE	):
																							lowercase_			:  List[str]									= output.sample

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






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass






					def 			_snake_case					(     self	):


											"""simple docstring"""





											lowercase_			:  Optional[int]									= {
											    '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, 1_28, 2_56],
											    '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',
											}
											lowercase_			:  Optional[int]									= self.dummy_input
											return init_dict, inputs_dict






					@unittest.skipIf(torch_device == '''mps'''       ,							'''mish op not supported in MPS'''	)
					def 			_snake_case					(     self	):


											"""simple docstring"""





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

											value_function.to(__SCREAMING_SNAKE_CASE	)
											lowercase_			:  List[str]									= 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 			_snake_case					(     self	):


											"""simple docstring"""





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

											lowercase_			:  Optional[Any]									= value_function.config.in_channels
											lowercase_			:  Any									= 14
											lowercase_			:  Dict									= torch.randn((1, seq_len, num_features)	).permute(
											    0       ,							2       ,							1	)  # match original, we can update values and remove
											lowercase_			:  Tuple									= torch.full((num_features,)       ,							0	)

											with torch.no_grad():
																	lowercase_			:  int									= value_function(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE	).sample

											# fmt: off
											lowercase_			:  str									= torch.tensor([165.25] * seq_len	)
											# fmt: on
											self.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE       ,							rtol=1E-3	)	)






					def 			_snake_case					(     self	):


											"""simple docstring"""





											pass





'''simple docstring'''







import math
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				int							):



						"""simple docstring"""





						if 1 < number < 4:
												# 2 and 3 are primes
												return True
						elif number < 2 or number % 2 == 0 or number % 3 == 0:
												# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
												return False

						# All primes number are in format of 6k +/- 1
						for i in range(5   ,   int(math.sqrt(__SCREAMING_SNAKE_CASE							) + 1							)   ,   6							):
												if number % i == 0 or number % (i + 2) == 0:
																		return False
						return True
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				int = 600851475143							):



						"""simple docstring"""





						try:
												lowercase_			:  List[str]									= int(__SCREAMING_SNAKE_CASE							)
						except (TypeError, ValueError):
												raise TypeError('''Parameter n must be int or castable to int.'''							)
						if n <= 0:
												raise ValueError('''Parameter n must be greater than or equal to one.'''							)
						lowercase_			:  Tuple									= 0
						if is_prime(__SCREAMING_SNAKE_CASE							):
												return n
						while n % 2 == 0:
												n //= 2
						if is_prime(__SCREAMING_SNAKE_CASE							):
												return n
						for i in range(3   ,   int(math.sqrt(__SCREAMING_SNAKE_CASE							)							) + 1   ,   2							):
												if n % i == 0:
																		if is_prime(n // i							):
																								lowercase_			:  str									= n // i
																								break
																		elif is_prime(__SCREAMING_SNAKE_CASE							):
																								lowercase_			:  Optional[Any]									= i
						return max_number


if __name__ == "__main__":
							print(f"""{solution() = }""")



