


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


_A      =     logging.get_logger(__name__)

_A      =     {
    """google/pegasus-x-base""": """https://huggingface.co/google/pegasus-x-base/resolve/main/config.json""",
    """google/pegasus-x-large""": """https://huggingface.co/google/pegasus-x-large/resolve/main/config.json""",
    # See all PEGASUS-X models at https://huggingface.co/models?filter=pegasus-x
}






class      SCREAMING_SNAKE_CASE_	( snake_case		):
			__a					:      int					=  '''pegasus_x'''
			__a					:      Dict					=  ['''past_key_values''']
			__a					:      Tuple					=  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}




			def __init__(      self					,      lowercase=9_6_1_0_3					,      lowercase=1_6_3_8_4					,      lowercase=1_6					,      lowercase=4_0_9_6					,      lowercase=1_6					,      lowercase=1_6					,      lowercase=4_0_9_6					,      lowercase=1_6					,      lowercase=0.0					,      lowercase=0.0					,      lowercase=True					,      lowercase=True					,      lowercase="gelu"					,      lowercase=1_0_2_4					,      lowercase=0.1					,      lowercase=0.0					,      lowercase=0.0					,      lowercase=0.0_2					,      lowercase=0					,      lowercase=True					,      lowercase=0					,      lowercase=1					,      lowercase=1					,      lowercase=3_2					,      lowercase=5_1_2					,      lowercase=True					,      **lowercase					,      )			->						Optional[Any]:


								'''simple docstring'''






								__SCREAMING_SNAKE_CASE					:							Optional[int]			   = vocab_size
								__SCREAMING_SNAKE_CASE					:							Dict			   = max_position_embeddings
								__SCREAMING_SNAKE_CASE					:							Optional[Any]			   = d_model
								__SCREAMING_SNAKE_CASE					:							Optional[int]			   = encoder_ffn_dim
								__SCREAMING_SNAKE_CASE					:							int			   = encoder_layers
								__SCREAMING_SNAKE_CASE					:							Optional[int]			   = encoder_attention_heads
								__SCREAMING_SNAKE_CASE					:							List[str]			   = decoder_ffn_dim
								__SCREAMING_SNAKE_CASE					:							Any			   = decoder_layers
								__SCREAMING_SNAKE_CASE					:							Tuple			   = decoder_attention_heads
								__SCREAMING_SNAKE_CASE					:							str			   = dropout
								__SCREAMING_SNAKE_CASE					:							Dict			   = attention_dropout
								__SCREAMING_SNAKE_CASE					:							Optional[int]			   = activation_dropout
								__SCREAMING_SNAKE_CASE					:							List[Any]			   = activation_function
								__SCREAMING_SNAKE_CASE					:							Optional[int]			   = init_std
								__SCREAMING_SNAKE_CASE					:							Union[str, Any]			   = encoder_layerdrop
								__SCREAMING_SNAKE_CASE					:							Any			   = decoder_layerdrop
								__SCREAMING_SNAKE_CASE					:							Optional[Any]			   = use_cache
								__SCREAMING_SNAKE_CASE					:							str			   = encoder_layers
								__SCREAMING_SNAKE_CASE					:							Any			   = scale_embedding  # scale factor will be sqrt(d_model) if True

								__SCREAMING_SNAKE_CASE					:							List[Any]			   = num_global_tokens
								__SCREAMING_SNAKE_CASE					:							List[Any]			   = block_size
								__SCREAMING_SNAKE_CASE					:							Optional[Any]			   = stagger_local_blocks

								super().__init__(
								    pad_token_id=lowercase					,      eos_token_id=lowercase					,      is_encoder_decoder=lowercase					,      decoder_start_token_id=lowercase					,      forced_eos_token_id=lowercase					,      **lowercase					,      )




			@property
			def 			_snake_case   (      self       )			->						int:


								'''simple docstring'''






								return self.encoder_attention_heads




			@property
			def 			_snake_case   (      self       )			->						int:


								'''simple docstring'''






								return self.d_model






'''simple docstring'''






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      SCREAMING_SNAKE_CASE_	( snake_case					,					snake_case					,					unittest.TestCase		):
			__a					:      Dict					=  IFSuperResolutionPipeline
			__a					:      Dict					=  TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
			__a					:      Tuple					=  TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
			__a					:      Tuple					=  PipelineTesterMixin.required_optional_params - {'''latents'''}




			def 			_snake_case   (      self       )			->						Dict:


								'''simple docstring'''






								return self._get_superresolution_dummy_components()




			def 			_snake_case   (      self					,      lowercase					,      lowercase=0       )			->						Union[str, Any]:


								'''simple docstring'''






								if str(lowercase       ).startswith('''mps'''       ):
													__SCREAMING_SNAKE_CASE					:							Optional[int]			   = torch.manual_seed(lowercase       )
								else:
													__SCREAMING_SNAKE_CASE					:							int			   = torch.Generator(device=lowercase       ).manual_seed(lowercase       )

								__SCREAMING_SNAKE_CASE					:							Optional[Any]			   = floats_tensor((1, 3, 3_2, 3_2)					,      rng=random.Random(lowercase       )       ).to(lowercase       )

								__SCREAMING_SNAKE_CASE					:							List[str]			   = {
								    '''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       )			->						List[str]:


								'''simple docstring'''






								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3       )




			def 			_snake_case   (      self       )			->						int:


								'''simple docstring'''






								self._test_save_load_optional_components()




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


								'''simple docstring'''






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




			def 			_snake_case   (      self       )			->						Optional[int]:


								'''simple docstring'''






								self._test_attention_slicing_forward_pass(expected_max_diff=1e-2       )




			def 			_snake_case   (      self       )			->						Optional[int]:


								'''simple docstring'''






								self._test_save_load_local()




			def 			_snake_case   (      self       )			->						List[str]:


								'''simple docstring'''






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


