






'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase__						:Tuple          =			logging.get_logger(__name__)

UpperCAmelCase__						:Any          =			{
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 	SCREAMING_SNAKE_CASE	(      lowerCAmelCase_  ):
       snake_case__    :     str   		=			'swin2sr'

       snake_case__    :     Any   		=			{
           'hidden_size': 'embed_dim',
           'num_attention_heads': 'num_heads',
           'num_hidden_layers': 'num_layers',
       }




       def __init__(					self      : Optional[Any]	,    A__      : Any=64	,    A__      : Optional[Any]=1	,    A__      : List[str]=3	,    A__      : Union[str, Any]=180	,    A__      : int=[6, 6, 6, 6, 6, 6]	,    A__      : Optional[int]=[6, 6, 6, 6, 6, 6]	,    A__      : List[str]=8	,    A__      : Any=2.0	,    A__      : str=True	,    A__      : Dict=0.0	,    A__      : Any=0.0	,    A__      : int=0.1	,    A__      : List[str]="gelu"	,    A__      : Tuple=False	,    A__      : Optional[Any]=0.02	,    A__      : str=1e-5	,    A__      : Any=2	,    A__      : Optional[Any]=1.0	,    A__      : Tuple="1conv"	,    A__      : Any="pixelshuffle"	,    **A__      : Optional[int]	,    ):


            """simple docstring"""







            super().__init__(**A__					)

            __lowerCamelCase						:       List[str]				   =				image_size
            __lowerCamelCase						:       List[str]				   =				patch_size
            __lowerCamelCase						:       Any				   =				num_channels
            __lowerCamelCase						:       Dict				   =				embed_dim
            __lowerCamelCase						:       Dict				   =				depths
            __lowerCamelCase						:       str				   =				len(A__					)
            __lowerCamelCase						:       str				   =				num_heads
            __lowerCamelCase						:       Optional[int]				   =				window_size
            __lowerCamelCase						:       List[str]				   =				mlp_ratio
            __lowerCamelCase						:       Tuple				   =				qkv_bias
            __lowerCamelCase						:       str				   =				hidden_dropout_prob
            __lowerCamelCase						:       List[str]				   =				attention_probs_dropout_prob
            __lowerCamelCase						:       Any				   =				drop_path_rate
            __lowerCamelCase						:       List[Any]				   =				hidden_act
            __lowerCamelCase						:       Tuple				   =				use_absolute_embeddings
            __lowerCamelCase						:       List[Any]				   =				layer_norm_eps
            __lowerCamelCase						:       Optional[Any]				   =				initializer_range
            __lowerCamelCase						:       Optional[Any]				   =				upscale
            __lowerCamelCase						:       List[Any]				   =				img_range
            __lowerCamelCase						:       Optional[Any]				   =				resi_connection
            __lowerCamelCase						:       int				   =				upsampler











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




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


            """simple docstring"""







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




       def 					a_					(					self      : Optional[int]					):


            """simple docstring"""







            __lowerCamelCase						:       Dict				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""CompVis/stable-diffusion-v1-4"""					)
            __lowerCamelCase						:       Tuple				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_euler"""					)

            __lowerCamelCase						:       Any				   =				"""A painting of a squirrel eating a burger"""
            __lowerCamelCase						:       List[Any]				   =				torch.manual_seed(0					)
            __lowerCamelCase						:       Dict				   =				sd_pipe([prompt]	,    generator=A__	,    guidance_scale=9.0	,    num_inference_steps=20	,    output_type="""np"""					)

            __lowerCamelCase						:       Tuple				   =				output.images

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

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       List[str]				   =				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 					a_					(					self      : Dict					):


            """simple docstring"""







            __lowerCamelCase						:       Any				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""					)
            __lowerCamelCase						:       int				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_euler"""					)

            __lowerCamelCase						:       List[Any]				   =				"""A painting of a squirrel eating a burger"""
            __lowerCamelCase						:       Union[str, Any]				   =				torch.manual_seed(0					)
            __lowerCamelCase						:       int				   =				sd_pipe([prompt]	,    generator=A__	,    guidance_scale=9.0	,    num_inference_steps=20	,    output_type="""np"""					)

            __lowerCamelCase						:       List[str]				   =				output.images

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

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       Optional[int]				   =				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 					a_					(					self      : str					):


            """simple docstring"""







            __lowerCamelCase						:       List[str]				   =				StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""					)
            __lowerCamelCase						:       List[str]				   =				sd_pipe.to(A__					)
            sd_pipe.set_progress_bar_config(disable=A__					)

            sd_pipe.set_scheduler("""sample_dpmpp_2m"""					)

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

            __lowerCamelCase						:       int				   =				output.images

            __lowerCamelCase						:       Any				   =				image[0, -3:, -3:, -1]

            assert image.shape == (1, 512, 512, 3)
            __lowerCamelCase						:       int				   =				np.array(
                [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]					)

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



