


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






  """simple docstring"""





  _SCREAMING_SNAKE_CASE						      =    IFImgaImgPipeline
  _SCREAMING_SNAKE_CASE						      =    TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
  _SCREAMING_SNAKE_CASE						      =    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
  _SCREAMING_SNAKE_CASE						      =    PipelineTesterMixin.required_optional_params - {'latents'}



  def    lowerCAmelCase__					(       self    :    str					)				->	List[Any]:




     """simple docstring"""
     return self._get_dummy_components()



  def    lowerCAmelCase__					(       self    :    Any      ,			_lowerCAmelCase    :    Dict      ,			_lowerCAmelCase    :    List[str]=0					)				->	Optional[Any]:




     """simple docstring"""
     if str(_lowerCAmelCase					).startswith("mps"					):
        snake_case_         =   torch.manual_seed(_lowerCAmelCase					)
     else:
        snake_case_         =   torch.Generator(device=_lowerCAmelCase					).manual_seed(_lowerCAmelCase					)

     snake_case_         =   floats_tensor((1, 3, 3_2, 3_2)      ,			rng=random.Random(_lowerCAmelCase					)					).to(_lowerCAmelCase					)

     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    :    Tuple					)				->	Optional[Any]:




     """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    lowerCAmelCase__					(       self    :    Dict					)				->	Optional[int]:




     """simple docstring"""
     self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3					)



  @unittest.skipIf(torch_device != "cuda"      ,			reason="float16 requires CUDA"					)
  def    lowerCAmelCase__					(       self    :    Optional[Any]					)				->	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    lowerCAmelCase__					(       self    :    Optional[int]					)				->	Dict:




     """simple docstring"""
     super().test_floataa_inference(expected_max_diff=1e-1					)



  def    lowerCAmelCase__					(       self    :    Tuple					)				->	Dict:




     """simple docstring"""
     self._test_attention_slicing_forward_pass(expected_max_diff=1e-2					)



  def    lowerCAmelCase__					(       self    :    Tuple					)				->	Tuple:




     """simple docstring"""
     self._test_save_load_local()



  def    lowerCAmelCase__					(       self    :    Optional[Any]					)				->	Tuple:




     """simple docstring"""
     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_torch_available


SCREAMING_SNAKE_CASE		:str											=       {'''configuration_cvt''': ['''CVT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''CvtConfig''']}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE		:Any											=       [
       '''CVT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''CvtForImageClassification''',
       '''CvtModel''',
       '''CvtPreTrainedModel''',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE		:Any											=       [
       '''TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''TFCvtForImageClassification''',
       '''TFCvtModel''',
       '''TFCvtPreTrainedModel''',
   ]

if TYPE_CHECKING:
   from .configuration_cvt import CVT_PRETRAINED_CONFIG_ARCHIVE_MAP, CvtConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_cvt import (
          CVT_PRETRAINED_MODEL_ARCHIVE_LIST,
          CvtForImageClassification,
          CvtModel,
          CvtPreTrainedModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_cvt import (
          TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFCvtForImageClassification,
          TFCvtModel,
          TFCvtPreTrainedModel,
      )


else:
   import sys

   SCREAMING_SNAKE_CASE		:str											=       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




