
import random
import unittest

import torch

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



							def     A__ (     self							)						->     Union[str, Any]:






								"""simple docstring"""



								return self._get_superresolution_dummy_components()



							def     A__ (     self	,				__snake_case	,				__snake_case=0							)						->     Union[str, Any]:






								"""simple docstring"""



								if str(__snake_case							).startswith("mps"							):
									UpperCAmelCase:					List[str] 						=     torch.manual_seed(__snake_case							)
								else:
									UpperCAmelCase:					Optional[int] 						=     torch.Generator(device=__snake_case							).manual_seed(__snake_case							)

								UpperCAmelCase:					Tuple 						=     floats_tensor((1, 3, 3_2, 3_2)	,				rng=random.Random(__snake_case							)							).to(__snake_case							)

								UpperCAmelCase:					Optional[int] 						=     {
								    "prompt": "A painting of a squirrel eating a burger",
								    "image": 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							)						->     List[str]:






								"""simple docstring"""



								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3							)



							def     A__ (     self							)						->     int:






								"""simple docstring"""



								self._test_save_load_optional_components()



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






								"""simple docstring"""



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



							def     A__ (     self							)						->     Optional[Any]:






								"""simple docstring"""



								self._test_attention_slicing_forward_pass(expected_max_diff=1e-2							)



							def     A__ (     self							)						->     Optional[Any]:






								"""simple docstring"""



								self._test_save_load_local()




							def     A__ (     self							)						->     List[Any]:






								"""simple docstring"""



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


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


snake_case_      :					Any				      =     {
    'configuration_imagegpt': ['IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ImageGPTConfig', 'ImageGPTOnnxConfig']
}

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_      :					str				      =     ['ImageGPTFeatureExtractor']
	snake_case_      :					Optional[int]				      =     ['ImageGPTImageProcessor']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_      :					List[str]				      =     [
	    'IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'ImageGPTForCausalImageModeling',
	    'ImageGPTForImageClassification',
	    'ImageGPTModel',
	    'ImageGPTPreTrainedModel',
	    'load_tf_weights_in_imagegpt',
	]


if TYPE_CHECKING:
	from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig, ImageGPTOnnxConfig

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_imagegpt import ImageGPTFeatureExtractor
		from .image_processing_imagegpt import ImageGPTImageProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_imagegpt import (
		    IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    ImageGPTForCausalImageModeling,
		    ImageGPTForImageClassification,
		    ImageGPTModel,
		    ImageGPTPreTrainedModel,
		    load_tf_weights_in_imagegpt,
		)

else:
	import sys

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