




import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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 			_lowerCamelCase    (      _SCREAMING_SNAKE_CASE				,      _SCREAMING_SNAKE_CASE				,      unittest.TestCase ):

      """simple docstring"""

      lowerCAmelCase__      :			Tuple     =       IFSuperResolutionPipeline
      lowerCAmelCase__      :			str     =       TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
      lowerCAmelCase__      :			Optional[int]     =       TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
      lowerCAmelCase__      :			Union[str, Any]     =       PipelineTesterMixin.required_optional_params - {"latents"}







      def    snake_case						(  self       :			Dict					):
          return self._get_superresolution_dummy_components()







      def    snake_case						(  self       :			Any			,							snake_case       :			Dict			,							snake_case       :			Any=0					):
          if str(snake_case					).startswith('''mps'''					):
              __UpperCamelCase			=    torch.manual_seed(snake_case					)
          else:
              __UpperCamelCase			=    torch.Generator(device=snake_case					).manual_seed(snake_case					)

          __UpperCamelCase			=    floats_tensor((1, 3, 32, 32)			,							rng=random.Random(snake_case					)					).to(snake_case					)

          __UpperCamelCase			=    {
              '''prompt''': '''A painting of a squirrel eating a burger''',
              '''image''': 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       :			Dict					):
          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3					)







      def    snake_case						(  self       :			int					):
          self._test_save_load_optional_components()







      @unittest.skipIf(torch_device != '''cuda'''			,							reason='''float16 requires CUDA'''					)
      def    snake_case						(  self       :			List[str]					):
          # 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       :			str					):
          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2					)







      def    snake_case						(  self       :			Tuple					):
          self._test_save_load_local()







      def    snake_case						(  self       :			Optional[Any]					):
          self._test_inference_batch_single_identical(
              expected_max_diff=1E-2			,							)









"""simple docstring"""
from typing import Callable, Optional, Union

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


A									=						logging.get_logger(__name__)

A									=						{
    """microsoft/prophetnet-large-uncased""": (
        """https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json"""
    ),
}

class        _UpperCamelCase	(						lowerCamelCase__	):


  """simple docstring"""





  snake_case_        =    'prophetnet'
  snake_case_        =    ['past_key_values']
  snake_case_        =    {
      'num_attention_heads': 'num_encoder_attention_heads',
  }



  def __init__( self					: Union[str, Any]       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[Union[str, Callable]] = "gelu"       ,       snake_case					: Optional[int] = 3_0522       ,       snake_case					: Optional[int] = 1024       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[int] = 512       ,       snake_case					: Optional[float] = 0.02       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 2       ,       snake_case					: Optional[int] = 32       ,       snake_case					: Optional[int] = 128       ,       snake_case					: Optional[bool] = False       ,       snake_case					: Optional[float] = 0.0       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 1       ,       snake_case					: Optional[int] = 2       ,       **snake_case					: Optional[int]       ,       )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     vocab_size
         __magic_name__			:		Tuple        =     hidden_size
         __magic_name__			:		str        =     encoder_ffn_dim
         __magic_name__			:		Tuple        =     num_encoder_layers
         __magic_name__			:		int        =     num_encoder_attention_heads
         __magic_name__			:		int        =     decoder_ffn_dim
         __magic_name__			:		Optional[int]        =     num_decoder_layers
         __magic_name__			:		str        =     num_decoder_attention_heads
         __magic_name__			:		Optional[Any]        =     max_position_embeddings
         __magic_name__			:		Union[str, Any]        =     init_std  # Normal(0, this parameter)
         __magic_name__			:		Tuple        =     activation_function

         # parameters for prophetnet
         __magic_name__			:		int        =     ngram
         __magic_name__			:		str        =     num_buckets
         __magic_name__			:		Any        =     relative_max_distance
         __magic_name__			:		Optional[int]        =     disable_ngram_loss
         __magic_name__			:		str        =     eps

         # 3 Types of Dropout
         __magic_name__			:		Dict        =     attention_dropout
         __magic_name__			:		Optional[int]        =     activation_dropout
         __magic_name__			:		List[Any]        =     dropout

         __magic_name__			:		str        =     use_cache

         super().__init__(
             pad_token_id=snake_case       ,       bos_token_id=snake_case       ,       eos_token_id=snake_case       ,       is_encoder_decoder=snake_case       ,       add_cross_attention=snake_case       ,       decoder_start_token_id=snake_case       ,       **snake_case       ,       )



  @property
  def 							_UpperCAmelCase      ( self					: str      )	->			int:


         '''simple docstring'''





         return self.num_encoder_layers + self.num_decoder_layers




  @num_hidden_layers.setter
  def 							_UpperCAmelCase      ( self					: Dict       ,       snake_case					: int      )	->			Optional[int]:


         '''simple docstring'''





         raise NotImplementedError(
             '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
             ''' `num_decoder_layers`.'''      )
