


'''simple docstring'''







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






						'''simple docstring'''







						__snake_case   =      IFImgaImgPipeline
						__snake_case   =      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
						__snake_case   =      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
						__snake_case   =      PipelineTesterMixin.required_optional_params - {"latents"}







						def lowerCAmelCase__ (  self:	Tuple     )							->	Optional[int]:
										return self._get_dummy_components()







						def lowerCAmelCase__ (  self:	Any      ,							__UpperCamelCase:	Union[str, Any]      ,							__UpperCamelCase:	Any=0     )							->	int:
										if str(__UpperCamelCase     ).startswith("mps"     ):
														__magic_name__				:					Optional[Any]						       =       torch.manual_seed(__UpperCamelCase     )
										else:
														__magic_name__				:					Union[str, Any]						       =       torch.Generator(device=__UpperCamelCase     ).manual_seed(__UpperCamelCase     )

										__magic_name__				:					Dict						       =       floats_tensor((1, 3, 32, 32)      ,							rng=random.Random(__UpperCamelCase     )     ).to(__UpperCamelCase     )

										__magic_name__				:					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







						def lowerCAmelCase__ (  self:	Dict     )							->	Optional[Any]:
										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 lowerCAmelCase__ (  self:	Tuple     )							->	Optional[Any]:
										self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3     )







						@unittest.skipIf(torch_device != "cuda"      ,							reason="float16 requires CUDA"     )
						def lowerCAmelCase__ (  self:	int     )							->	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     )







						@unittest.skipIf(torch_device != "cuda"      ,							reason="float16 requires CUDA"     )
						def lowerCAmelCase__ (  self:	Dict     )							->	int:
										super().test_floataa_inference(expected_max_diff=1E-1     )







						def lowerCAmelCase__ (  self:	Any     )							->	Dict:
										self._test_attention_slicing_forward_pass(expected_max_diff=1E-2     )







						def lowerCAmelCase__ (  self:	Tuple     )							->	int:
										self._test_save_load_local()







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



'''simple docstring'''







import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput






@dataclass
class 		_snake_case    (				snake_case_		):






						'''simple docstring'''







						__snake_case   =      42
						__snake_case   =      None
						__snake_case   =      None






class 		_snake_case    (				unittest.TestCase		):






						'''simple docstring'''







						def lowerCAmelCase__ (  self:	List[str]     )							->	str:
										__magic_name__				:					List[Any]						       =       ModelOutputTest(a=30     )
										self.assertEqual(x.a      ,							30     )
										self.assertIsNone(x.b     )
										self.assertIsNone(x.c     )
										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					Optional[int]						       =       x.d







						def lowerCAmelCase__ (  self:	Dict     )							->	Dict:
										__magic_name__				:					List[Any]						       =       ModelOutputTest(a=30      ,							b=10     )
										self.assertEqual(x[0]      ,							30     )
										self.assertEqual(x[1]      ,							10     )
										self.assertEqual(x[:2]      ,							(30, 10)     )
										self.assertEqual(x[:]      ,							(30, 10)     )

										__magic_name__				:					str						       =       ModelOutputTest(a=30      ,							c=10     )
										self.assertEqual(x[0]      ,							30     )
										self.assertEqual(x[1]      ,							10     )
										self.assertEqual(x[:2]      ,							(30, 10)     )
										self.assertEqual(x[:]      ,							(30, 10)     )







						def lowerCAmelCase__ (  self:	List[Any]     )							->	Optional[int]:
										__magic_name__				:					Optional[Any]						       =       ModelOutputTest(a=30      ,							b=10     )
										self.assertEqual(x["a"]      ,							30     )
										self.assertEqual(x["b"]      ,							10     )
										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					str						       =       x["c"]

										__magic_name__				:					Optional[Any]						       =       ModelOutputTest(a=30      ,							c=10     )
										self.assertEqual(x["a"]      ,							30     )
										self.assertEqual(x["c"]      ,							10     )
										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					Union[str, Any]						       =       x["b"]







						def lowerCAmelCase__ (  self:	Optional[Any]     )							->	Any:
										__magic_name__				:					Any						       =       ModelOutputTest(a=30     )
										self.assertEqual(list(x.keys()     )      ,							["a"]     )
										self.assertEqual(list(x.values()     )      ,							[30]     )
										self.assertEqual(list(x.items()     )      ,							[("a", 30)]     )
										self.assertEqual(list(__UpperCamelCase     )      ,							["a"]     )

										__magic_name__				:					Dict						       =       ModelOutputTest(a=30      ,							b=10     )
										self.assertEqual(list(x.keys()     )      ,							["a", "b"]     )
										self.assertEqual(list(x.values()     )      ,							[30, 10]     )
										self.assertEqual(list(x.items()     )      ,							[("a", 30), ("b", 10)]     )
										self.assertEqual(list(__UpperCamelCase     )      ,							["a", "b"]     )

										__magic_name__				:					int						       =       ModelOutputTest(a=30      ,							c=10     )
										self.assertEqual(list(x.keys()     )      ,							["a", "c"]     )
										self.assertEqual(list(x.values()     )      ,							[30, 10]     )
										self.assertEqual(list(x.items()     )      ,							[("a", 30), ("c", 10)]     )
										self.assertEqual(list(__UpperCamelCase     )      ,							["a", "c"]     )

										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					str						       =       x.update({"d": 20}     )
										with self.assertRaises(__UpperCamelCase     ):
														del x["a"]
										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					List[str]						       =       x.pop("a"     )
										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					Optional[Any]						       =       x.setdefault("d"      ,							32     )







						def lowerCAmelCase__ (  self:	Dict     )							->	int:
										__magic_name__				:					Any						       =       ModelOutputTest(a=30     )
										__magic_name__				:					Tuple						       =       10
										self.assertEqual(x.a      ,							10     )
										self.assertEqual(x["a"]      ,							10     )







						def lowerCAmelCase__ (  self:	Dict     )							->	Union[str, Any]:
										__magic_name__				:					Tuple						       =       ModelOutputTest(a=30     )
										__magic_name__				:					Union[str, Any]						       =       10
										self.assertEqual(x.a      ,							10     )
										self.assertEqual(x["a"]      ,							10     )







						def lowerCAmelCase__ (  self:	Optional[int]     )							->	Optional[int]:
										__magic_name__				:					Tuple						       =       ModelOutputTest({"a": 30, "b": 10}     )
										self.assertEqual(list(x.keys()     )      ,							["a", "b"]     )
										self.assertEqual(x.a      ,							30     )
										self.assertEqual(x.b      ,							10     )







						def lowerCAmelCase__ (  self:	Optional[int]     )							->	Optional[Any]:
										__magic_name__				:					List[str]						       =       ModelOutputTest([("a", 30), ("b", 10)]     )
										self.assertEqual(list(x.keys()     )      ,							["a", "b"]     )
										self.assertEqual(x.a      ,							30     )
										self.assertEqual(x.b      ,							10     )

										with self.assertRaises(__UpperCamelCase     ):
														__magic_name__				:					Any						       =       ModelOutputTest([("a", 30), (10, 10)]     )

										__magic_name__				:					Any						       =       ModelOutputTest(a=(30, 30)     )
										self.assertEqual(list(x.keys()     )      ,							["a"]     )
										self.assertEqual(x.a      ,							(30, 30)     )