





"""simple docstring"""





import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()





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


						def     snake_case_   (self		) ->   Union[str, Any]:
								# clean up the VRAM after each test
								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()


						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	StableDiffusionKDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4"		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								sd_pipe.set_scheduler("sample_euler"		)

								UpperCamelCase   =	"A painting of a squirrel eating a burger"
								UpperCamelCase   =	torch.manual_seed(0		)
								UpperCamelCase   =	sd_pipe([prompt]   ,							generator=__a   ,							guidance_scale=9.0   ,							num_inference_steps=20   ,							output_type="np"		)

								UpperCamelCase   =	output.images

								UpperCamelCase   =	image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								UpperCamelCase   =	np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]		)

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


						def     snake_case_   (self		) ->   List[Any]:
								UpperCamelCase   =	StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								sd_pipe.set_scheduler("sample_euler"		)

								UpperCamelCase   =	"A painting of a squirrel eating a burger"
								UpperCamelCase   =	torch.manual_seed(0		)
								UpperCamelCase   =	sd_pipe([prompt]   ,							generator=__a   ,							guidance_scale=9.0   ,							num_inference_steps=20   ,							output_type="np"		)

								UpperCamelCase   =	output.images

								UpperCamelCase   =	image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								UpperCamelCase   =	np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]		)

								assert np.abs(image_slice.flatten() - expected_slice		).max() < 5e-1




						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"		)
								UpperCamelCase   =	sd_pipe.to(__a		)
								sd_pipe.set_progress_bar_config(disable=__a		)

								sd_pipe.set_scheduler("sample_dpmpp_2m"		)

								UpperCamelCase   =	"A painting of a squirrel eating a burger"
								UpperCamelCase   =	torch.manual_seed(0		)
								UpperCamelCase   =	sd_pipe(
								    [prompt]   ,							generator=__a   ,							guidance_scale=7.5   ,							num_inference_steps=15   ,							output_type="np"   ,							use_karras_sigmas=__a   ,							)

								UpperCamelCase   =	output.images

								UpperCamelCase   =	image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_12, 5_12, 3)
								UpperCamelCase   =	np.array(
								    [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]		)

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













"""simple docstring"""





import argparse
from collections import defaultdict


def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		UpperCamelCase   =	F"{file}_{class_name}_{test_name}"
		done_test[_id] += 1

		with open(_SCREAMING_SNAKE_CASE  ,	"r"    ) as f:
				UpperCamelCase   =	f.readlines()

		UpperCamelCase   =	F"class {class_name}("
		UpperCamelCase   =	F"{4 * ' '}def {test_name}("
		UpperCamelCase   =	F"{8 * ' '}{correct_line.split()[0]}"
		UpperCamelCase   =	F"{16 * ' '}{correct_line.split()[0]}"
		UpperCamelCase   =	False
		UpperCamelCase   =	False
		UpperCamelCase   =	False
		UpperCamelCase   =	False
		UpperCamelCase   =	0
		UpperCamelCase   =	0

		UpperCamelCase   =	[]
		for line in lines:
				if line.startswith(_SCREAMING_SNAKE_CASE    ):
						UpperCamelCase   =	True
				elif in_class and line.startswith(_SCREAMING_SNAKE_CASE    ):
						UpperCamelCase   =	True
				elif in_class and in_func and (line.startswith(_SCREAMING_SNAKE_CASE    ) or line.startswith(_SCREAMING_SNAKE_CASE    )):
						UpperCamelCase   =	len(line.split(correct_line.split()[0]    )[0]    )
						count += 1

						if count == done_test[_id]:
								UpperCamelCase   =	True

				if in_class and in_func and in_line:
						if ")" not in line:
								continue
						else:
								UpperCamelCase   =	True

				if in_class and in_func and in_line and insert_line:
						new_lines.append(F"{spaces * ' '}{correct_line}"    )
						UpperCamelCase   =	UpperCamelCase   =	UpperCamelCase   =	UpperCamelCase   =	False
				else:
						new_lines.append(_SCREAMING_SNAKE_CASE    )

		with open(_SCREAMING_SNAKE_CASE  ,	"w"    ) as f:
				for line in new_lines:
						f.write(_SCREAMING_SNAKE_CASE    )


def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE=None    ):




		"""simple docstring"""


		if fail is not None:
				with open(_SCREAMING_SNAKE_CASE  ,	"r"    ) as f:
						UpperCamelCase   =	{l.strip() for l in f.readlines()}
		else:
				UpperCamelCase   =	None

		with open(_SCREAMING_SNAKE_CASE  ,	"r"    ) as f:
				UpperCamelCase   =	f.readlines()

		UpperCamelCase   =	defaultdict(_SCREAMING_SNAKE_CASE    )
		for line in correct_lines:
				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   =	line.split(";"    )
				if test_failures is None or "::".join([file, class_name, test_name]    ) in test_failures:
						overwrite_file(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE    )


if __name__ == "__main__":
						lowerCAmelCase__     			=			argparse.ArgumentParser()
						parser.add_argument('''--correct_filename''', help='''filename of tests with expected result''')
						parser.add_argument('''--fail_filename''', help='''filename of test failures''', type=str, default=None)
						lowerCAmelCase__     			=			parser.parse_args()

						main(args.correct_filename, args.fail_filename)






