





import random
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		import PIL

		from transformers import FlavaImageProcessor
		from transformers.image_utils import PILImageResampling
		from transformers.models.flava.image_processing_flava import (
		    FLAVA_CODEBOOK_MEAN,
		    FLAVA_CODEBOOK_STD,
		    FLAVA_IMAGE_MEAN,
		    FLAVA_IMAGE_STD,
		)
else:
		SCREAMING_SNAKE_CASE_      :			Union[str, Any]		  =      None

class 		snake_case_      (       unittest.TestCase	):







	'''simple docstring'''




	def __init__(	self       :    Optional[Any]				,			__lowerCamelCase       :    Optional[Any]				,			__lowerCamelCase       :    Tuple=7				,			__lowerCamelCase       :    Optional[int]=3				,			__lowerCamelCase       :    Tuple=30				,			__lowerCamelCase       :    Optional[int]=400				,			__lowerCamelCase       :    Any=True				,			__lowerCamelCase       :    Tuple=None				,			__lowerCamelCase       :    Optional[Any]=True				,			__lowerCamelCase       :    Union[str, Any]=None				,			__lowerCamelCase       :    Dict=None				,			__lowerCamelCase       :    Tuple=True				,			__lowerCamelCase       :    Optional[int]=1 / 255				,			__lowerCamelCase       :    Optional[Any]=True				,			__lowerCamelCase       :    Any=FLAVA_IMAGE_MEAN				,			__lowerCamelCase       :    Optional[Any]=FLAVA_IMAGE_STD				,			__lowerCamelCase       :    Dict=14				,			__lowerCamelCase       :    List[str]=75				,			__lowerCamelCase       :    Optional[Any]=None				,			__lowerCamelCase       :    List[Any]=16				,			__lowerCamelCase       :    List[Any]=0.3				,			__lowerCamelCase       :    Optional[int]=None				,			__lowerCamelCase       :    Union[str, Any]=True				,			__lowerCamelCase       :    Any=None				,			__lowerCamelCase       :    List[str]=None				,			__lowerCamelCase       :    Optional[Any]=True				,			__lowerCamelCase       :    List[str]=None				,			__lowerCamelCase       :    Union[str, Any]=True				,			__lowerCamelCase       :    Tuple=True				,			__lowerCamelCase       :    Optional[Any]=FLAVA_CODEBOOK_MEAN				,			__lowerCamelCase       :    Tuple=FLAVA_CODEBOOK_STD				,			)					->   Dict:

			'''simple docstring'''




			__lowercase					=    size if size is not None else {'height': 224, 'width': 224}
			__lowercase					=    crop_size if crop_size is not None else {'height': 224, 'width': 224}
			__lowercase					=    codebook_size if codebook_size is not None else {'height': 112, 'width': 112}
			__lowercase					=    codebook_crop_size if codebook_crop_size is not None else {'height': 112, 'width': 112}

			__lowercase					=    parent
			__lowercase					=    batch_size
			__lowercase					=    num_channels
			__lowercase					=    do_resize
			__lowercase					=    do_rescale
			__lowercase					=    rescale_factor
			__lowercase					=    min_resolution
			__lowercase					=    max_resolution
			__lowercase					=    size
			__lowercase					=    resample if resample is not None else PILImageResampling.BICUBIC
			__lowercase					=    do_normalize
			__lowercase					=    image_mean
			__lowercase					=    image_std
			__lowercase					=    do_center_crop
			__lowercase					=    crop_size

			__lowercase					=    input_size_patches
			__lowercase					=    total_mask_patches
			__lowercase					=    mask_group_max_patches
			__lowercase					=    mask_group_min_patches
			__lowercase					=    mask_group_min_aspect_ratio
			__lowercase					=    mask_group_max_aspect_ratio

			__lowercase					=    codebook_do_resize
			__lowercase					=    codebook_size
			__lowercase					=    codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
			__lowercase					=    codebook_do_center_crop
			__lowercase					=    codebook_crop_size
			__lowercase					=    codebook_do_map_pixels
			__lowercase					=    codebook_do_normalize
			__lowercase					=    codebook_image_mean
			__lowercase					=    codebook_image_std




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

			'''simple docstring'''




			return {
			    "image_mean": self.image_mean,
			    "image_std": self.image_std,
			    "do_normalize": self.do_normalize,
			    "do_resize": self.do_resize,
			    "size": self.size,
			    "resample": self.resample,
			    "do_rescale": self.do_rescale,
			    "rescale_factor": self.rescale_factor,
			    "do_center_crop": self.do_center_crop,
			    "crop_size": self.crop_size,
			    "input_size_patches": self.input_size_patches,
			    "total_mask_patches": self.total_mask_patches,
			    "mask_group_max_patches": self.mask_group_max_patches,
			    "mask_group_min_patches": self.mask_group_min_patches,
			    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
			    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
			    "codebook_do_resize": self.codebook_do_resize,
			    "codebook_size": self.codebook_size,
			    "codebook_resample": self.codebook_resample,
			    "codebook_do_center_crop": self.codebook_do_center_crop,
			    "codebook_crop_size": self.codebook_crop_size,
			    "codebook_do_map_pixels": self.codebook_do_map_pixels,
			    "codebook_do_normalize": self.codebook_do_normalize,
			    "codebook_image_mean": self.codebook_image_mean,
			    "codebook_image_std": self.codebook_image_std,
			}




	def       UpperCAmelCase (	self       :    int      )					->   Dict:

			'''simple docstring'''




			return (self.size["height"], self.size["width"])




	def       UpperCAmelCase (	self       :    List[Any]      )					->   Any:

			'''simple docstring'''




			return (
			    (self.input_size_patches, self.input_size_patches)
			    if not isinstance(self.input_size_patches				,			__lowerCamelCase      )
			    else self.input_size_patches
			)






	def       UpperCAmelCase (	self       :    Union[str, Any]      )					->   List[Any]:

			'''simple docstring'''




			return (self.codebook_size["height"], self.codebook_size["width"])





