






"""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 					__SCREAMING_SNAKE_CASE(		A__      ,					A__      ,					unittest.TestCase		):
							_UpperCAmelCase	      =    IFImgaImgPipeline
							_UpperCAmelCase	      =    TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
							_UpperCAmelCase	      =    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
							_UpperCAmelCase	      =    PipelineTesterMixin.required_optional_params - {"latents"}
							def lowerCAmelCase_	(       self: List[Any]  )						->						Dict:
											return self._get_dummy_components()
							def lowerCAmelCase_	(       self: List[str]    ,		UpperCamelCase: List[str]    ,		UpperCamelCase: List[Any]=0  )						->						Any:






											if str(_A  ).startswith('mps'  ):
															snake_case__													=       torch.manual_seed(_A  )
											else:
															snake_case__													=       torch.Generator(device=_A  ).manual_seed(_A  )

											snake_case__													=       floats_tensor((1, 3, 32, 32)    ,		rng=random.Random(_A  )  ).to(_A  )

											snake_case__													=       {
											    "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: Any  )						->						List[str]:
											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: Any  )						->						Union[str, Any]:
											self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3  )
							@unittest.skipIf(torch_device != 'cuda'    ,		reason='float16 requires CUDA'  )
							def lowerCAmelCase_	(       self: Tuple  )						->						Optional[Any]:
											super().test_save_load_floataa(expected_max_diff=1e-1  )
							@unittest.skipIf(torch_device != 'cuda'    ,		reason='float16 requires CUDA'  )
							def lowerCAmelCase_	(       self: Optional[Any]  )						->						Union[str, Any]:
											super().test_floataa_inference(expected_max_diff=1e-1  )
							def lowerCAmelCase_	(       self: int  )						->						Union[str, Any]:
											self._test_attention_slicing_forward_pass(expected_max_diff=1e-2  )
							def lowerCAmelCase_	(       self: str  )						->						Optional[int]:
											self._test_save_load_local()


							def lowerCAmelCase_	(       self: Any  )						->						List[Any]:
											self._test_inference_batch_single_identical(
											    expected_max_diff=1e-2    ,		)












from typing import TYPE_CHECKING

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


__UpperCamelCase   :						int							=  {
    """configuration_openai""": ["""OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """OpenAIGPTConfig"""],
    """tokenization_openai""": ["""OpenAIGPTTokenizer"""],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase   :						Optional[Any]							=  ["""OpenAIGPTTokenizerFast"""]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase   :						List[str]							=  [
							    """OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """OpenAIGPTDoubleHeadsModel""",
							    """OpenAIGPTForSequenceClassification""",
							    """OpenAIGPTLMHeadModel""",
							    """OpenAIGPTModel""",
							    """OpenAIGPTPreTrainedModel""",
							    """load_tf_weights_in_openai_gpt""",
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__UpperCamelCase   :						Dict							=  [
							    """TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """TFOpenAIGPTDoubleHeadsModel""",
							    """TFOpenAIGPTForSequenceClassification""",
							    """TFOpenAIGPTLMHeadModel""",
							    """TFOpenAIGPTMainLayer""",
							    """TFOpenAIGPTModel""",
							    """TFOpenAIGPTPreTrainedModel""",
							]


if TYPE_CHECKING:
							from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
							from .tokenization_openai import OpenAIGPTTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_openai_fast import OpenAIGPTTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_openai import (
														    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    OpenAIGPTDoubleHeadsModel,
														    OpenAIGPTForSequenceClassification,
														    OpenAIGPTLMHeadModel,
														    OpenAIGPTModel,
														    OpenAIGPTPreTrainedModel,
														    load_tf_weights_in_openai_gpt,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_openai import (
														    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFOpenAIGPTDoubleHeadsModel,
														    TFOpenAIGPTForSequenceClassification,
														    TFOpenAIGPTLMHeadModel,
														    TFOpenAIGPTMainLayer,
														    TFOpenAIGPTModel,
														    TFOpenAIGPTPreTrainedModel,
														)

else:
							import sys

							__UpperCamelCase   :						List[Any]							=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




