


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      (				lowerCamelCase_				,		lowerCamelCase_				,		unittest.TestCase ):


				"""simple docstring"""







				a_:		Dict					      =	IFSuperResolutionPipeline
				a_:		Optional[int]					      =	TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
				a_:		Dict					      =	TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
				a_:		Optional[int]					      =	PipelineTesterMixin.required_optional_params - {"""latents"""}






				def        lowerCAmelCase__			(				self     :    Optional[int]					):
								return self._get_superresolution_dummy_components()






				def        lowerCAmelCase__			(				self     :    List[str]	,							lowerCamelCase_     :    Optional[int]	,							lowerCamelCase_     :    Optional[int]=0					):
								if str(lowerCamelCase_					).startswith("""mps"""					):
												_lowerCAmelCase  						=torch.manual_seed(lowerCamelCase_					)
								else:
												_lowerCAmelCase  						=torch.Generator(device=lowerCamelCase_					).manual_seed(lowerCamelCase_					)

								_lowerCAmelCase  						=floats_tensor((1, 3, 32, 32)	,							rng=random.Random(lowerCamelCase_					)					).to(lowerCamelCase_					)

								_lowerCAmelCase  						={
								    """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        lowerCAmelCase__			(				self     :    Dict					):
								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3					)






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






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






				def        lowerCAmelCase__			(				self     :    Optional[Any]					):
								self._test_save_load_local()






				def        lowerCAmelCase__			(				self     :    Optional[int]					):
								self._test_inference_batch_single_identical(
								    expected_max_diff=1e-2	,							)





from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_torch_available


__SCREAMING_SNAKE_CASE	:							str           =  {
    '''configuration_ernie_m''': ['''ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ErnieMConfig'''],
}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__SCREAMING_SNAKE_CASE	:							Any           =  ['''ErnieMTokenizer''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__SCREAMING_SNAKE_CASE	:							Tuple           =  [
		    '''ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ErnieMForMultipleChoice''',
		    '''ErnieMForQuestionAnswering''',
		    '''ErnieMForSequenceClassification''',
		    '''ErnieMForTokenClassification''',
		    '''ErnieMModel''',
		    '''ErnieMPreTrainedModel''',
		    '''ErnieMForInformationExtraction''',
		]


if TYPE_CHECKING:
		from .configuration_ernie_m import ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieMConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_ernie_m import ErnieMTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_ernie_m import (
				    ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ErnieMForInformationExtraction,
				    ErnieMForMultipleChoice,
				    ErnieMForQuestionAnswering,
				    ErnieMForSequenceClassification,
				    ErnieMForTokenClassification,
				    ErnieMModel,
				    ErnieMPreTrainedModel,
				)


else:
		import sys

		__SCREAMING_SNAKE_CASE	:							str           =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

