






import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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 							__snake_case(       __UpperCAmelCase  ,							__UpperCAmelCase  ,							unittest.TestCase   ):
 lowercase			:							List[str]		   =		IFImgaImgPipeline
 lowercase			:							Dict		   =		TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
 lowercase			:							List[Any]		   =		TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
 lowercase			:							Union[str, Any]		   =		PipelineTesterMixin.required_optional_params - {'''latents'''}



 def     UpperCAmelCase     (						self : Tuple						):

    """simple docstring"""






    return self._get_dummy_components()



 def     UpperCAmelCase     (						self : List[str]			,		UpperCAmelCase__ : Dict			,		UpperCAmelCase__ : List[Any]=0						):

    """simple docstring"""






    if str(UpperCAmelCase__						).startswith("""mps"""						):
       lowercase__    :						Optional[Any]       =			torch.manual_seed(UpperCAmelCase__						)
    else:
       lowercase__    :						Dict       =			torch.Generator(device=UpperCAmelCase__						).manual_seed(UpperCAmelCase__						)

    lowercase__    :						Dict       =			floats_tensor((1, 3, 32, 32)			,		rng=random.Random(UpperCAmelCase__						)						).to(UpperCAmelCase__						)

    lowercase__    :						Dict       =			{
        """prompt""": """A painting of a squirrel eating a burger""",
        """image""": image,
        """generator""": generator,
        """num_inference_steps""": 2,
        """output_type""": """numpy""",
    }

    return inputs



 def     UpperCAmelCase     (						self : List[Any]						):

    """simple docstring"""






    self._test_save_load_optional_components()



 @unittest.skipIf(
     torch_device != """cuda""" or not is_xformers_available()			,		reason="""XFormers attention is only available with CUDA and `xformers` installed"""			,		)
 def     UpperCAmelCase     (						self : Any						):

    """simple docstring"""






    self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3						)



 @unittest.skipIf(torch_device != """cuda"""			,		reason="""float16 requires CUDA"""						)
 def     UpperCAmelCase     (						self : Optional[int]						):

    """simple docstring"""






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



 @unittest.skipIf(torch_device != """cuda"""			,		reason="""float16 requires CUDA"""						)
 def     UpperCAmelCase     (						self : str						):

    """simple docstring"""






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



 def     UpperCAmelCase     (						self : Union[str, Any]						):

    """simple docstring"""






    self._test_attention_slicing_forward_pass(expected_max_diff=1e-2						)



 def     UpperCAmelCase     (						self : List[Any]						):

    """simple docstring"""






    self._test_save_load_local()







 def     UpperCAmelCase     (						self : Union[str, Any]						):

    """simple docstring"""






    self._test_inference_batch_single_identical(
        expected_max_diff=1e-2			,		)









import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
       from PIL import Image

class 			__A(    unittest.TestCase    ,      __UpperCAmelCase			):

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    load_tool('''image-question-answering'''   )
            self.tool.setup()
            _UpperCamelCase														=    load_tool('''image-question-answering''',							remote=A   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.tool(A,							'''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.remote_tool(A,							'''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.tool(image=A,							question='''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )



     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''   )   ) / '''000000039769.png'''   )
            _UpperCamelCase														=    self.remote_tool(image=A,							question='''How many cats are sleeping on the couch?'''   )
            self.assertEqual(A,							'''2'''   )






