


'''simple docstring'''
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 					__lowerCAmelCase   (   snake_case__				,			snake_case__				,			unittest.TestCase						):

						"""simple docstring"""






						_UpperCAmelCase		:       Optional[int]   						=IFImgaImgSuperResolutionPipeline
						_UpperCAmelCase		:       List[Any]   						=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
						_UpperCAmelCase		:       int   						=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"original_image"}						)
						_UpperCAmelCase		:       Any   						=PipelineTesterMixin.required_optional_params - {'latents'}






						def 				_UpperCAmelCase       (  self							:      List[str]	):
													return self._get_superresolution_dummy_components()






						def 				_UpperCAmelCase       (  self							:      List[Any] ,  lowerCAmelCase							:      List[Any] ,  lowerCAmelCase							:      str=0	):
													if str(lowerCAmelCase	).startswith("mps"	):
																				A_			    =		torch.manual_seed(lowerCAmelCase	)
													else:
																				A_			    =		torch.Generator(device=lowerCAmelCase	).manual_seed(lowerCAmelCase	)

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

													A_			    =		{
													    '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							:      Union[str, Any]	):
													self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)






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






						@unittest.skipIf(torch_device != "cuda" ,  reason="float16 requires CUDA"	)
						def 				_UpperCAmelCase       (  self							:      Optional[int]	):
													# 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 				_UpperCAmelCase       (  self							:      Tuple	):
													self._test_attention_slicing_forward_pass(expected_max_diff=1e-2	)






						def 				_UpperCAmelCase       (  self							:      Optional[int]	):
													self._test_save_load_local()






						def 				_UpperCAmelCase       (  self							:      Tuple	):
													self._test_inference_batch_single_identical(
													    expected_max_diff=1e-2 ,  )












import os
import sys

_lowercase		:  List[str]			       =os.path.join(os.path.dirname(__file__), """src""")
sys.path.append(SRC_DIR)


from transformers import (
    AutoConfig,
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForMaskedLM,
    AutoModelForQuestionAnswering,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    add_start_docstrings,
)


_lowercase		:  Optional[int]			       =[
    """torch""",
    """numpy""",
    """tokenizers""",
    """filelock""",
    """requests""",
    """tqdm""",
    """regex""",
    """sentencepiece""",
    """sacremoses""",
    """importlib_metadata""",
    """huggingface_hub""",
]


@add_start_docstrings(AutoConfig.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoConfig.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoTokenizer.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoTokenizer.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModel.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModel.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForCausalLM.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForCausalLM.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForMaskedLM.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForMaskedLM.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForSequenceClassification.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForSequenceClassification.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)





@add_start_docstrings(AutoModelForQuestionAnswering.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForQuestionAnswering.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)
