


'''simple docstring'''

import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


a_  :    List[Any]      =			False





@nightly
@require_torch_gpu
class 					snake_case   (   unittest.TestCase      ):





		"""simple docstring"""




		def   snake_case		(   self					):







			"""simple docstring"""
			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()






		def   snake_case		(   self					):







			"""simple docstring"""
			lowerCamelCase_								=  VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"					)
			# remove text_unet
			pipe.remove_unused_weights()
			pipe.to(__lowerCAmelCase					)
			pipe.set_progress_bar_config(disable=__lowerCAmelCase					)

			lowerCamelCase_								=  load_image(
			    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"					)

			lowerCamelCase_								=  torch.manual_seed(0					)
			lowerCamelCase_								=  pipe(
			    prompt="first prompt"      ,  image=__lowerCAmelCase      ,  text_to_image_strength=0.75      ,  generator=__lowerCAmelCase      ,  guidance_scale=7.5      ,  num_inference_steps=2      ,  output_type="numpy"      ,  ).images

			with tempfile.TemporaryDirectory() as tmpdirname:
				pipe.save_pretrained(__lowerCAmelCase					)
				lowerCamelCase_								=  VersatileDiffusionDualGuidedPipeline.from_pretrained(__lowerCAmelCase					)

			pipe.to(__lowerCAmelCase					)
			pipe.set_progress_bar_config(disable=__lowerCAmelCase					)

			lowerCamelCase_								=  generator.manual_seed(0					)
			lowerCamelCase_								=  pipe(
			    prompt="first prompt"      ,  image=__lowerCAmelCase      ,  text_to_image_strength=0.75      ,  generator=__lowerCAmelCase      ,  guidance_scale=7.5      ,  num_inference_steps=2      ,  output_type="numpy"      ,  ).images

			assert np.abs(image - new_image					).sum() < 1e-5, "Models don't have the same forward pass"







		def   snake_case		(   self					):







			"""simple docstring"""
			lowerCamelCase_								=  VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"					)
			pipe.remove_unused_weights()
			pipe.to(__lowerCAmelCase					)
			pipe.set_progress_bar_config(disable=__lowerCAmelCase					)

			lowerCamelCase_								=  "cyberpunk 2077"
			lowerCamelCase_								=  load_image(
			    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"					)
			lowerCamelCase_								=  torch.manual_seed(0					)
			lowerCamelCase_								=  pipe(
			    prompt=__lowerCAmelCase      ,  image=__lowerCAmelCase      ,  text_to_image_strength=0.75      ,  generator=__lowerCAmelCase      ,  guidance_scale=7.5      ,  num_inference_steps=50      ,  output_type="numpy"      ,  ).images

			lowerCamelCase_								=  image[0, 253:256, 253:256, -1]

			assert image.shape == (1, 512, 512, 3)
			lowerCamelCase_								=  np.array([0.0_787, 0.0_849, 0.0_826, 0.0_812, 0.0_807, 0.0_795, 0.0_818, 0.0_798, 0.0_779]					)

			assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2







'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a_  :    Optional[Any]      =			logging.get_logger(__name__)

a_  :    Tuple      =			{
    """google/electra-small-generator""": """https://huggingface.co/google/electra-small-generator/resolve/main/config.json""",
    """google/electra-base-generator""": """https://huggingface.co/google/electra-base-generator/resolve/main/config.json""",
    """google/electra-large-generator""": """https://huggingface.co/google/electra-large-generator/resolve/main/config.json""",
    """google/electra-small-discriminator""": (
        """https://huggingface.co/google/electra-small-discriminator/resolve/main/config.json"""
    ),
    """google/electra-base-discriminator""": (
        """https://huggingface.co/google/electra-base-discriminator/resolve/main/config.json"""
    ),
    """google/electra-large-discriminator""": (
        """https://huggingface.co/google/electra-large-discriminator/resolve/main/config.json"""
    ),
}





class 					snake_case   (   lowercase      ):





  """simple docstring"""




  _lowerCamelCase		   =  "electra"






  def __init__(   self      ,  UpperCamelCase=3_0522      ,  UpperCamelCase=128      ,  UpperCamelCase=256      ,  UpperCamelCase=12      ,  UpperCamelCase=4      ,  UpperCamelCase=1024      ,  UpperCamelCase="gelu"      ,  UpperCamelCase=0.1      ,  UpperCamelCase=0.1      ,  UpperCamelCase=512      ,  UpperCamelCase=2      ,  UpperCamelCase=0.02      ,  UpperCamelCase=1e-12      ,  UpperCamelCase="first"      ,  UpperCamelCase=True      ,  UpperCamelCase="gelu"      ,  UpperCamelCase=0.1      ,  UpperCamelCase=0      ,  UpperCamelCase="absolute"      ,  UpperCamelCase=True      ,  UpperCamelCase=None      ,  **UpperCamelCase      ,  ):







   """simple docstring"""
   super().__init__(pad_token_id=UpperCamelCase      ,  **UpperCamelCase					)

   lowerCamelCase_								=  vocab_size
   lowerCamelCase_								=  embedding_size
   lowerCamelCase_								=  hidden_size
   lowerCamelCase_								=  num_hidden_layers
   lowerCamelCase_								=  num_attention_heads
   lowerCamelCase_								=  intermediate_size
   lowerCamelCase_								=  hidden_act
   lowerCamelCase_								=  hidden_dropout_prob
   lowerCamelCase_								=  attention_probs_dropout_prob
   lowerCamelCase_								=  max_position_embeddings
   lowerCamelCase_								=  type_vocab_size
   lowerCamelCase_								=  initializer_range
   lowerCamelCase_								=  layer_norm_eps

   lowerCamelCase_								=  summary_type
   lowerCamelCase_								=  summary_use_proj
   lowerCamelCase_								=  summary_activation
   lowerCamelCase_								=  summary_last_dropout
   lowerCamelCase_								=  position_embedding_type
   lowerCamelCase_								=  use_cache
   lowerCamelCase_								=  classifier_dropout





class 					snake_case   (   lowercase      ):





  """simple docstring"""




  @property
  def   snake_case		(   self					):







   """simple docstring"""
   if self.task == "multiple-choice":
    lowerCamelCase_								=  {0: "batch", 1: "choice", 2: "sequence"}
   else:
    lowerCamelCase_								=  {0: "batch", 1: "sequence"}
   return OrderedDict(
       [
           ("input_ids", dynamic_axis),
           ("attention_mask", dynamic_axis),
           ("token_type_ids", dynamic_axis),
       ]					)



