





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     __SCREAMING_SNAKE_CASE   (       lowerCamelCase__				,						lowerCamelCase__				,						unittest.TestCase    ):
							snake_case       : List[Any]         =    IFInpaintingSuperResolutionPipeline
							snake_case       : Tuple         =    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
							snake_case       : Optional[int]         =    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}    )
							snake_case       : Union[str, Any]         =    PipelineTesterMixin.required_optional_params - {"""latents"""}






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






							def 			_lowerCamelCase						(  self					,	__lowerCAmelCase					,	__lowerCAmelCase=0					):






														if str(__lowerCamelCase					).startswith("""mps"""					):
																					UpperCamelCase__			       =     torch.manual_seed(__lowerCamelCase					)
														else:
																					UpperCamelCase__			       =     torch.Generator(device=__lowerCamelCase					).manual_seed(__lowerCamelCase					)

														UpperCamelCase__			       =     floats_tensor((1, 3, 16, 16)					,	rng=random.Random(__lowerCamelCase					)					).to(__lowerCamelCase					)
														UpperCamelCase__			       =     floats_tensor((1, 3, 32, 32)					,	rng=random.Random(__lowerCamelCase					)					).to(__lowerCamelCase					)
														UpperCamelCase__			       =     floats_tensor((1, 3, 32, 32)					,	rng=random.Random(__lowerCamelCase					)					).to(__lowerCamelCase					)

														UpperCamelCase__			       =     {
														    '''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 			_lowerCamelCase						(  self					):
														self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3					)






							def 			_lowerCamelCase						(  self					):
														self._test_save_load_optional_components()






							@unittest.skipIf(torch_device != """cuda"""					,	reason="""float16 requires CUDA"""					)
							def 			_lowerCamelCase						(  self					):
														super().test_save_load_floataa(expected_max_diff=1E-1					)






							def 			_lowerCamelCase						(  self					):
														self._test_attention_slicing_forward_pass(expected_max_diff=1E-2					)






							def 			_lowerCamelCase						(  self					):
														self._test_save_load_local()







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











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


UpperCamelCase__     =	logging.get_logger(__name__)

UpperCamelCase__     =	{
    "facebook/s2t-wav2vec2-large-en-de": (
        "https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}

class     __SCREAMING_SNAKE_CASE   (       _a    ):
							snake_case       : Dict         =    """speech_to_text_2"""
							snake_case       : List[Any]         =    ["""past_key_values"""]
							snake_case       : List[str]         =    {"""num_attention_heads""": """decoder_attention_heads""", """hidden_size""": """d_model"""}






							def __init__(  self					,	__lowerCAmelCase=10000					,	__lowerCAmelCase=6					,	__lowerCAmelCase=2048					,	__lowerCAmelCase=4					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=True					,	__lowerCAmelCase="relu"					,	__lowerCAmelCase=256					,	__lowerCAmelCase=0.1					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=0.0					,	__lowerCAmelCase=0.02					,	__lowerCAmelCase=2					,	__lowerCAmelCase=True					,	__lowerCAmelCase=1					,	__lowerCAmelCase=0					,	__lowerCAmelCase=2					,	__lowerCAmelCase=1024					,	**__lowerCAmelCase					,	):
														UpperCamelCase__			       =     vocab_size
														UpperCamelCase__			       =     d_model
														UpperCamelCase__			       =     decoder_ffn_dim
														UpperCamelCase__			       =     decoder_layers
														UpperCamelCase__			       =     decoder_attention_heads
														UpperCamelCase__			       =     dropout
														UpperCamelCase__			       =     attention_dropout
														UpperCamelCase__			       =     activation_dropout
														UpperCamelCase__			       =     activation_function
														UpperCamelCase__			       =     init_std
														UpperCamelCase__			       =     decoder_layerdrop
														UpperCamelCase__			       =     use_cache
														UpperCamelCase__			       =     decoder_layers
														UpperCamelCase__			       =     scale_embedding  # scale factor will be sqrt(d_model) if True
														UpperCamelCase__			       =     max_target_positions

														super().__init__(
														    pad_token_id=__lowerCAmelCase					,	bos_token_id=__lowerCAmelCase					,	eos_token_id=__lowerCAmelCase					,	decoder_start_token_id=__lowerCAmelCase					,	**__lowerCAmelCase					,	)




