


import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin





@skip_mps
class 							lowercase_					(			a__      ,a__      ,unittest.TestCase):






							"""simple docstring"""







							snake_case_										=		IFInpaintingSuperResolutionPipeline
							snake_case_										=		TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
							snake_case_										=		TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'''original_image'''})
							snake_case_										=		PipelineTesterMixin.required_optional_params - {"""latents"""}


							def     lowercase__  ( self		):







													"""simple docstring"""


													return self._get_superresolution_dummy_components()


							def     lowercase__  ( self      ,     _UpperCAmelCase      ,     _UpperCAmelCase=0		):







													"""simple docstring"""


													if str(__a		).startswith("""mps"""		):
																			a_		      =		torch.manual_seed(__a		)
													else:
																			a_		      =		torch.Generator(device=__a		).manual_seed(__a		)

													a_		      =		floats_tensor((1, 3, 16, 16)      ,     rng=random.Random(__a		)		).to(__a		)
													a_		      =		floats_tensor((1, 3, 32, 32)      ,     rng=random.Random(__a		)		).to(__a		)
													a_		      =		floats_tensor((1, 3, 32, 32)      ,     rng=random.Random(__a		)		).to(__a		)

													a_		      =		{
													    """prompt""": """A painting of a squirrel eating a burger""",
													    """image""": image,
													    """original_image""": original_image,
													    """mask_image""": mask_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     lowercase__  ( self		):







													"""simple docstring"""


													self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3		)


							def     lowercase__  ( self		):







													"""simple docstring"""


													self._test_save_load_optional_components()


							@unittest.skipIf(torch_device != """cuda"""      ,     reason="""float16 requires CUDA"""		)
							def     lowercase__  ( self		):







													"""simple docstring"""


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


							def     lowercase__  ( self		):







													"""simple docstring"""


													self._test_attention_slicing_forward_pass(expected_max_diff=1e-2		)


							def     lowercase__  ( self		):







													"""simple docstring"""


													self._test_save_load_local()






							def     lowercase__  ( self		):







													"""simple docstring"""


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





'''simple docstring'''







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


lowercase      :   Optional[int]      =       logging.get_logger(__name__)

lowercase      :   Optional[Any]      =       {
    """google/pegasus-large""": """https://huggingface.co/google/pegasus-large/resolve/main/config.json""",
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Any          =					"""pegasus"""
     lowerCAmelCase_  :     Dict          =					["""past_key_values"""]
     lowerCAmelCase_  :     str          =					{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}







     def __init__(				self							,__a=50_265							,__a=1_024							,__a=12							,__a=4_096							,__a=16							,__a=12							,__a=4_096							,__a=16							,__a=0.0							,__a=0.0							,__a=True							,__a=True							,__a="gelu"							,__a=1_024							,__a=0.1							,__a=0.0							,__a=0.0							,__a=0.02							,__a=0							,__a=False							,__a=0							,__a=1							,__a=1							,**__a							,)      ->				int:
          snake_case			:      List[Any]        =			vocab_size
          snake_case			:      Optional[Any]        =			max_position_embeddings
          snake_case			:      List[Any]        =			d_model
          snake_case			:      str        =			encoder_ffn_dim
          snake_case			:      List[Any]        =			encoder_layers
          snake_case			:      Optional[Any]        =			encoder_attention_heads
          snake_case			:      Union[str, Any]        =			decoder_ffn_dim
          snake_case			:      Tuple        =			decoder_layers
          snake_case			:      Union[str, Any]        =			decoder_attention_heads
          snake_case			:      Union[str, Any]        =			dropout
          snake_case			:      int        =			attention_dropout
          snake_case			:      int        =			activation_dropout
          snake_case			:      Optional[Any]        =			activation_function
          snake_case			:      Tuple        =			init_std
          snake_case			:      Union[str, Any]        =			encoder_layerdrop
          snake_case			:      int        =			decoder_layerdrop
          snake_case			:      Dict        =			use_cache
          snake_case			:      Dict        =			encoder_layers
          snake_case			:      List[Any]        =			scale_embedding  # scale factor will be sqrt(d_model) if True
          super().__init__(
              pad_token_id=__a							,eos_token_id=__a							,is_encoder_decoder=__a							,decoder_start_token_id=__a							,forced_eos_token_id=__a							,**__a							,)







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.encoder_attention_heads







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.d_model



