

"""simple docstring"""





import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


_a							=							False




class  _lowerCAmelCase  (     unittest.TestCase       ):







 """simple docstring"""







 pass







@nightly
@require_torch_gpu
class  _lowerCAmelCase  (     unittest.TestCase       ):







 """simple docstring"""







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


 def  _lowercase			(      self							:      Optional[Any]     ):
    __lowercase								=						VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"     )
    # remove text_unet
    pipe.remove_unused_weights()
    pipe.to(UpperCAmelCase__     )
    pipe.set_progress_bar_config(disable=UpperCAmelCase__     )

    __lowercase								=						"A painting of a squirrel eating a burger "
    __lowercase								=						torch.manual_seed(0     )
    __lowercase								=						pipe(
        prompt=UpperCAmelCase__, generator=UpperCAmelCase__, guidance_scale=7.5, num_inference_steps=2, output_type="numpy"     ).images

    with tempfile.TemporaryDirectory() as tmpdirname:
       pipe.save_pretrained(UpperCAmelCase__     )
       __lowercase								=						VersatileDiffusionTextToImagePipeline.from_pretrained(UpperCAmelCase__     )
    pipe.to(UpperCAmelCase__     )
    pipe.set_progress_bar_config(disable=UpperCAmelCase__     )

    __lowercase								=						generator.manual_seed(0     )
    __lowercase								=						pipe(
        prompt=UpperCAmelCase__, generator=UpperCAmelCase__, guidance_scale=7.5, num_inference_steps=2, output_type="numpy"     ).images

    assert np.abs(image - new_image     ).sum() < 1E-5, "Models don't have the same forward pass"



 def  _lowercase			(      self							:      List[str]     ):
    __lowercase								=						VersatileDiffusionTextToImagePipeline.from_pretrained(
        "shi-labs/versatile-diffusion", torch_dtype=torch.floataa     )
    pipe.to(UpperCAmelCase__     )
    pipe.set_progress_bar_config(disable=UpperCAmelCase__     )

    __lowercase								=						"A painting of a squirrel eating a burger "
    __lowercase								=						torch.manual_seed(0     )
    __lowercase								=						pipe(
        prompt=UpperCAmelCase__, generator=UpperCAmelCase__, guidance_scale=7.5, num_inference_steps=5_0, output_type="numpy"     ).images

    __lowercase								=						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)
    __lowercase								=						np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778]     )

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







"""simple docstring"""





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


_a							=							logging.get_logger(__name__)

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




class  _lowerCAmelCase  (     lowercase       ):







 """simple docstring"""







 __UpperCAmelCase     : List[Any]       		=     "swin2sr"

 __UpperCAmelCase     : List[Any]       		=     {
     "hidden_size": "embed_dim",
     "num_attention_heads": "num_heads",
     "num_hidden_layers": "num_layers",
 }


 def __init__(      self							:      Any, UpperCAmelCase__							:      Dict=6_4, UpperCAmelCase__							:      List[Any]=1, UpperCAmelCase__							:      Dict=3, UpperCAmelCase__							:      Optional[Any]=1_8_0, UpperCAmelCase__							:      Any=[6, 6, 6, 6, 6, 6], UpperCAmelCase__							:      Dict=[6, 6, 6, 6, 6, 6], UpperCAmelCase__							:      Tuple=8, UpperCAmelCase__							:      Optional[int]=2.0, UpperCAmelCase__							:      List[str]=True, UpperCAmelCase__							:      Tuple=0.0, UpperCAmelCase__							:      Optional[Any]=0.0, UpperCAmelCase__							:      List[str]=0.1, UpperCAmelCase__							:      Dict="gelu", UpperCAmelCase__							:      Dict=False, UpperCAmelCase__							:      Dict=0.02, UpperCAmelCase__							:      Tuple=1E-5, UpperCAmelCase__							:      str=2, UpperCAmelCase__							:      str=1.0, UpperCAmelCase__							:      Optional[int]="1conv", UpperCAmelCase__							:      Dict="pixelshuffle", **UpperCAmelCase__							:      List[Any], ):
    super().__init__(**UpperCAmelCase__     )

    __lowercase								=						image_size
    __lowercase								=						patch_size
    __lowercase								=						num_channels
    __lowercase								=						embed_dim
    __lowercase								=						depths
    __lowercase								=						len(UpperCAmelCase__     )
    __lowercase								=						num_heads
    __lowercase								=						window_size
    __lowercase								=						mlp_ratio
    __lowercase								=						qkv_bias
    __lowercase								=						hidden_dropout_prob
    __lowercase								=						attention_probs_dropout_prob
    __lowercase								=						drop_path_rate
    __lowercase								=						hidden_act
    __lowercase								=						use_absolute_embeddings
    __lowercase								=						layer_norm_eps
    __lowercase								=						initializer_range
    __lowercase								=						upscale
    __lowercase								=						img_range
    __lowercase								=						resi_connection
    __lowercase								=						upsampler




