





'''simple docstring'''




import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin







@skip_mps
class   A_	(  lowerCAmelCase_							,						lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : int           =							IFInpaintingSuperResolutionPipeline
 _lowerCamelCase  : Optional[Any]           =							TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
 _lowerCamelCase  : Optional[int]           =							TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}			)
 _lowerCamelCase  : Optional[Any]           =							PipelineTesterMixin.required_optional_params - {"""latents"""}




 def      lowercase	(					self       :    Union[str, Any]    ):
      return self._get_superresolution_dummy_components()




 def      lowercase	(					self       :    Optional[int]	,			snake_case_       :    Optional[Any]	,			snake_case_       :    str=0    ):
      if str(snake_case_    ).startswith("mps"    ):
           _UpperCAmelCase     							=   torch.manual_seed(snake_case_    )
      else:
           _UpperCAmelCase     							=   torch.Generator(device=snake_case_    ).manual_seed(snake_case_    )

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

      _UpperCAmelCase     							=   {
          "prompt": "A painting of a squirrel eating a burger",
          "image": image,
          "original_image": original_image,
          "mask_image": mask_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]    ):
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3    )




 def      lowercase	(					self       :    List[Any]    ):
      self._test_save_load_optional_components()




 @unittest.skipIf(torch_device != "cuda"	,			reason="float16 requires CUDA"    )
 def      lowercase	(					self       :    Any    ):
      # 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      lowercase	(					self       :    Any    ):
      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2    )




 def      lowercase	(					self       :    Tuple    ):
      self._test_save_load_local()




 def      lowercase	(					self       :    Tuple    ):
      self._test_inference_batch_single_identical(
          expected_max_diff=1e-2	,			)











'''simple docstring'''




from ..utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
)


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  from ..utils.dummy_pt_objects import *  # noqa F403
else:
  from .scheduling_consistency_models import CMStochasticIterativeScheduler
  from .scheduling_ddim import DDIMScheduler
  from .scheduling_ddim_inverse import DDIMInverseScheduler
  from .scheduling_ddim_parallel import DDIMParallelScheduler
  from .scheduling_ddpm import DDPMScheduler
  from .scheduling_ddpm_parallel import DDPMParallelScheduler
  from .scheduling_deis_multistep import DEISMultistepScheduler
  from .scheduling_dpmsolver_multistep import DPMSolverMultistepScheduler
  from .scheduling_dpmsolver_multistep_inverse import DPMSolverMultistepInverseScheduler
  from .scheduling_dpmsolver_singlestep import DPMSolverSinglestepScheduler
  from .scheduling_euler_ancestral_discrete import EulerAncestralDiscreteScheduler
  from .scheduling_euler_discrete import EulerDiscreteScheduler
  from .scheduling_heun_discrete import HeunDiscreteScheduler
  from .scheduling_ipndm import IPNDMScheduler
  from .scheduling_k_dpm_2_ancestral_discrete import KDPMaAncestralDiscreteScheduler
  from .scheduling_k_dpm_2_discrete import KDPMaDiscreteScheduler
  from .scheduling_karras_ve import KarrasVeScheduler
  from .scheduling_pndm import PNDMScheduler
  from .scheduling_repaint import RePaintScheduler
  from .scheduling_sde_ve import ScoreSdeVeScheduler
  from .scheduling_sde_vp import ScoreSdeVpScheduler
  from .scheduling_unclip import UnCLIPScheduler
  from .scheduling_unipc_multistep import UniPCMultistepScheduler
  from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
  from .scheduling_vq_diffusion import VQDiffusionScheduler

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  from ..utils.dummy_flax_objects import *  # noqa F403
else:
  from .scheduling_ddim_flax import FlaxDDIMScheduler
  from .scheduling_ddpm_flax import FlaxDDPMScheduler
  from .scheduling_dpmsolver_multistep_flax import FlaxDPMSolverMultistepScheduler
  from .scheduling_karras_ve_flax import FlaxKarrasVeScheduler
  from .scheduling_lms_discrete_flax import FlaxLMSDiscreteScheduler
  from .scheduling_pndm_flax import FlaxPNDMScheduler
  from .scheduling_sde_ve_flax import FlaxScoreSdeVeScheduler
  from .scheduling_utils_flax import (
      FlaxKarrasDiffusionSchedulers,
      FlaxSchedulerMixin,
      FlaxSchedulerOutput,
      broadcast_to_shape_from_left,
  )


try:
  if not (is_torch_available() and is_scipy_available()):
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  from ..utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
  from .scheduling_lms_discrete import LMSDiscreteScheduler

try:
  if not (is_torch_available() and is_torchsde_available()):
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  from ..utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
  from .scheduling_dpmsolver_sde import DPMSolverSDEScheduler