@require_torch
@require_vision
class 		snake_case_      (       UpperCAmelCase_    ,    unittest.TestCase	):







	'''simple docstring'''
	__UpperCamelCase        =		FlavaImageProcessor if is_vision_available() else None
	__UpperCamelCase        =		None




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

			'''simple docstring'''




			__lowercase					=    FlavaImageProcessingTester(self      )




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

			'''simple docstring'''




			return self.image_processor_tester.prepare_image_processor_dict()




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

			'''simple docstring'''




			__lowercase					=    self.image_processing_class(**self.image_processor_dict      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'image_mean'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'image_std'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'do_normalize'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'do_resize'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'resample'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'crop_size'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'do_center_crop'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'do_rescale'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'rescale_factor'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'masking_generator'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_do_resize'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_size'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_resample'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_do_center_crop'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_crop_size'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_do_map_pixels'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_do_normalize'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_image_mean'      )      )
			self.assertTrue(hasattr(__lowerCamelCase				,			'codebook_image_std'      )      )




	def       UpperCAmelCase (	self       :    str      )					->   str:

			'''simple docstring'''




			__lowercase					=    self.image_processing_class.from_dict(self.image_processor_dict      )
			self.assertEqual(image_processor.size				,			{'height': 224, 'width': 224}      )
			self.assertEqual(image_processor.crop_size				,			{'height': 224, 'width': 224}      )
			self.assertEqual(image_processor.codebook_size				,			{'height': 112, 'width': 112}      )
			self.assertEqual(image_processor.codebook_crop_size				,			{'height': 112, 'width': 112}      )

			__lowercase					=    self.image_processing_class.from_dict(
			    self.image_processor_dict				,			size=42				,			crop_size=84				,			codebook_size=33				,			codebook_crop_size=66      )
			self.assertEqual(image_processor.size				,			{'height': 42, 'width': 42}      )
			self.assertEqual(image_processor.crop_size				,			{'height': 84, 'width': 84}      )
			self.assertEqual(image_processor.codebook_size				,			{'height': 33, 'width': 33}      )
			self.assertEqual(image_processor.codebook_crop_size				,			{'height': 66, 'width': 66}      )




	def       UpperCAmelCase (	self       :    Any      )					->   str:

			'''simple docstring'''




			pass




	def       UpperCAmelCase (	self       :    Tuple      )					->   Any:

			'''simple docstring'''




			__lowercase					=    self.image_processing_class(**self.image_processor_dict      )
			# create random PIL images
			__lowercase					=    prepare_image_inputs(self.image_processor_tester				,			equal_resolution=__lowerCamelCase      )
			for image in image_inputs:
					self.assertIsInstance(__lowerCamelCase				,			PIL.Image.Image      )

			# Test not batched input
			__lowercase					=    image_processing(image_inputs[0]				,			return_tensors='pt'      )

			# Test no bool masked pos
			self.assertFalse('bool_masked_pos' in encoded_images      )

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()

			self.assertEqual(
			    encoded_images.pixel_values.shape				,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)				,			)

			# Test batched
			__lowercase					=    image_processing(__lowerCamelCase				,			return_tensors='pt'      )
			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()

			# Test no bool masked pos
			self.assertFalse('bool_masked_pos' in encoded_images      )

			self.assertEqual(
			    encoded_images.pixel_values.shape				,			(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        expected_height,
			        expected_width,
			    )				,			)




	def       UpperCAmelCase (	self       :    List[Any]				,			__lowerCamelCase       :    Tuple				,			__lowerCamelCase       :    Optional[int]      )					->   Dict:

			'''simple docstring'''




			__lowercase					=    self.image_processing_class(**self.image_processor_dict      )
			# create random tensors
			__lowercase					=    prepare_image_inputs(self.image_processor_tester				,			equal_resolution=__lowerCamelCase				,			**__lowerCamelCase      )
			for image in image_inputs:
					self.assertIsInstance(__lowerCamelCase				,			__lowerCamelCase      )

			# Test not batched input
			__lowercase					=    image_processing(image_inputs[0]				,			return_tensors='pt'      )

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()
			self.assertEqual(
			    encoded_images.pixel_values.shape				,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)				,			)

			__lowercase					=    image_processing(__lowerCamelCase				,			return_image_mask=__lowerCamelCase				,			return_tensors='pt'      )

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()
			self.assertEqual(
			    encoded_images.pixel_values.shape				,			(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        expected_height,
			        expected_width,
			    )				,			)

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_mask_size()
			self.assertEqual(
			    encoded_images.bool_masked_pos.shape				,			(
			        self.image_processor_tester.batch_size,
			        expected_height,
			        expected_width,
			    )				,			)

			# Test batched
			__lowercase					=    image_processing(__lowerCamelCase				,			return_tensors='pt'      ).pixel_values

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()
			self.assertEqual(
			    encoded_images.shape				,			(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        expected_height,
			        expected_width,
			    )				,			)

			# Test masking
			__lowercase					=    image_processing(__lowerCamelCase				,			return_image_mask=__lowerCamelCase				,			return_tensors='pt'      )

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_image_size()
			self.assertEqual(
			    encoded_images.pixel_values.shape				,			(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        expected_height,
			        expected_width,
			    )				,			)

			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_mask_size()
			self.assertEqual(
			    encoded_images.bool_masked_pos.shape				,			(
			        self.image_processor_tester.batch_size,
			        expected_height,
			        expected_width,
			    )				,			)




	def       UpperCAmelCase (	self       :    Any      )					->   List[str]:

			'''simple docstring'''




			self._test_call_framework(np.ndarray				,			prepare_kwargs={'numpify': True}      )




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

			'''simple docstring'''




			self._test_call_framework(torch.Tensor				,			prepare_kwargs={'torchify': True}      )




	def       UpperCAmelCase (	self       :    Any      )					->   List[Any]:

			'''simple docstring'''




			random.seed(1_234      )
			__lowercase					=    self.image_processing_class(**self.image_processor_dict      )
			__lowercase					=    prepare_image_inputs(self.image_processor_tester				,			equal_resolution=__lowerCamelCase				,			torchify=__lowerCamelCase      )

			# Test not batched input
			__lowercase					=    image_processing(image_inputs[0]				,			return_image_mask=__lowerCamelCase				,			return_tensors='pt'      )
			self.assertEqual(encoded_images.bool_masked_pos.sum().item()				,			75      )






	def       UpperCAmelCase (	self       :    str      )					->   Tuple:

			'''simple docstring'''




			__lowercase					=    self.image_processing_class(**self.image_processor_dict      )
			# create random PIL images
			__lowercase					=    prepare_image_inputs(self.image_processor_tester				,			equal_resolution=__lowerCamelCase      )
			for image in image_inputs:
					self.assertIsInstance(__lowerCamelCase				,			PIL.Image.Image      )

			# Test not batched input
			__lowercase					=    image_processing(image_inputs[0]				,			return_codebook_pixels=__lowerCamelCase				,			return_tensors='pt'      )
			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_codebook_image_size()
			self.assertEqual(
			    encoded_images.codebook_pixel_values.shape				,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)				,			)

			# Test batched
			__lowercase					=    image_processing(__lowerCamelCase				,			return_codebook_pixels=__lowerCamelCase				,			return_tensors='pt'      )
			__lowercase	,			__lowercase					=    self.image_processor_tester.get_expected_codebook_image_size()
			self.assertEqual(
			    encoded_images.codebook_pixel_values.shape				,			(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        expected_height,
			        expected_width,
			    )				,			)











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 		snake_case_      (       UpperCAmelCase_    ,    UpperCAmelCase_    ,    unittest.TestCase	):







	'''simple docstring'''
	__UpperCamelCase        =		UNetaDModel
	__UpperCamelCase        =		'''sample'''




	@property
	def       UpperCAmelCase (	self       :    str      )					->   List[str]:

			'''simple docstring'''




			__lowercase					=    4
			__lowercase					=    14
			__lowercase					=    16

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

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




	@property
	def       UpperCAmelCase (	self       :    List[str]      )					->   Union[str, Any]:

			'''simple docstring'''




			return (4, 14, 16)




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

			'''simple docstring'''




			return (4, 14, 16)




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

			'''simple docstring'''




			pass




	def       UpperCAmelCase (	self       :    Union[str, Any]      )					->   Dict:

			'''simple docstring'''




			pass




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

			'''simple docstring'''




			super().test_determinism()




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

			'''simple docstring'''




			super().test_outputs_equivalence()




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

			'''simple docstring'''




			super().test_from_save_pretrained()




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

			'''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       :    Optional[int]      )					->   Tuple:

			'''simple docstring'''




			super().test_output()




	def       UpperCAmelCase (	self       :    List[Any]      )					->   List[str]:

			'''simple docstring'''




			__lowercase					=    {
			    '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',
			}
			__lowercase					=    self.dummy_input
			return init_dict, inputs_dict




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

			'''simple docstring'''




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

			model.to(__lowerCamelCase      )
			__lowercase					=    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       :    List[str]      )					->   Dict:

			'''simple docstring'''




			__lowercase					=    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					=    model.config.in_channels
			__lowercase					=    16
			__lowercase					=    torch.randn((1, seq_len, num_features)      ).permute(
			    0				,			2				,			1      )  # match original, we can update values and remove
			__lowercase					=    torch.full((num_features,)				,			0      )

			with torch.no_grad():
					__lowercase					=    model(__lowerCamelCase				,			__lowerCamelCase      ).sample.permute(0				,			2				,			1      )

			__lowercase					=    output[0, -3:, -3:].flatten()
			# fmt: off
			__lowercase					=    torch.tensor([-2.137172, 1.1426016, 0.3688687, -0.766922, 0.7303146, 0.11038864, -0.4760633, 0.13270172, 0.02591348]      )
			# fmt: on
			self.assertTrue(torch.allclose(__lowerCamelCase				,			__lowerCamelCase				,			rtol=1E-3      )      )




	def       UpperCAmelCase (	self       :    List[Any]      )					->   int:

			'''simple docstring'''




			pass






	@slow
	def       UpperCAmelCase (	self       :    List[str]      )					->   Dict:

			'''simple docstring'''




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

			__lowercase					=    65_536
			__lowercase					=    torch.sin(torch.arange(__lowerCamelCase      )[None, None, :].repeat(1				,			2				,			1      )      ).to(__lowerCamelCase      )
			__lowercase					=    torch.tensor([1]      ).to(__lowerCamelCase      )

			with torch.no_grad():
					__lowercase					=    model(__lowerCamelCase				,			__lowerCamelCase      ).sample

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

			assert (output_sum - 224.0896).abs() < 0.5
			assert (output_max - 0.0607).abs() < 4E-4





class 		snake_case_      (       UpperCAmelCase_    ,    UpperCAmelCase_    ,    unittest.TestCase	):







	'''simple docstring'''
	__UpperCamelCase        =		UNetaDModel
	__UpperCamelCase        =		'''sample'''




	@property
	def       UpperCAmelCase (	self       :    int      )					->   Union[str, Any]:

			'''simple docstring'''




			__lowercase					=    4
			__lowercase					=    14
			__lowercase					=    16

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

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




	@property
	def       UpperCAmelCase (	self       :    List[str]      )					->   Union[str, Any]:

			'''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       :    Dict      )					->   str:

			'''simple docstring'''




			super().test_determinism()




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

			'''simple docstring'''




			super().test_outputs_equivalence()




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

			'''simple docstring'''




			super().test_from_save_pretrained()




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

			'''simple docstring'''




			super().test_from_save_pretrained_variant()




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

			'''simple docstring'''




			super().test_model_from_pretrained()




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

			'''simple docstring'''




			__lowercase	,			__lowercase					=    self.prepare_init_args_and_inputs_for_common()
			__lowercase					=    self.model_class(**__lowerCamelCase      )
			model.to(__lowerCamelCase      )
			model.eval()

			with torch.no_grad():
					__lowercase					=    model(**__lowerCamelCase      )

					if isinstance(__lowerCamelCase				,			__lowerCamelCase      ):
							__lowercase					=    output.sample

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




	def       UpperCAmelCase (	self       :    Optional[int]      )					->   str:

			'''simple docstring'''




			pass




	def       UpperCAmelCase (	self       :    Optional[int]      )					->   Optional[int]:

			'''simple docstring'''




			pass




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

			'''simple docstring'''




			__lowercase					=    {
			    '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',
			}
			__lowercase					=    self.dummy_input
			return init_dict, inputs_dict




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

			'''simple docstring'''




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

			value_function.to(__lowerCamelCase      )
			__lowercase					=    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       :    Union[str, Any]      )					->   Optional[Any]:

			'''simple docstring'''




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

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

			with torch.no_grad():
					__lowercase					=    value_function(__lowerCamelCase				,			__lowerCamelCase      ).sample

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






	def       UpperCAmelCase (	self       :    Dict      )					->   str:

			'''simple docstring'''




			pass




