




"""simple docstring"""




import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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     __magic_name__							(       UpperCAmelCase__						,					UpperCAmelCase__						,					unittest.TestCase				):






				'''simple docstring'''
				__UpperCamelCase			  =						IFInpaintingPipeline
				__UpperCamelCase			  =						TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
				__UpperCamelCase			  =						TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
				__UpperCamelCase			  =						PipelineTesterMixin.required_optional_params - {"latents"}





				def    _lowerCAmelCase				(       self ):





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





				def    _lowerCAmelCase				(       self		, _a		, _a=0 ):





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

							lowerCamelCase			      =					floats_tensor((1, 3, 32, 32)		, rng=random.Random(_a ) ).to(_a )
							lowerCamelCase			      =					floats_tensor((1, 3, 32, 32)		, rng=random.Random(_a ) ).to(_a )

							lowerCamelCase			      =					{
							    """prompt""": """A painting of a squirrel eating a burger""",
							    """image""": 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    _lowerCAmelCase				(       self ):





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





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							self._test_save_load_optional_components()





				@unittest.skipIf(torch_device != """cuda"""		, reason="""float16 requires CUDA""" )
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							# 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    _lowerCAmelCase				(       self ):





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





				def    _lowerCAmelCase				(       self ):





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





				def    _lowerCAmelCase				(       self ):





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









"""simple docstring"""




import operator as op


lowerCAmelCase							:			Dict     							=							"""scaler.pt"""
lowerCAmelCase							:			Tuple     							=							"""pytorch_model"""
lowerCAmelCase							:			Union[str, Any]     							=							"""random_states"""
lowerCAmelCase							:			Union[str, Any]     							=							"""optimizer"""
lowerCAmelCase							:			Dict     							=							"""scheduler"""
lowerCAmelCase							:			int     							=							"""pytorch_model.bin"""
lowerCAmelCase							:			str     							=							"""pytorch_model.bin.index.json"""
lowerCAmelCase							:			Union[str, Any]     							=							"""model.safetensors"""
lowerCAmelCase							:			List[Any]     							=							"""model.safetensors.index.json"""
lowerCAmelCase							:			List[Any]     							=							"""1.10.2"""
lowerCAmelCase							:			Any     							=							"""py38"""
lowerCAmelCase							:			Optional[int]     							=							"""4.17.0"""
lowerCAmelCase							:			str     							=							["""ml.p3.16xlarge""", """ml.p3dn.24xlarge""", """ml.p4dn.24xlarge"""]
lowerCAmelCase							:			Tuple     							=							["""FULL_SHARD""", """SHARD_GRAD_OP""", """NO_SHARD""", """HYBRID_SHARD""", """HYBRID_SHARD_ZERO2"""]
lowerCAmelCase							:			List[Any]     							=							["""TRANSFORMER_BASED_WRAP""", """SIZE_BASED_WRAP""", """NO_WRAP"""]
lowerCAmelCase							:			List[str]     							=							["""BACKWARD_PRE""", """BACKWARD_POST""", """NO_PREFETCH"""]
lowerCAmelCase							:			List[str]     							=							["""FULL_STATE_DICT""", """LOCAL_STATE_DICT""", """SHARDED_STATE_DICT"""]
lowerCAmelCase							:			Any     							=							"""2.0.1"""
lowerCAmelCase							:			List[Any]     							=							["""pdsh""", """standard""", """openmpi""", """mvapich"""]
lowerCAmelCase							:			Union[str, Any]     							=							["""default""", """reduce-overhead""", """max-autotune"""]

lowerCAmelCase							:			Optional[int]     							=							{""">""": op.gt, """>=""": op.ge, """==""": op.eq, """!=""": op.ne, """<=""": op.le, """<""": op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
lowerCAmelCase							:			Union[str, Any]     							=							[
    """nnodes""",
    """nproc_per_node""",
    """rdzv_backend""",
    """rdzv_endpoint""",
    """rdzv_id""",
    """rdzv_conf""",
    """standalone""",
    """max_restarts""",
    """monitor_interval""",
    """start_method""",
    """role""",
    """module""",
    """m""",
    """no_python""",
    """run_path""",
    """log_dir""",
    """r""",
    """redirects""",
    """t""",
    """tee""",
    """node_rank""",
    """master_addr""",
    """master_port""",
]

lowerCAmelCase							:			List[str]     							=							["""DEEPSPEED""", """MULTI_GPU""", """FSDP""", """MEGATRON_LM"""]
lowerCAmelCase							:			Optional[Any]     							=							["""DEEPSPEED""", """MULTI_XPU""", """FSDP"""]



