"""simple docstring"""







import unittest

import numpy as np
import torch

from diffusers import DDIMPipeline, DDIMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, slow, torch_device

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()



class  _lowerCamelCase			(__lowerCamelCase						,							unittest.TestCase     ):
				_snake_case     =  DDIMPipeline
				_snake_case     =  UNCONDITIONAL_IMAGE_GENERATION_PARAMS
				_snake_case     =  PipelineTesterMixin.required_optional_params - {
				    "num_images_per_prompt",
				    "latents",
				    "callback",
				    "callback_steps",
				}
				_snake_case     =  UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS
				_snake_case     =  False







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					torch.manual_seed(0						)
					_lowercase :    Dict							=							UNetaDModel(
					    block_out_channels=(3_2, 6_4)			,					layers_per_block=2			,					sample_size=3_2			,					in_channels=3			,					out_channels=3			,					down_block_types=('DownBlock2D', 'AttnDownBlock2D')			,					up_block_types=('AttnUpBlock2D', 'UpBlock2D')			,					)
					_lowercase :    Dict							=							DDIMScheduler()
					_lowercase :    Optional[int]							=							{'unet': unet, 'scheduler': scheduler}
					return components







				def 							__UpperCAmelCase					( self    :       str			,					lowerCamelCase_    :       List[str]			,					lowerCamelCase_    :       Tuple=0						):

					"""simple docstring"""






					if str(lowerCamelCase_						).startswith('mps'						):
						_lowercase :    Tuple							=							torch.manual_seed(lowerCamelCase_						)
					else:
						_lowercase :    Dict							=							torch.Generator(device=lowerCamelCase_						).manual_seed(lowerCamelCase_						)
					_lowercase :    Optional[int]							=							{
					    'batch_size': 1,
					    'generator': generator,
					    'num_inference_steps': 2,
					    'output_type': 'numpy',
					}
					return inputs







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    str							=							'cpu'

					_lowercase :    Optional[int]							=							self.get_dummy_components()
					_lowercase :    Any							=							self.pipeline_class(**lowerCamelCase_						)
					pipe.to(lowerCamelCase_						)
					pipe.set_progress_bar_config(disable=lowerCamelCase_						)

					_lowercase :    Any							=							self.get_dummy_inputs(lowerCamelCase_						)
					_lowercase :    Optional[int]							=							pipe(**lowerCamelCase_						).images
					_lowercase :    Tuple							=							image[0, -3:, -3:, -1]

					self.assertEqual(image.shape			,					(1, 3_2, 3_2, 3)						)
					_lowercase :    Union[str, Any]							=							np.array(
					    [1.0_00E00, 5.7_17E-01, 4.7_17E-01, 1.0_00E00, 0.0_00E00, 1.0_00E00, 3.0_00E-04, 0.0_00E00, 9.0_00E-04]						)
					_lowercase :    List[str]							=							np.abs(image_slice.flatten() - expected_slice						).max()
					self.assertLessEqual(lowerCamelCase_			,					1E-3						)







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3						)







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					super().test_save_load_local(expected_max_difference=3E-3						)







				def 							__UpperCAmelCase					( self    :       List[str]						):

					"""simple docstring"""






					super().test_save_load_optional_components(expected_max_difference=3E-3						)







				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






					super().test_inference_batch_single_identical(expected_max_diff=3E-3						)



@slow
@require_torch_gpu
class  _lowerCamelCase			(unittest.TestCase     ):







				def 							__UpperCAmelCase					( self    :       Union[str, Any]						):

					"""simple docstring"""






					_lowercase :    Any							=							'google/ddpm-cifar10-32'

					_lowercase :    int							=							UNetaDModel.from_pretrained(lowerCamelCase_						)
					_lowercase :    Optional[Any]							=							DDIMScheduler()

					_lowercase :    Dict							=							DDIMPipeline(unet=lowerCamelCase_			,					scheduler=lowerCamelCase_						)
					ddim.to(lowerCamelCase_						)
					ddim.set_progress_bar_config(disable=lowerCamelCase_						)

					_lowercase :    Dict							=							torch.manual_seed(0						)
					_lowercase :    Optional[Any]							=							ddim(generator=lowerCamelCase_			,					eta=0.0			,					output_type='numpy'						).images

					_lowercase :    Union[str, Any]							=							image[0, -3:, -3:, -1]

					assert image.shape == (1, 3_2, 3_2, 3)
					_lowercase :    Optional[int]							=							np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453]						)

					assert np.abs(image_slice.flatten() - expected_slice						).max() < 1E-2







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    Any							=							'google/ddpm-ema-bedroom-256'

					_lowercase :    int							=							UNetaDModel.from_pretrained(lowerCamelCase_						)
					_lowercase :    List[str]							=							DDIMScheduler.from_pretrained(lowerCamelCase_						)

					_lowercase :    int							=							DDIMPipeline(unet=lowerCamelCase_			,					scheduler=lowerCamelCase_						)
					ddpm.to(lowerCamelCase_						)
					ddpm.set_progress_bar_config(disable=lowerCamelCase_						)

					_lowercase :    List[str]							=							torch.manual_seed(0						)
					_lowercase :    List[str]							=							ddpm(generator=lowerCamelCase_			,					output_type='numpy'						).images

					_lowercase :    Optional[int]							=							image[0, -3:, -3:, -1]

					assert image.shape == (1, 2_5_6, 2_5_6, 3)
					_lowercase :    Any							=							np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069]						)

					assert np.abs(image_slice.flatten() - expected_slice						).max() < 1E-2




"""simple docstring"""







from typing import Any


def      __lowerCAmelCase(		__UpperCAmelCase			):






	"""simple docstring"""





	if not input_list:
		return []
	_lowercase :    List[str]							=							[input_list.count(__UpperCAmelCase			) for value in input_list]
	_lowercase :    Optional[int]							=							max(__UpperCAmelCase			)  # Gets the maximum count in the input list.
	# Gets values of modes
	return sorted({input_list[i] for i, value in enumerate(__UpperCAmelCase			) if value == y}			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()



