


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



		"""simple docstring"""

		UpperCamelCase    :				Tuple 					=		IFImgaImgPipeline
		UpperCamelCase    :				Dict 					=		TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
		UpperCamelCase    :				Dict 					=		TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
		UpperCamelCase    :				List[str] 					=		PipelineTesterMixin.required_optional_params - {"latents"}







		def 				__A      (   self  )     ->   Optional[int]:







					'''simple docstring'''







					return self._get_dummy_components()







		def 				__A      (   self		,			A		,			A=0  )     ->   int:







					'''simple docstring'''







					if str(A  ).startswith("""mps"""  ):
								lowerCamelCase								=     torch.manual_seed(A  )
					else:
								lowerCamelCase								=     torch.Generator(device=A  ).manual_seed(A  )

					lowerCamelCase								=     floats_tensor((1, 3, 32, 32)		,			rng=random.Random(A  )  ).to(A  )

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

					return inputs







		def 				__A      (   self  )     ->   Tuple:







					'''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 				__A      (   self  )     ->   Union[str, Any]:







					'''simple docstring'''







					self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3  )







		@unittest.skipIf(torch_device != """cuda"""		,			reason="""float16 requires CUDA"""  )
		def 				__A      (   self  )     ->   Union[str, Any]:







					'''simple docstring'''







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







		@unittest.skipIf(torch_device != """cuda"""		,			reason="""float16 requires CUDA"""  )
		def 				__A      (   self  )     ->   Optional[Any]:







					'''simple docstring'''







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







		def 				__A      (   self  )     ->   str:







					'''simple docstring'''







					self._test_attention_slicing_forward_pass(expected_max_diff=1e-2  )







		def 				__A      (   self  )     ->   str:







					'''simple docstring'''







					self._test_save_load_local()







		def 				__A      (   self  )     ->   Optional[int]:







					'''simple docstring'''







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





from typing import TYPE_CHECKING

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


UpperCAmelCase      :						List[str]    =		{
    "configuration_big_bird": ["BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP", "BigBirdConfig", "BigBirdOnnxConfig"],
}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase      :						str    =		["BigBirdTokenizer"]

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase      :						str    =		["BigBirdTokenizerFast"]

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase      :						Dict    =		[
		    "BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "BigBirdForCausalLM",
		    "BigBirdForMaskedLM",
		    "BigBirdForMultipleChoice",
		    "BigBirdForPreTraining",
		    "BigBirdForQuestionAnswering",
		    "BigBirdForSequenceClassification",
		    "BigBirdForTokenClassification",
		    "BigBirdLayer",
		    "BigBirdModel",
		    "BigBirdPreTrainedModel",
		    "load_tf_weights_in_big_bird",
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCAmelCase      :						Dict    =		[
		    "FlaxBigBirdForCausalLM",
		    "FlaxBigBirdForMaskedLM",
		    "FlaxBigBirdForMultipleChoice",
		    "FlaxBigBirdForPreTraining",
		    "FlaxBigBirdForQuestionAnswering",
		    "FlaxBigBirdForSequenceClassification",
		    "FlaxBigBirdForTokenClassification",
		    "FlaxBigBirdModel",
		    "FlaxBigBirdPreTrainedModel",
		]

if TYPE_CHECKING:
		from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_big_bird import BigBirdTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_big_bird_fast import BigBirdTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_big_bird import (
				    BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BigBirdForCausalLM,
				    BigBirdForMaskedLM,
				    BigBirdForMultipleChoice,
				    BigBirdForPreTraining,
				    BigBirdForQuestionAnswering,
				    BigBirdForSequenceClassification,
				    BigBirdForTokenClassification,
				    BigBirdLayer,
				    BigBirdModel,
				    BigBirdPreTrainedModel,
				    load_tf_weights_in_big_bird,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_big_bird import (
				    FlaxBigBirdForCausalLM,
				    FlaxBigBirdForMaskedLM,
				    FlaxBigBirdForMultipleChoice,
				    FlaxBigBirdForPreTraining,
				    FlaxBigBirdForQuestionAnswering,
				    FlaxBigBirdForSequenceClassification,
				    FlaxBigBirdForTokenClassification,
				    FlaxBigBirdModel,
				    FlaxBigBirdPreTrainedModel,
				)

else:
		import sys

		UpperCAmelCase      :						Dict    =		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

