

import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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						(__magic_name__		,   __magic_name__		,   unittest.TestCase				):


					'''simple docstring'''






					UpperCAmelCase__:   Optional[int]  							=       IFImgaImgSuperResolutionPipeline
					UpperCAmelCase__:   List[Any]  							=       TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
					UpperCAmelCase__:   Tuple  							=       TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}				)
					UpperCAmelCase__:   Optional[Any]  							=       PipelineTesterMixin.required_optional_params - {'''latents'''}






					def   __A			( self			):
						return self._get_superresolution_dummy_components()






					def   __A			( self    ,       A__    ,       A__=0			):
						if str(A__			).startswith("""mps"""			):
							A__							:    Optional[int]        =		torch.manual_seed(A__			)
						else:
							A__							:    Tuple        =		torch.Generator(device=A__			).manual_seed(A__			)

						A__							:    Any        =		floats_tensor((1, 3, 32, 32)    ,       rng=random.Random(A__			)			).to(A__			)
						A__							:    str        =		floats_tensor((1, 3, 16, 16)    ,       rng=random.Random(A__			)			).to(A__			)

						A__							:    int        =		{
						    """prompt""": """A painting of a squirrel eating a burger""",
						    """image""": image,
						    """original_image""": original_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   __A			( self			):
						self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3			)






					def   __A			( self			):
						self._test_save_load_optional_components()






					@unittest.skipIf(torch_device != """cuda"""    ,       reason="""float16 requires CUDA"""			)
					def   __A			( self			):
						# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
						super().test_save_load_floataa(expected_max_diff=1e-1			)






					def   __A			( self			):
						self._test_attention_slicing_forward_pass(expected_max_diff=1e-2			)






					def   __A			( self			):
						self._test_save_load_local()






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






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


A_       : int         =			logging.get_logger(__name__)

A_       : Optional[Any]         =			{
    'alibaba-damo/mgp-str-base': 'https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json',
}



class     _a						(__magic_name__				):


					'''simple docstring'''






					UpperCAmelCase__:   List[Any]  							=       '''mgp-str'''






					def __init__( self    ,       A__=[32, 128]    ,       A__=4    ,       A__=3    ,       A__=27    ,       A__=38    ,       A__=5_0257    ,       A__=3_0522    ,       A__=768    ,       A__=12    ,       A__=12    ,       A__=4.0    ,       A__=True    ,       A__=False    ,       A__=1e-5    ,       A__=0.0    ,       A__=0.0    ,       A__=0.0    ,       A__=False    ,       A__=0.0_2    ,       **A__    ,       ):
						super().__init__(**A__			)

						A__							:    Dict        =		image_size
						A__							:    int        =		patch_size
						A__							:    Dict        =		num_channels
						A__							:    List[Any]        =		max_token_length
						A__							:    str        =		num_character_labels
						A__							:    Tuple        =		num_bpe_labels
						A__							:    Optional[Any]        =		num_wordpiece_labels
						A__							:    Optional[int]        =		hidden_size
						A__							:    Tuple        =		num_hidden_layers
						A__							:    Any        =		num_attention_heads
						A__							:    List[Any]        =		mlp_ratio
						A__							:    Tuple        =		distilled
						A__							:    Union[str, Any]        =		layer_norm_eps
						A__							:    Tuple        =		drop_rate
						A__							:    List[str]        =		qkv_bias
						A__							:    Optional[Any]        =		attn_drop_rate
						A__							:    Union[str, Any]        =		drop_path_rate
						A__							:    Optional[Any]        =		output_aa_attentions
						A__							:    Optional[int]        =		initializer_range



