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




	'''simple docstring'''





	snake_case_      					=  IFSuperResolutionPipeline
	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        UpperCamelCase_						( self      :				Union[str, Any]				):
					return self._get_superresolution_dummy_components()






	def        UpperCamelCase_						( self      :				int							,A      :				Union[str, Any]							,A      :				Tuple=0				):
					if str(A				).startswith("mps"				):
									__A         =				torch.manual_seed(A				)
					else:
									__A         =				torch.Generator(device=A				).manual_seed(A				)

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

					__A         =				{
					    "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        UpperCamelCase_						( self      :				int				):
					self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3				)






	def        UpperCamelCase_						( self      :				Tuple				):
					self._test_save_load_optional_components()






	@unittest.skipIf(torch_device != "cuda"							,reason="float16 requires CUDA"				)
	def        UpperCamelCase_						( self      :				List[str]				):
					# 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				)






	def        UpperCamelCase_						( self      :				Union[str, Any]				):
					self._test_attention_slicing_forward_pass(expected_max_diff=1E-2				)






	def        UpperCamelCase_						( self      :				List[Any]				):
					self._test_save_load_local()







	def        UpperCamelCase_						( self      :				Dict				):
					self._test_inference_batch_single_identical(
					    expected_max_diff=1E-2							,)


from typing import Any





class 							UpperCAmelCase   :




	'''simple docstring'''





	def __init__( self      :				Union[str, Any]				):
					__A         =				[]
					__A         =				0






	def __str__( self      :				Tuple				):
					__A         =				"<" + str(self.stack				)[1:-1] + ">"
					return printed






	def        UpperCamelCase_						( self      :				Optional[int]							,A      :				Any				):
					self.stack.append(A				)
					__A         =				self.length + 1






	def        UpperCamelCase_						( self      :				Any				):
					self.rotate(1				)
					__A         =				self.stack[self.length - 1]
					__A         =				self.stack[:-1]
					self.rotate(self.length - 1				)
					__A         =				self.length - 1
					return dequeued






	def        UpperCamelCase_						( self      :				Tuple							,A      :				int				):
					for _ in range(A				):
									__A         =				self.stack[0]
									__A         =				self.stack[1:]
									self.put(A				)
									__A         =				self.length - 1






	def        UpperCamelCase_						( self      :				Optional[Any]				):
					__A         =				self.get()
					self.put(A				)
					self.rotate(self.length - 1				)
					return front






	def        UpperCamelCase_						( self      :				Optional[Any]				):
					return self.length
