





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







	'''simple docstring'''




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

			'''simple docstring'''




			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()




	def    UpperCAmelCase			(						self							:     str   )       -> Dict:

			'''simple docstring'''




			__lowercase											=     StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4'   )
			__lowercase											=     sd_pipe.to(__lowerCamelCase   )
			sd_pipe.set_progress_bar_config(disable=__lowerCamelCase   )

			sd_pipe.set_scheduler('sample_euler'   )

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

			__lowercase											=     output.images

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

			assert image.shape == (1, 512, 512, 3)
			__lowercase											=     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    UpperCAmelCase			(						self							:     Tuple   )       -> Dict:

			'''simple docstring'''




			__lowercase											=     StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'   )
			__lowercase											=     sd_pipe.to(__lowerCamelCase   )
			sd_pipe.set_progress_bar_config(disable=__lowerCamelCase   )

			sd_pipe.set_scheduler('sample_euler'   )

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

			__lowercase											=     output.images

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

			assert image.shape == (1, 512, 512, 3)
			__lowercase											=     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    UpperCAmelCase			(						self							:     Union[str, Any]   )       -> str:

			'''simple docstring'''




			__lowercase											=     StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'   )
			__lowercase											=     sd_pipe.to(__lowerCamelCase   )
			sd_pipe.set_progress_bar_config(disable=__lowerCamelCase   )

			sd_pipe.set_scheduler('sample_dpmpp_2m'   )

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

			__lowercase											=     output.images

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

			assert image.shape == (1, 512, 512, 3)
			__lowercase											=     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











from math import factorial



def  SCREAMING_SNAKE_CASE				(      snake_case						,   snake_case							)		->    int:

		# If either of the conditions are true, the function is being asked
		# to calculate a factorial of a negative number, which is not possible
		if n < k or k < 0:
				raise ValueError('Please enter positive integers for n and k where n >= k'							)
		return factorial(snake_case							) // (factorial(snake_case							) * factorial(n - k							))


if __name__ == "__main__":
		print(
		    '''The number of five-card hands possible from a standard''',
		    F"""fifty-two card deck is: {combinations(52, 5)}\n""",
		)

		print(
		    '''If a class of 40 students must be arranged into groups of''',
		    F"""4 for group projects, there are {combinations(40, 4)} ways""",
		    '''to arrange them.\n''',
		)

		print(
		    '''If 10 teams are competing in a Formula One race, there''',
		    F"""are {combinations(10, 3)} ways that first, second and""",
		    '''third place can be awarded.''',
		)




