



'''simple docstring'''


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


 '''simple docstring'''




 __magic_name__       :			Any	=   IFSuperResolutionPipeline
 __magic_name__       :			Any	=   TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
 __magic_name__       :			List[str]	=   TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
 __magic_name__       :			Dict	=   PipelineTesterMixin.required_optional_params - {"latents"}




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



      """simple docstring"""







      return self._get_superresolution_dummy_components()




 def    lowercase_	( self				,	lowerCAmelCase_				,	lowerCAmelCase_=0)			->   List[Any]:



      """simple docstring"""







      if str(lowerCAmelCase_).startswith("mps"):
           a_									=torch.manual_seed(lowerCAmelCase_)
      else:
           a_									=torch.Generator(device=lowerCAmelCase_).manual_seed(lowerCAmelCase_)

      a_									=floats_tensor((1, 3, 3_2, 3_2)				,	rng=random.Random(lowerCAmelCase_)).to(lowerCAmelCase_)

      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    lowercase_	( self)			->   List[str]:



      """simple docstring"""







      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3)




 def    lowercase_	( self)			->   str:



      """simple docstring"""







      self._test_save_load_optional_components()




 @unittest.skipIf(torch_device != "cuda"				,	reason="float16 requires CUDA")
 def    lowercase_	( self)			->   Dict:



      """simple docstring"""







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




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2)




 def    lowercase_	( self)			->   int:



      """simple docstring"""







      self._test_save_load_local()




 def    lowercase_	( self)			->   str:



      """simple docstring"""







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







'''simple docstring'''


from dataclasses import dataclass
from typing import Callable, Optional

import datasets







@dataclass
class 						UpperCAmelCase						(		datasets.BuilderConfig):


 '''simple docstring'''




 __magic_name__       :			Optional[Callable]	=   None
 __magic_name__       :			Optional[dict]	=   None
 __magic_name__       :			Optional[datasets.Features]	=   None




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



      """simple docstring"""







      assert self.generator is not None, "generator must be specified"

      if self.gen_kwargs is None:
           a_									={}







class 						UpperCAmelCase						(		datasets.GeneratorBasedBuilder):


 '''simple docstring'''




 __magic_name__       :			Tuple	=   GeneratorConfig




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      return datasets.DatasetInfo(features=self.config.features)




 def    lowercase_	( self				,	lowerCAmelCase_)			->   int:



      """simple docstring"""







      return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,	gen_kwargs=self.config.gen_kwargs)]




 def    lowercase_	( self				,	**lowerCAmelCase_)			->   List[Any]:



      """simple docstring"""







      for idx, ex in enumerate(self.config.generator(**lowerCAmelCase_)):
           yield idx, ex


