






import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 							A_      (  __lowercase	,				__lowercase	,				unittest.TestCase     ):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:     Optional[Any]	=   IFSuperResolutionPipeline
 _SCREAMING_SNAKE_CASE							:     Tuple	=   TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
 _SCREAMING_SNAKE_CASE							:     int	=   TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
 _SCREAMING_SNAKE_CASE							:     List[str]	=   PipelineTesterMixin.required_optional_params - {"latents"}


 def 	snake_case__			(		self)	->						Optional[Any]:

     """simple docstring"""



     return self._get_superresolution_dummy_components()


 def 	snake_case__			(		self							,					_A							,					_A=0)	->						str:

     """simple docstring"""



     if str(_A).startswith('''mps'''):
         _UpperCAmelCase			: int     					=			torch.manual_seed(_A)
     else:
         _UpperCAmelCase			: Tuple     					=			torch.Generator(device=_A).manual_seed(_A)

     _UpperCAmelCase			: Optional[int]     					=			floats_tensor((1, 3, 32, 32)							,					rng=random.Random(_A)).to(_A)

     _UpperCAmelCase			: int     					=			{
         '''prompt''': '''A painting of a squirrel eating a burger''',
         '''image''': image,
         '''generator''': generator,
         '''num_inference_steps''': 2,
         '''output_type''': '''numpy''',
     }

     return inputs


 @unittest.skipIf(
     torch_device != '''cuda''' or not is_xformers_available()							,					reason='''XFormers attention is only available with CUDA and `xformers` installed'''							,					)
 def 	snake_case__			(		self)	->						str:

     """simple docstring"""



     self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3)


 def 	snake_case__			(		self)	->						Tuple:

     """simple docstring"""



     self._test_save_load_optional_components()


 @unittest.skipIf(torch_device != '''cuda'''							,					reason='''float16 requires CUDA''')
 def 	snake_case__			(		self)	->						Optional[Any]:

     """simple docstring"""



     super().test_save_load_floataa(expected_max_diff=1e-1)


 def 	snake_case__			(		self)	->						Union[str, Any]:

     """simple docstring"""



     self._test_attention_slicing_forward_pass(expected_max_diff=1e-2)


 def 	snake_case__			(		self)	->						int:

     """simple docstring"""



     self._test_save_load_local()


 def 	snake_case__			(		self)	->						int:

     """simple docstring"""



     self._test_inference_batch_single_identical(
         expected_max_diff=1e-2							,					)












from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE								=  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE								=  {
    'MBZUAI/swiftformer-xs': 'https://huggingface.co/MBZUAI/swiftformer-xs/resolve/main/config.json',
}
class 							A_      (  __lowercase     ):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:     Dict	=   "swiftformer"


 def __init__(		self							,					_A=3							,					_A=[3, 3, 6, 4]							,					_A=[48, 56, 112, 220]							,					_A=4							,					_A=[True, True, True, True]							,					_A="gelu"							,					_A=3							,					_A=2							,					_A=1							,					_A=0.0							,					_A=True							,					_A=1e-5							,					_A=1e-5							,					**_A							,					)	->						List[Any]:

     """simple docstring"""



     super().__init__(**_A)
     _UpperCAmelCase			: Tuple     					=			num_channels
     _UpperCAmelCase			: Optional[int]     					=			depths
     _UpperCAmelCase			: Union[str, Any]     					=			embed_dims
     _UpperCAmelCase			: Dict     					=			mlp_ratio
     _UpperCAmelCase			: Tuple     					=			downsamples
     _UpperCAmelCase			: str     					=			hidden_act
     _UpperCAmelCase			: int     					=			down_patch_size
     _UpperCAmelCase			: Dict     					=			down_stride
     _UpperCAmelCase			: Dict     					=			down_pad
     _UpperCAmelCase			: Tuple     					=			drop_path_rate
     _UpperCAmelCase			: Tuple     					=			use_layer_scale
     _UpperCAmelCase			: int     					=			layer_scale_init_value
     _UpperCAmelCase			: int     					=			batch_norm_eps



class 							A_      (  __lowercase     ):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:     List[Any]	=   version.parse("1.11"     )


 @property
 def 	snake_case__			(		self)	->						Mapping[str, Mapping[int, str]]:

     """simple docstring"""



     return OrderedDict(
         [
             ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
         ])


 @property
 def 	snake_case__			(		self)	->						float:

     """simple docstring"""



     return 1e-4




