


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 (							lowercase__							,  lowercase__							,  unittest.TestCase):


       """simple docstring"""




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





       def 						lowerCAmelCase     (   self							:			Tuple       ):


             '''simple docstring'''



             return self._get_superresolution_dummy_components()





       def 						lowerCAmelCase     (   self							:			Union[str, Any]					,      __lowerCamelCase							:			int					,      __lowerCamelCase							:			int=0       ):


             '''simple docstring'''



             if str(__lowerCamelCase       ).startswith("mps"       ):
                   lowerCamelCase__		:				List[Any]    =  torch.manual_seed(__lowerCamelCase       )
             else:
                   lowerCamelCase__		:				List[Any]    =  torch.Generator(device=__lowerCamelCase       ).manual_seed(__lowerCamelCase       )

             lowerCamelCase__		:				Optional[int]    =  floats_tensor((1, 3, 16, 16)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )
             lowerCamelCase__		:				List[Any]    =  floats_tensor((1, 3, 32, 32)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )
             lowerCamelCase__		:				Union[str, Any]    =  floats_tensor((1, 3, 32, 32)					,      rng=random.Random(__lowerCamelCase       )       ).to(__lowerCamelCase       )

             lowerCamelCase__		:				Tuple    =  {
                 "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 						lowerCAmelCase     (   self							:			Optional[Any]       ):


             '''simple docstring'''



             self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3       )





       def 						lowerCAmelCase     (   self							:			Optional[int]       ):


             '''simple docstring'''



             self._test_save_load_optional_components()





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


             '''simple docstring'''



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





       def 						lowerCAmelCase     (   self							:			Union[str, Any]       ):


             '''simple docstring'''



             self._test_attention_slicing_forward_pass(expected_max_diff=1E-2       )





       def 						lowerCAmelCase     (   self							:			Tuple       ):


             '''simple docstring'''



             self._test_save_load_local()





       def 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



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






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


A      :    str		=					logging.get_logger(__name__)

A      :    int		=					{
    "alibaba-damo/mgp-str-base": "https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json",
}







class 			_lowercase (							lowercase__):


       """simple docstring"""




       A__											=			"mgp-str"





       def __init__(   self							:			List[str]					,      __lowerCamelCase							:			List[Any]=[32, 128]					,      __lowerCamelCase							:			Optional[int]=4					,      __lowerCamelCase							:			str=3					,      __lowerCamelCase							:			Optional[Any]=27					,      __lowerCamelCase							:			List[str]=38					,      __lowerCamelCase							:			Dict=50257					,      __lowerCamelCase							:			List[Any]=30522					,      __lowerCamelCase							:			Optional[Any]=768					,      __lowerCamelCase							:			str=12					,      __lowerCamelCase							:			Optional[int]=12					,      __lowerCamelCase							:			List[str]=4.0					,      __lowerCamelCase							:			Union[str, Any]=True					,      __lowerCamelCase							:			Any=False					,      __lowerCamelCase							:			Dict=1E-5					,      __lowerCamelCase							:			int=0.0					,      __lowerCamelCase							:			Optional[int]=0.0					,      __lowerCamelCase							:			List[Any]=0.0					,      __lowerCamelCase							:			Union[str, Any]=False					,      __lowerCamelCase							:			str=0.0_2					,      **__lowerCamelCase							:			Dict					,      ):


             '''simple docstring'''



             super().__init__(**__lowerCamelCase       )

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


