'''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   UpperCamelCase					(       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    SCREAMING_SNAKE_CASE_     (					self     :						Optional[int]):


         """simple docstring"""







         return self._get_superresolution_dummy_components()





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[str]							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Optional[int]=0):


         """simple docstring"""







         if str(lowerCamelCase_).startswith('mps'):
              a					:							int							= torch.manual_seed(lowerCamelCase_)
         else:
              a					:							Any							= torch.Generator(device=lowerCamelCase_).manual_seed(lowerCamelCase_)

         a					:							int							= floats_tensor((1, 3, 3_2, 3_2)							,							rng=random.Random(lowerCamelCase_)).to(lowerCamelCase_)

         a					:							Dict							= {
             '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    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3)





    def    SCREAMING_SNAKE_CASE_     (					self     :						int):


         """simple docstring"""







         self._test_save_load_optional_components()





    @unittest.skipIf(torch_device != 'cuda'							,							reason='float16 requires CUDA')
    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]):


         """simple docstring"""







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





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]):


         """simple docstring"""







         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]):


         """simple docstring"""







         self._test_save_load_local()







    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[int]):


         """simple docstring"""







         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__)

