






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			(     UpperCamelCase					,					UpperCamelCase					,					unittest.TestCase				):
    """simple docstring"""

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



    def _a							(				self      :     Any      )      ->							List[Any]:
           return self._get_superresolution_dummy_components()



    def _a							(				self      :     str ,     __SCREAMING_SNAKE_CASE      :     Union[str, Any] ,     __SCREAMING_SNAKE_CASE      :     Optional[Any]=0      )      ->							int:
           if str(__SCREAMING_SNAKE_CASE      ).startswith("""mps"""      ):
                  __UpperCAmelCase     				=torch.manual_seed(__SCREAMING_SNAKE_CASE      )
           else:
                  __UpperCAmelCase     				=torch.Generator(device=__SCREAMING_SNAKE_CASE      ).manual_seed(__SCREAMING_SNAKE_CASE      )

           __UpperCAmelCase     				=floats_tensor((1, 3, 32, 32) ,     rng=random.Random(__SCREAMING_SNAKE_CASE      )      ).to(__SCREAMING_SNAKE_CASE      )
           __UpperCAmelCase     				=floats_tensor((1, 3, 16, 16) ,     rng=random.Random(__SCREAMING_SNAKE_CASE      )      ).to(__SCREAMING_SNAKE_CASE      )

           __UpperCAmelCase     				={
               """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      :     Optional[Any]      )      ->							Dict:
           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )



    def _a							(				self      :     str      )      ->							str:
           self._test_save_load_optional_components()



    @unittest.skipIf(torch_device != """cuda""" ,     reason="""float16 requires CUDA"""      )
    def _a							(				self      :     Optional[Any]      )      ->							str:
           # 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      :     Any      )      ->							Optional[int]:
           self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )



    def _a							(				self      :     List[Any]      )      ->							Tuple:
           self._test_save_load_local()



    def _a							(				self      :     List[Any]      )      ->							Union[str, Any]:
           self._test_inference_batch_single_identical(
               expected_max_diff=1e-2 ,     )





"""simple docstring"""






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


__lowerCAmelCase       :			int   	=logging.get_logger(__name__)

__lowerCAmelCase       :			Optional[Any]   	={
    """uw-madison/mra-base-512-4""": """https://huggingface.co/uw-madison/mra-base-512-4/resolve/main/config.json""",
}





class 					_A		(			lowerCAmelCase      ):
      snake_case__     :  Optional[int]				    =      'mra'

      def __init__(		self						,			__lowerCAmelCase=5_0265						,			__lowerCAmelCase=768						,			__lowerCAmelCase=12						,			__lowerCAmelCase=12						,			__lowerCAmelCase=3072						,			__lowerCAmelCase="gelu"						,			__lowerCAmelCase=0.1						,			__lowerCAmelCase=0.1						,			__lowerCAmelCase=512						,			__lowerCAmelCase=1						,			__lowerCAmelCase=0.0_2						,			__lowerCAmelCase=1E-5						,			__lowerCAmelCase="absolute"						,			__lowerCAmelCase=4						,			__lowerCAmelCase="full"						,			__lowerCAmelCase=0						,			__lowerCAmelCase=0						,			__lowerCAmelCase=1						,			__lowerCAmelCase=0						,			__lowerCAmelCase=2						,			**__lowerCAmelCase						,			):







            """simple docstring"""



            super().__init__(pad_token_id=__lowerCAmelCase						,			bos_token_id=__lowerCAmelCase						,			eos_token_id=__lowerCAmelCase						,			**__lowerCAmelCase		)

            lowercase								=      vocab_size
            lowercase								=      max_position_embeddings
            lowercase								=      hidden_size
            lowercase								=      num_hidden_layers
            lowercase								=      num_attention_heads
            lowercase								=      intermediate_size
            lowercase								=      hidden_act
            lowercase								=      hidden_dropout_prob
            lowercase								=      attention_probs_dropout_prob
            lowercase								=      initializer_range
            lowercase								=      type_vocab_size
            lowercase								=      layer_norm_eps
            lowercase								=      position_embedding_type
            lowercase								=      block_per_row
            lowercase								=      approx_mode
            lowercase								=      initial_prior_first_n_blocks
            lowercase								=      initial_prior_diagonal_n_blocks



