





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


   def 					snake_case				( self					):
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()


   def 					snake_case				( self					):
       A       :       Optional[int]							=						StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''					)
       A       :       Tuple							=						sd_pipe.to(_UpperCAmelCase					)
       sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase					)

       sd_pipe.set_scheduler('''sample_euler'''					)

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

       A       :       int							=						output.images

       A       :       List[str]							=						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       A       :       Any							=						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					):
       A       :       List[Any]							=						StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''					)
       A       :       Optional[int]							=						sd_pipe.to(_UpperCAmelCase					)
       sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase					)

       sd_pipe.set_scheduler('''sample_euler'''					)

       A       :       Optional[Any]							=						'''A painting of a squirrel eating a burger'''
       A       :       Dict							=						torch.manual_seed(0					)
       A       :       Optional[int]							=						sd_pipe([prompt]    ,   generator=_UpperCAmelCase    ,   guidance_scale=9.0    ,   num_inference_steps=20    ,   output_type='''np'''					)

       A       :       Union[str, Any]							=						output.images

       A       :       int							=						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       A       :       List[Any]							=						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					):
       A       :       List[str]							=						StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''					)
       A       :       Optional[int]							=						sd_pipe.to(_UpperCAmelCase					)
       sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase					)

       sd_pipe.set_scheduler('''sample_dpmpp_2m'''					)

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

       A       :       str							=						output.images

       A       :       Dict							=						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       A       :       int							=						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'''






def 							_lowerCamelCase(  UpperCamelCase__    : Union[str, Any]    ,       UpperCamelCase__    : str		)		->  Optional[Any]:
    A       :       Tuple							=						0
    while b > 0:
        if b & 1:
            res += a

        a += a
        b >>= 1

    return res
def 							_lowerCamelCase(  UpperCamelCase__    : Any    ,       UpperCamelCase__    : Any    ,       UpperCamelCase__    : List[str]		)		->  Any:
    A       :       str							=						0
    while b > 0:
        if b & 1:
            A       :       List[Any]							=						((res % c) + (a % c)) % c

        a += a
        b >>= 1

    return res
