


"""simple docstring"""


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


     """simple docstring"""
     snake_case__	:					Optional[int]													=IFInpaintingSuperResolutionPipeline
     snake_case__	:					Tuple													=TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'''width''', '''height'''}
     snake_case__	:					Dict													=TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'''original_image'''})
     snake_case__	:					Optional[Any]													=PipelineTesterMixin.required_optional_params - {'''latents'''}

     def 		a__						(	self:						Optional[Any]	)->    Tuple:
           return self._get_superresolution_dummy_components()

     def 		a__						(	self:						List[Any]     ,		__a:						List[Any]     ,		__a:						int=0	)->    List[str]:
           if str(__a	).startswith("""mps"""	):
                 lowerCamelCase					:					List[Any]        =	torch.manual_seed(__a	)
           else:
                 lowerCamelCase					:					Dict        =	torch.Generator(device=__a	).manual_seed(__a	)

           lowerCamelCase					:					Any        =	floats_tensor((1, 3, 16, 16)     ,		rng=random.Random(__a	)	).to(__a	)
           lowerCamelCase					:					Tuple        =	floats_tensor((1, 3, 32, 32)     ,		rng=random.Random(__a	)	).to(__a	)
           lowerCamelCase					:					Union[str, Any]        =	floats_tensor((1, 3, 32, 32)     ,		rng=random.Random(__a	)	).to(__a	)

           lowerCamelCase					:					List[str]        =	{
               """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 		a__						(	self:						Optional[int]	)->    int:
           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)

     def 		a__						(	self:						Any	)->    Tuple:
           self._test_save_load_optional_components()

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

     def 		a__						(	self:						Optional[Any]	)->    int:
           self._test_save_load_local()







     def 		a__						(	self:						Dict	)->    List[str]:
           self._test_inference_batch_single_identical(
               expected_max_diff=1e-2     ,		)








"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__lowerCamelCase      :List[str]	    =		{
    'configuration_owlvit': [
        'OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'OwlViTConfig',
        'OwlViTOnnxConfig',
        'OwlViTTextConfig',
        'OwlViTVisionConfig',
    ],
    'processing_owlvit': ['OwlViTProcessor'],
}


try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase      :Optional[int]	    =		['OwlViTFeatureExtractor']
    __lowerCamelCase      :List[str]	    =		['OwlViTImageProcessor']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase      :Optional[Any]	    =		[
        'OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
        'OwlViTModel',
        'OwlViTPreTrainedModel',
        'OwlViTTextModel',
        'OwlViTVisionModel',
        'OwlViTForObjectDetection',
    ]

if TYPE_CHECKING:
    from .configuration_owlvit import (
        OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
        OwlViTConfig,
        OwlViTOnnxConfig,
        OwlViTTextConfig,
        OwlViTVisionConfig,
    )
    from .processing_owlvit import OwlViTProcessor

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_owlvit import OwlViTFeatureExtractor
        from .image_processing_owlvit import OwlViTImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_owlvit import (
            OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
            OwlViTForObjectDetection,
            OwlViTModel,
            OwlViTPreTrainedModel,
            OwlViTTextModel,
            OwlViTVisionModel,
        )

else:
    import sys

    __lowerCamelCase      :Dict	    =		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




