


"""simple docstring"""







import importlib
import os
import sys


# This is required to make the module import works (when the python process is running from the root of the repo)
sys.path.append('''.''')




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				test_file.split(os.path.sep   )
					if components[0:2] != ["tests", "models"]:
										raise ValueError(
										    "`test_file` should start with `tests/models/` (with `/` being the OS specific path separator). Got "
										    f"""{test_file} instead."""   )
					__SCREAMING_SNAKE_CASE						   =				components[-1]
					if not test_fn.endswith("py"   ):
										raise ValueError(f"""`test_file` should be a python file. Got {test_fn} instead."""   )
					if not test_fn.startswith("test_modeling_"   ):
										raise ValueError(
										    f"""`test_file` should point to a file name of the form `test_modeling_*.py`. Got {test_fn} instead."""   )

					__SCREAMING_SNAKE_CASE						   =				components[:-1] + [test_fn.replace(".py"  ,						""   )]
					__SCREAMING_SNAKE_CASE						   =				".".join(lowerCAmelCase_   )

					return test_module_path




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_module_path(lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				importlib.import_module(lowerCAmelCase_   )

					return test_module




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				[]
					__SCREAMING_SNAKE_CASE						   =				get_test_module(lowerCAmelCase_   )
					for attr in dir(lowerCAmelCase_   ):
										if attr.endswith("ModelTester"   ):
															tester_classes.append(getattr(lowerCAmelCase_  ,						lowerCAmelCase_   )   )

    # sort with class names
					return sorted(lowerCAmelCase_  ,						key=lambda lowerCAmelCase_   : x.__name__   )




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				[]
					__SCREAMING_SNAKE_CASE						   =				get_test_module(lowerCAmelCase_   )
					for attr in dir(lowerCAmelCase_   ):
										__SCREAMING_SNAKE_CASE						   =				getattr(lowerCAmelCase_  ,						lowerCAmelCase_   )
										# (TF/Flax)ModelTesterMixin is also an attribute in specific model test module. Let's exclude them by checking
										# `all_model_classes` is not empty (which also excludes other special classes).
										__SCREAMING_SNAKE_CASE						   =				getattr(lowerCAmelCase_  ,						"all_model_classes"  ,						[]   )
										if len(lowerCAmelCase_   ) > 0:
															test_classes.append(lowerCAmelCase_   )

    # sort with class names
					return sorted(lowerCAmelCase_  ,						key=lambda lowerCAmelCase_   : x.__name__   )




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_test_classes(lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				set()
					for test_class in test_classes:
										model_classes.update(test_class.all_model_classes   )

					# sort with class names
					return sorted(lowerCAmelCase_  ,						key=lambda lowerCAmelCase_   : x.__name__   )




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				test_class()
					if hasattr(lowerCAmelCase_  ,						"setUp"   ):
										test.setUp()

					__SCREAMING_SNAKE_CASE						   =				None
					if hasattr(lowerCAmelCase_  ,						"model_tester"   ):
										# `(TF/Flax)ModelTesterMixin` has this attribute default to `None`. Let's skip this case.
										if test.model_tester is not None:
															__SCREAMING_SNAKE_CASE						   =				test.model_tester.__class__

					return model_tester




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_test_classes(lowerCAmelCase_   )

					__SCREAMING_SNAKE_CASE						   =				[]
					for test_class in test_classes:
										if model_class in test_class.all_model_classes:
															target_test_classes.append(lowerCAmelCase_   )

    # sort with class names
					return sorted(lowerCAmelCase_  ,						key=lambda lowerCAmelCase_   : x.__name__   )




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_test_classes_for_model(lowerCAmelCase_  ,						lowerCAmelCase_   )

					__SCREAMING_SNAKE_CASE						   =				[]
					for test_class in test_classes:
										__SCREAMING_SNAKE_CASE						   =				get_model_tester_from_test_class(lowerCAmelCase_   )
										if tester_class is not None:
															tester_classes.append(lowerCAmelCase_   )

    # sort with class names
					return sorted(lowerCAmelCase_  ,						key=lambda lowerCAmelCase_   : x.__name__   )




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_test_classes(lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				{test_class: get_model_tester_from_test_class(lowerCAmelCase_   ) for test_class in test_classes}
					return test_tester_mapping




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_model_classes(lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				{
					    model_class: get_test_classes_for_model(lowerCAmelCase_  ,						lowerCAmelCase_   ) for model_class in model_classes
					}
					return model_test_mapping




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				get_model_classes(lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				{
					    model_class: get_tester_classes_for_model(lowerCAmelCase_  ,						lowerCAmelCase_   ) for model_class in model_classes
					}
					return model_to_tester_mapping




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					if isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   ):
										return o
					elif isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   ):
										return o.__name__
					elif isinstance(lowerCAmelCase_  ,						(list, tuple)   ):
										return [to_json(lowerCAmelCase_   ) for x in o]
					elif isinstance(lowerCAmelCase_  ,						lowerCAmelCase_   ):
										return {to_json(lowerCAmelCase_   ): to_json(lowerCAmelCase_   ) for k, v in o.items()}
					else:
										return o




"""simple docstring"""







import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


a__				:							Tuple						=     False




class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	pass




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

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				int   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				VersatileDiffusionImageVariationPipeline.from_pretrained("shi-labs/versatile-diffusion"   )
						pipe.to(UpperCAmelCase__   )
						pipe.set_progress_bar_config(disable=UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE						   =				load_image(
						    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"   )
						__SCREAMING_SNAKE_CASE						   =				torch.manual_seed(0   )
						__SCREAMING_SNAKE_CASE						   =				pipe(
						    image=UpperCAmelCase__			,			generator=UpperCAmelCase__			,			guidance_scale=7.5			,			num_inference_steps=5_0			,			output_type="numpy"			,			).images

						__SCREAMING_SNAKE_CASE						   =				image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

						assert image.shape == (1, 5_1_2, 5_1_2, 3)
						__SCREAMING_SNAKE_CASE						   =				np.array([0.0_441, 0.0_469, 0.0_507, 0.0_575, 0.0_632, 0.0_650, 0.0_865, 0.0_909, 0.0_945]   )

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