




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'''



    lowerCamelCase_				:     Dict     					=				IFSuperResolutionPipeline
    lowerCamelCase_				:     int     					=				TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
    lowerCamelCase_				:     Tuple     					=				TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
    lowerCamelCase_				:     int     					=				PipelineTesterMixin.required_optional_params - {"""latents"""}







    def    _lowercase					(   self					)					->				Dict:
           return self._get_superresolution_dummy_components()







    def    _lowercase					(   self					,  UpperCamelCase__					,  UpperCamelCase__=0					)					->				Union[str, Any]:
           if str(UpperCamelCase__					).startswith("mps"					):
                  lowerCamelCase       :				List[str]      			= torch.manual_seed(UpperCamelCase__					)
           else:
                  lowerCamelCase       :				Any      			= torch.Generator(device=UpperCamelCase__					).manual_seed(UpperCamelCase__					)

           lowerCamelCase       :				str      			= floats_tensor((1, 3, 32, 32)					,  rng=random.Random(UpperCamelCase__					)					).to(UpperCamelCase__					)

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







    def    _lowercase					(   self					)					->				Dict:
           self._test_save_load_optional_components()







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







    def    _lowercase					(   self					)					->				int:
           self._test_save_load_local()







    def    _lowercase					(   self					)					->				Dict:
           self._test_inference_batch_single_identical(
               expected_max_diff=1e-2					,  )












from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


SCREAMING_SNAKE_CASE__	:				Dict  =       {
    'configuration_oneformer': ['ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OneFormerConfig'],
    'processing_oneformer': ['OneFormerProcessor'],
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       SCREAMING_SNAKE_CASE__	:				Optional[Any]  =       ['OneFormerImageProcessor']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       SCREAMING_SNAKE_CASE__	:				Optional[int]  =       [
           'ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
           'OneFormerForUniversalSegmentation',
           'OneFormerModel',
           'OneFormerPreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_oneformer import ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, OneFormerConfig
       from .processing_oneformer import OneFormerProcessor

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_oneformer import OneFormerImageProcessor
       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_oneformer import (
                  ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  OneFormerForUniversalSegmentation,
                  OneFormerModel,
                  OneFormerPreTrainedModel,
              )


else:
       import sys

       SCREAMING_SNAKE_CASE__	:				str  =       _LazyModule(__name__, globals()['__file__'], _import_structure)






