



"""simple docstring"""
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 			snake_case_						(						a_     ,a_     ,unittest.TestCase				):
       __lowerCAmelCase    					=					IFInpaintingSuperResolutionPipeline
       __lowerCAmelCase    					=					TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
       __lowerCAmelCase    					=					TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"original_image"}				)
       __lowerCAmelCase    					=					PipelineTesterMixin.required_optional_params - {"latents"}






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






       def snake_case_  (   self			,     a_			,     a_=0      ):
         if str(a_      ).startswith("mps"      ):
           a_     :      int 						=     torch.manual_seed(a_      )
         else:
           a_     :      Optional[Any] 						=     torch.Generator(device=a_      ).manual_seed(a_      )

         a_     :      Optional[Any] 						=     floats_tensor((1, 3, 1_6, 1_6)			,     rng=random.Random(a_      )      ).to(a_      )
         a_     :      Any 						=     floats_tensor((1, 3, 3_2, 3_2)			,     rng=random.Random(a_      )      ).to(a_      )
         a_     :      Optional[int] 						=     floats_tensor((1, 3, 3_2, 3_2)			,     rng=random.Random(a_      )      ).to(a_      )

         a_     :      str 						=     {
             "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 snake_case_  (   self      ):
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )






       def snake_case_  (   self      ):
         self._test_save_load_optional_components()






       @unittest.skipIf(torch_device != "cuda"			,     reason="float16 requires CUDA"      )
       def snake_case_  (   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 snake_case_  (   self      ):
         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )






       def snake_case_  (   self      ):
         self._test_save_load_local()






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




"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_				= logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_				= {
    """google/realm-cc-news-pretrained-embedder""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-encoder""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-scorer""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-openqa""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"""
    ),
    """google/realm-orqa-nq-openqa""": """https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json""",
    """google/realm-orqa-nq-reader""": """https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json""",
    """google/realm-orqa-wq-openqa""": """https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json""",
    """google/realm-orqa-wq-reader""": """https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json""",
    # See all REALM models at https://huggingface.co/models?filter=realm
}




class 			snake_case_						(						a_				):
							__lowerCAmelCase    					=					"realm"






							def __init__(   self			,     a_=3_0_5_2_2			,     a_=7_6_8			,     a_=1_2_8			,     a_=1_2			,     a_=1_2			,     a_=8			,     a_=3_0_7_2			,     a_="gelu_new"			,     a_=0.1			,     a_=0.1			,     a_=5_1_2			,     a_=2			,     a_=0.02			,     a_=1e-12			,     a_=2_5_6			,     a_=1_0			,     a_=1e-3			,     a_=5			,     a_=3_2_0			,     a_=1_3_3_5_3_7_1_8			,     a_=5_0_0_0			,     a_=1			,     a_=0			,     a_=2			,     **a_			,     ):
									super().__init__(pad_token_id=a_			,     bos_token_id=a_			,     eos_token_id=a_			,     **a_      )

									# Common config
									a_     :      Optional[int] 						=     vocab_size
									a_     :      List[Any] 						=     max_position_embeddings
									a_     :      Optional[Any] 						=     hidden_size
									a_     :      Optional[Any] 						=     retriever_proj_size
									a_     :      List[str] 						=     num_hidden_layers
									a_     :      List[Any] 						=     num_attention_heads
									a_     :      Tuple 						=     num_candidates
									a_     :      str 						=     intermediate_size
									a_     :      Optional[int] 						=     hidden_act
									a_     :      List[str] 						=     hidden_dropout_prob
									a_     :      List[str] 						=     attention_probs_dropout_prob
									a_     :      Tuple 						=     initializer_range
									a_     :      Tuple 						=     type_vocab_size
									a_     :      str 						=     layer_norm_eps

									# Reader config
									a_     :      str 						=     span_hidden_size
									a_     :      Union[str, Any] 						=     max_span_width
									a_     :      Tuple 						=     reader_layer_norm_eps
									a_     :      List[Any] 						=     reader_beam_size
									a_     :      str 						=     reader_seq_len

									# Retrieval config
									a_     :      str 						=     num_block_records
									a_     :      int 						=     searcher_beam_size