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


_lowercase											=    logging.get_logger(__name__)

_lowercase											=    {
    "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 			lowercase_		(      A       ):
       __lowerCamelCase				       =						"realm"


       def __init__(    self						,       __A=30_522						,       __A=768						,       __A=128						,       __A=12						,       __A=12						,       __A=8						,       __A=3_072						,       __A="gelu_new"						,       __A=0.1						,       __A=0.1						,       __A=512						,       __A=2						,       __A=0.02						,       __A=1e-1_2						,       __A=256						,       __A=10						,       __A=1e-3						,       __A=5						,       __A=320						,       __A=13_353_718						,       __A=5_000						,       __A=1						,       __A=0						,       __A=2						,       **__A						,       )						->    Union[str, Any]:
              super().__init__(pad_token_id=__A						,       bos_token_id=__A						,       eos_token_id=__A						,       **__A				)

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

              # Reader config
              SCREAMING_SNAKE_CASE_							:				str		=span_hidden_size
              SCREAMING_SNAKE_CASE_							:				Optional[Any]		=max_span_width
              SCREAMING_SNAKE_CASE_							:				int		=reader_layer_norm_eps
              SCREAMING_SNAKE_CASE_							:				List[str]		=reader_beam_size
              SCREAMING_SNAKE_CASE_							:				int		=reader_seq_len

              # Retrieval config
              SCREAMING_SNAKE_CASE_							:				Optional[int]		=num_block_records
              SCREAMING_SNAKE_CASE_							:				List[Any]		=searcher_beam_size





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

   '''simple docstring'''




   A     :	str												=     IFImgaImgSuperResolutionPipeline
   A     :	Dict												=     TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
   A     :	Any												=     TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"original_image"}						)
   A     :	str												=     PipelineTesterMixin.required_optional_params - {"latents"}


   def       UpperCAmelCase		(    self	:      Dict)						->					Dict:




         """simple docstring"""

         return self._get_superresolution_dummy_components()


   def       UpperCAmelCase		(    self	:      Optional[Any]      ,					lowerCAmelCase	:      Tuple      ,					lowerCAmelCase	:      Union[str, Any]=0)						->					str:




         """simple docstring"""

         if str(lowerCAmelCase).startswith('mps'):
               lowercase__  =	torch.manual_seed(lowerCAmelCase)
         else:
               lowercase__  =	torch.Generator(device=lowerCAmelCase).manual_seed(lowerCAmelCase)

         lowercase__  =	floats_tensor((1, 3, 32, 32)      ,					rng=random.Random(lowerCAmelCase)).to(lowerCAmelCase)
         lowercase__  =	floats_tensor((1, 3, 16, 16)      ,					rng=random.Random(lowerCAmelCase)).to(lowerCAmelCase)

         lowercase__  =	{
             '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       UpperCAmelCase		(    self	:      str)						->					Dict:




         """simple docstring"""

         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3)


   def       UpperCAmelCase		(    self	:      List[Any])						->					Dict:




         """simple docstring"""

         self._test_save_load_optional_components()


   @unittest.skipIf(torch_device != 'cuda'      ,					reason='float16 requires CUDA')
   def       UpperCAmelCase		(    self	:      Optional[Any])						->					List[Any]:




         """simple docstring"""

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


   def       UpperCAmelCase		(    self	:      str)						->					Union[str, Any]:




         """simple docstring"""

         self._test_attention_slicing_forward_pass(expected_max_diff=1E-2)


   def       UpperCAmelCase		(    self	:      Tuple)						->					Tuple:




         """simple docstring"""

         self._test_save_load_local()



   def       UpperCAmelCase		(    self	:      List[str])						->					Tuple:




         """simple docstring"""

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