




import collections
import inspect
import unittest

from transformers import NatConfig
from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import NatBackbone, NatForImageClassification, NatModel
      from transformers.models.nat.modeling_nat import NAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class       A      :
     """simple docstring"""

     def __init__(     self	: str						,	A__	: List[Any]						,	A__	: str=1_3						,	A__	: Optional[Any]=6_4						,	A__	: int=4						,	A__	: List[str]=3						,	A__	: Any=1_6						,	A__	: List[str]=[1, 2, 1]						,	A__	: Union[str, Any]=[2, 4, 8]						,	A__	: int=3						,	A__	: List[str]=2.0						,	A__	: Dict=True						,	A__	: int=0.0						,	A__	: List[str]=0.0						,	A__	: Union[str, Any]=0.1						,	A__	: str="gelu"						,	A__	: Optional[Any]=True						,	A__	: List[Any]=0.02						,	A__	: Tuple=1E-5						,	A__	: List[Any]=True						,	A__	: List[str]=None						,	A__	: List[str]=True						,	A__	: Union[str, Any]=1_0						,	A__	: Union[str, Any]=["stage1", "stage2"]						,	A__	: Optional[int]=[1, 2]						,	)					->							str:
           lowerCamelCase__   	=					parent
           lowerCamelCase__   	=					batch_size
           lowerCamelCase__   	=					image_size
           lowerCamelCase__   	=					patch_size
           lowerCamelCase__   	=					num_channels
           lowerCamelCase__   	=					embed_dim
           lowerCamelCase__   	=					depths
           lowerCamelCase__   	=					num_heads
           lowerCamelCase__   	=					kernel_size
           lowerCamelCase__   	=					mlp_ratio
           lowerCamelCase__   	=					qkv_bias
           lowerCamelCase__   	=					hidden_dropout_prob
           lowerCamelCase__   	=					attention_probs_dropout_prob
           lowerCamelCase__   	=					drop_path_rate
           lowerCamelCase__   	=					hidden_act
           lowerCamelCase__   	=					patch_norm
           lowerCamelCase__   	=					layer_norm_eps
           lowerCamelCase__   	=					initializer_range
           lowerCamelCase__   	=					is_training
           lowerCamelCase__   	=					scope
           lowerCamelCase__   	=					use_labels
           lowerCamelCase__   	=					num_labels
           lowerCamelCase__   	=					out_features
           lowerCamelCase__   	=					out_indices




     def 			__snake_case (     self	: Dict      )					->							int:
           lowerCamelCase__   	=					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

           lowerCamelCase__   	=					None
           if self.use_labels:
                 lowerCamelCase__   	=					ids_tensor([self.batch_size]						,	self.num_labels      )

           lowerCamelCase__   	=					self.get_config()

           return config, pixel_values, labels




     def 			__snake_case (     self	: int      )					->							Optional[Any]:
           return NatConfig(
               num_labels=self.num_labels						,	image_size=self.image_size						,	patch_size=self.patch_size						,	num_channels=self.num_channels						,	embed_dim=self.embed_dim						,	depths=self.depths						,	num_heads=self.num_heads						,	kernel_size=self.kernel_size						,	mlp_ratio=self.mlp_ratio						,	qkv_bias=self.qkv_bias						,	hidden_dropout_prob=self.hidden_dropout_prob						,	attention_probs_dropout_prob=self.attention_probs_dropout_prob						,	drop_path_rate=self.drop_path_rate						,	hidden_act=self.hidden_act						,	patch_norm=self.patch_norm						,	layer_norm_eps=self.layer_norm_eps						,	initializer_range=self.initializer_range						,	out_features=self.out_features						,	out_indices=self.out_indices						,	)




     def 			__snake_case (     self	: int						,	A__	: Optional[int]						,	A__	: Optional[int]						,	A__	: List[str]      )					->							Union[str, Any]:
           lowerCamelCase__   	=					NatModel(config=__snake_case      )
           model.to(__snake_case      )
           model.eval()
           lowerCamelCase__   	=					model(__snake_case      )

           lowerCamelCase__   	=					(config.image_size // config.patch_size) // (2 ** (len(config.depths      ) - 1))
           lowerCamelCase__   	=					int(config.embed_dim * 2 ** (len(config.depths      ) - 1)      )

           self.parent.assertEqual(
               result.last_hidden_state.shape						,	(self.batch_size, expected_height, expected_width, expected_dim)      )




     def 			__snake_case (     self	: Dict						,	A__	: Dict						,	A__	: Dict						,	A__	: Optional[Any]      )					->							Union[str, Any]:
           lowerCamelCase__   	=					NatForImageClassification(__snake_case      )
           model.to(__snake_case      )
           model.eval()
           lowerCamelCase__   	=					model(__snake_case						,	labels=__snake_case      )
           self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels)      )

           # test greyscale images
           lowerCamelCase__   	=					1
           lowerCamelCase__   	=					NatForImageClassification(__snake_case      )
           model.to(__snake_case      )
           model.eval()

           lowerCamelCase__   	=					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
           lowerCamelCase__   	=					model(__snake_case      )
           self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels)      )




     def 			__snake_case (     self	: List[str]						,	A__	: Dict						,	A__	: Optional[int]						,	A__	: str      )					->							Tuple:
           lowerCamelCase__   	=					NatBackbone(config=__snake_case      )
           model.to(__snake_case      )
           model.eval()
           lowerCamelCase__   	=					model(__snake_case      )

           # verify hidden states
           self.parent.assertEqual(len(result.feature_maps      )						,	len(config.out_features      )      )
           self.parent.assertListEqual(list(result.feature_maps[0].shape      )						,	[self.batch_size, model.channels[0], 1_6, 1_6]      )

           # verify channels
           self.parent.assertEqual(len(model.channels      )						,	len(config.out_features      )      )

           # verify backbone works with out_features=None
           lowerCamelCase__   	=					None
           lowerCamelCase__   	=					NatBackbone(config=__snake_case      )
           model.to(__snake_case      )
           model.eval()
           lowerCamelCase__   	=					model(__snake_case      )

           # verify feature maps
           self.parent.assertEqual(len(result.feature_maps      )						,	1      )
           self.parent.assertListEqual(list(result.feature_maps[0].shape      )						,	[self.batch_size, model.channels[-1], 4, 4]      )

           # verify channels
           self.parent.assertEqual(len(model.channels      )						,	1      )




     def 			__snake_case (     self	: List[Any]      )					->							Union[str, Any]:
           lowerCamelCase__   	=					self.prepare_config_and_inputs()
           lowerCamelCase__   	=					config_and_inputs
           lowerCamelCase__   	=					{"pixel_values": pixel_values}
           return config, inputs_dict






@require_natten
@require_torch
class       A      (		__A      ,    __A      ,    unittest.TestCase		):
     """simple docstring"""

     _snake_case:						int  =(
         (
             NatModel,
             NatForImageClassification,
             NatBackbone,
         )
         if is_torch_available()
         else ()
     )
     _snake_case:						Union[str, Any]  =(
         {'feature-extraction': NatModel, 'image-classification': NatForImageClassification}
         if is_torch_available()
         else {}
     )
     _snake_case:						Union[str, Any]  =False

     _snake_case:						Optional[int]  =False
     _snake_case:						str  =False
     _snake_case:						List[str]  =False
     _snake_case:						Tuple  =False




     def 			__snake_case (     self	: Union[str, Any]      )					->							Optional[Any]:
           lowerCamelCase__   	=					NatModelTester(self      )
           lowerCamelCase__   	=					ConfigTester(self						,	config_class=__snake_case						,	embed_dim=3_7      )




     def 			__snake_case (     self	: List[Any]      )					->							int:
           self.create_and_test_config_common_properties()
           self.config_tester.create_and_test_config_to_json_string()
           self.config_tester.create_and_test_config_to_json_file()
           self.config_tester.create_and_test_config_from_and_save_pretrained()
           self.config_tester.create_and_test_config_with_num_labels()
           self.config_tester.check_config_can_be_init_without_params()
           self.config_tester.check_config_arguments_init()




     def 			__snake_case (     self	: int      )					->							Union[str, Any]:
           return




     def 			__snake_case (     self	: str      )					->							List[str]:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__snake_case      )




     def 			__snake_case (     self	: Optional[Any]      )					->							List[Any]:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*__snake_case      )




     def 			__snake_case (     self	: int      )					->							Optional[Any]:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_backbone(*__snake_case      )




     @unittest.skip(reason='Nat does not use inputs_embeds'      )
     def 			__snake_case (     self	: Any      )					->							int:
           pass




     @unittest.skip(reason='Nat does not use feedforward chunking'      )
     def 			__snake_case (     self	: Optional[Any]      )					->							Union[str, Any]:
           pass




     def 			__snake_case (     self	: List[Any]      )					->							List[Any]:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 lowerCamelCase__   	=					model_class(__snake_case      )
                 self.assertIsInstance(model.get_input_embeddings()						,	(nn.Module)      )
                 lowerCamelCase__   	=					model.get_output_embeddings()
                 self.assertTrue(x is None or isinstance(__snake_case						,	nn.Linear      )      )




     def 			__snake_case (     self	: int      )					->							Tuple:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 lowerCamelCase__   	=					model_class(__snake_case      )
                 lowerCamelCase__   	=					inspect.signature(model.forward      )
                 # signature.parameters is an OrderedDict => so arg_names order is deterministic
                 lowerCamelCase__   	=					[*signature.parameters.keys()]

                 lowerCamelCase__   	=					["pixel_values"]
                 self.assertListEqual(arg_names[:1]						,	__snake_case      )




     def 			__snake_case (     self	: Optional[Any]      )					->							Optional[Any]:
           self.skipTest('Nat\'s attention operation is handled entirely by NATTEN.'      )




     def 			__snake_case (     self	: Union[str, Any]						,	A__	: Tuple						,	A__	: Union[str, Any]						,	A__	: str						,	A__	: List[str]      )					->							Any:
           lowerCamelCase__   	=					model_class(__snake_case      )
           model.to(__snake_case      )
           model.eval()

           with torch.no_grad():
                 lowerCamelCase__   	=					model(**self._prepare_for_class(__snake_case						,	__snake_case      )      )

           lowerCamelCase__   	=					outputs.hidden_states

           lowerCamelCase__   	=					getattr(
               self.model_tester						,	'expected_num_hidden_layers'						,	len(self.model_tester.depths      ) + 1      )
           self.assertEqual(len(__snake_case      )						,	__snake_case      )

           # Nat has a different seq_length
           lowerCamelCase__   	=					(
               config.patch_size
               if isinstance(config.patch_size						,	collections.abc.Iterable      )
               else (config.patch_size, config.patch_size)
           )

           lowerCamelCase__   	=					image_size[0] // patch_size[0]
           lowerCamelCase__   	=					image_size[1] // patch_size[1]

           self.assertListEqual(
               list(hidden_states[0].shape[-3:]      )						,	[height, width, self.model_tester.embed_dim]						,	)

           if model_class.__name__ != "NatBackbone":
                 lowerCamelCase__   	=					outputs.reshaped_hidden_states
                 self.assertEqual(len(__snake_case      )						,	__snake_case      )

                 lowerCamelCase__   	=					reshaped_hidden_states[0].shape
                 lowerCamelCase__   	=					(
                     reshaped_hidden_states[0].view(__snake_case						,	__snake_case						,	__snake_case						,	__snake_case      ).permute(0						,	2						,	3						,	1      )
                 )
                 self.assertListEqual(
                     list(reshaped_hidden_states.shape[-3:]      )						,	[height, width, self.model_tester.embed_dim]						,	)




     def 			__snake_case (     self	: List[Any]      )					->							str:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs_for_common()

           lowerCamelCase__   	=					(
               self.model_tester.image_size
               if isinstance(self.model_tester.image_size						,	collections.abc.Iterable      )
               else (self.model_tester.image_size, self.model_tester.image_size)
           )

           for model_class in self.all_model_classes:
                 lowerCamelCase__   	=					True
                 self.check_hidden_states_output(__snake_case						,	__snake_case						,	__snake_case						,	__snake_case      )

                 # check that output_hidden_states also work using config
                 del inputs_dict["output_hidden_states"]
                 lowerCamelCase__   	=					True

                 self.check_hidden_states_output(__snake_case						,	__snake_case						,	__snake_case						,	__snake_case      )




     @slow
     def 			__snake_case (     self	: str      )					->							List[Any]:

           for model_name in NAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowerCamelCase__   	=					NatModel.from_pretrained(__snake_case      )
                 self.assertIsNotNone(__snake_case      )




     def 			__snake_case (     self	: List[str]      )					->							Optional[Any]:
           lowerCamelCase__   	=					self.model_tester.prepare_config_and_inputs_for_common()

           lowerCamelCase__   	=					_config_zero_init(__snake_case      )
           for model_class in self.all_model_classes:
                 lowerCamelCase__   	=					model_class(config=__snake_case      )
                 for name, param in model.named_parameters():
                       if "embeddings" not in name and param.requires_grad:
                             self.assertIn(
                                 ((param.data.mean() * 1E9).round() / 1E9).item()						,	[0.0, 1.0]						,	msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""						,	)






@require_natten
@require_vision
@require_torch
class       A      (		unittest.TestCase		):
     """simple docstring"""

     @cached_property
     def 			__snake_case (     self	: List[Any]      )					->							Any:
           return AutoImageProcessor.from_pretrained('shi-labs/nat-mini-in1k-224'      ) if is_vision_available() else None




     @slow
     def 			__snake_case (     self	: Any      )					->							int:
           lowerCamelCase__   	=					NatForImageClassification.from_pretrained('shi-labs/nat-mini-in1k-224'      ).to(__snake_case      )
           lowerCamelCase__   	=					self.default_image_processor

           lowerCamelCase__   	=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      )
           lowerCamelCase__   	=					image_processor(images=__snake_case						,	return_tensors='pt'      ).to(__snake_case      )

           # forward pass
           with torch.no_grad():
                 lowerCamelCase__   	=					model(**__snake_case      )

           # verify the logits
           lowerCamelCase__   	=					torch.Size((1, 1_0_0_0)      )
           self.assertEqual(outputs.logits.shape						,	__snake_case      )
           lowerCamelCase__   	=					torch.tensor([0.3805, -0.8676, -0.3912]      ).to(__snake_case      )
           self.assertTrue(torch.allclose(outputs.logits[0, :3]						,	__snake_case						,	atol=1E-4      )      )






@require_torch
@require_natten
class       A      (		unittest.TestCase      ,    __A		):
     """simple docstring"""

     _snake_case:						Any  =(NatBackbone,) if is_torch_available() else ()
     _snake_case:						List[Any]  =NatConfig




     def 			__snake_case (     self	: int      )					->							Optional[Any]:
           lowerCamelCase__   	=					NatModelTester(self      )






import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPImageProcessor, CLIPVisionConfig

from diffusers import AutoencoderKL, PaintByExamplePipeline, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.paint_by_example import PaintByExampleImageEncoder
from diffusers.utils import floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()






class 							_a(     __A						, unittest.TestCase     ):
		lowerCamelCase__  :Optional[int] 					=		PaintByExamplePipeline
		lowerCamelCase__  :Union[str, Any] 					=		IMAGE_GUIDED_IMAGE_INPAINTING_PARAMS
		lowerCamelCase__  :Optional[Any] 					=		IMAGE_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
		lowerCamelCase__  :int 					=		frozenset([]     )  # TO_DO: update the image_prams once refactored VaeImageProcessor.preprocess







		def 							lowercase							(     self					)   ->   Dict:


							'''simple docstring'''

							torch.manual_seed(0					)
							_snake_case							:       Union[str, Any]												= UNetaDConditionModel(
							    block_out_channels=(3_2, 6_4)			,    layers_per_block=2			,    sample_size=3_2			,    in_channels=9			,    out_channels=4			,    down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")			,    up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")			,    cross_attention_dim=3_2			,    )
							_snake_case							:       int												= PNDMScheduler(skip_prk_steps=__snake_case					)
							torch.manual_seed(0					)
							_snake_case							:       Any												= AutoencoderKL(
							    block_out_channels=[3_2, 6_4]			,    in_channels=3			,    out_channels=3			,    down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]			,    up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]			,    latent_channels=4			,    )
							torch.manual_seed(0					)
							_snake_case							:       Dict												= CLIPVisionConfig(
							    hidden_size=3_2			,    projection_dim=3_2			,    intermediate_size=3_7			,    layer_norm_eps=1E-05			,    num_attention_heads=4			,    num_hidden_layers=5			,    image_size=3_2			,    patch_size=4			,    )
							_snake_case							:       Any												= PaintByExampleImageEncoder(__snake_case			,    proj_size=3_2					)
							_snake_case							:       Dict												= CLIPImageProcessor(crop_size=3_2			,    size=3_2					)

							_snake_case							:       Any												= {
							    "unet": unet,
							    "scheduler": scheduler,
							    "vae": vae,
							    "image_encoder": image_encoder,
							    "safety_checker": None,
							    "feature_extractor": feature_extractor,
							}
							return components







		def 							lowercase							(     self			,    __snake_case					)   ->   Tuple:


							'''simple docstring'''

							_snake_case							:       List[str]												= np.array(image.convert("RGB"					)					)
							_snake_case							:       str												= image[None].transpose(0			,    3			,    1			,    2					)
							_snake_case							:       Dict												= torch.from_numpy(__snake_case					).to(dtype=torch.floataa					) / 1_27.5 - 1.0
							return image







		def 							lowercase							(     self			,    __snake_case="cpu"			,    __snake_case=0					)   ->   Any:


							'''simple docstring'''

							_snake_case							:       Tuple												= floats_tensor((1, 3, 3_2, 3_2)			,    rng=random.Random(__snake_case					)					).to(__snake_case					)
							_snake_case							:       Union[str, Any]												= image.cpu().permute(0			,    2			,    3			,    1					)[0]
							_snake_case							:       List[Any]												= Image.fromarray(np.uinta(__snake_case					)					).convert("RGB"					).resize((6_4, 6_4)					)
							_snake_case							:       List[Any]												= Image.fromarray(np.uinta(image + 4					)					).convert("RGB"					).resize((6_4, 6_4)					)
							_snake_case							:       Any												= Image.fromarray(np.uinta(__snake_case					)					).convert("RGB"					).resize((3_2, 3_2)					)

							if str(__snake_case					).startswith("mps"					):
												_snake_case							:       Union[str, Any]												= torch.manual_seed(__snake_case					)
							else:
												_snake_case							:       List[Any]												= torch.Generator(device=__snake_case					).manual_seed(__snake_case					)
							_snake_case							:       Optional[int]												= {
							    "example_image": example_image,
							    "image": init_image,
							    "mask_image": mask_image,
							    "generator": generator,
							    "num_inference_steps": 2,
							    "guidance_scale": 6.0,
							    "output_type": "numpy",
							}
							return inputs







		def 							lowercase							(     self					)   ->   int:


							'''simple docstring'''

							_snake_case							:       Optional[Any]												= self.get_dummy_components()

							# make sure here that pndm scheduler skips prk
							_snake_case							:       int												= PaintByExamplePipeline(**__snake_case					)
							_snake_case							:       List[Any]												= pipe.to("cpu"					)
							pipe.set_progress_bar_config(disable=__snake_case					)

							_snake_case							:       List[str]												= self.get_dummy_inputs()
							_snake_case							:       int												= pipe(**__snake_case					)
							_snake_case							:       Dict												= output.images

							_snake_case							:       Optional[int]												= image[0, -3:, -3:, -1]

							assert image.shape == (1, 6_4, 6_4, 3)
							_snake_case							:       int												= np.array([0.46_86, 0.56_87, 0.40_07, 0.52_18, 0.57_41, 0.44_82, 0.49_40, 0.46_29, 0.45_03]					)

							assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2







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


							'''simple docstring'''

							_snake_case							:       Optional[int]												= "cpu"
							_snake_case							:       str												= self.get_dummy_inputs()
							inputs.pop("mask_image"					)
							_snake_case							:       Union[str, Any]												= self.convert_to_pt(inputs.pop("image"					)					)
							_snake_case							:       Union[str, Any]												= image.clamp(0			,    1					) / 2

							# make sure here that pndm scheduler skips prk
							_snake_case							:       Dict												= PaintByExamplePipeline(**self.get_dummy_components()					)
							_snake_case							:       Union[str, Any]												= pipe.to(__snake_case					)
							pipe.set_progress_bar_config(disable=__snake_case					)

							_snake_case							:       int												= pipe(image=__snake_case			,    mask_image=mask_image[:, 0]			,    **__snake_case					)
							_snake_case							:       Optional[int]												= output.images

							_snake_case							:       Any												= image.cpu().permute(0			,    2			,    3			,    1					)[0]
							_snake_case							:       List[str]												= mask_image.cpu().permute(0			,    2			,    3			,    1					)[0]

							_snake_case							:       Any												= Image.fromarray(np.uinta(__snake_case					)					).convert("RGB"					)
							_snake_case							:       int												= Image.fromarray(np.uinta(__snake_case					)					).convert("RGB"					)

							_snake_case							:       Optional[int]												= pipe(**self.get_dummy_inputs()					)
							_snake_case							:       Dict												= output.images

							assert out_a.shape == (1, 6_4, 6_4, 3)
							assert np.abs(out_a.flatten() - out_a.flatten()					).max() < 5E-2







		def 							lowercase							(     self					)   ->   Union[str, Any]:


							'''simple docstring'''

							super().test_inference_batch_single_identical(expected_max_diff=3E-3					)






@slow
@require_torch_gpu
class 							_a(     unittest.TestCase     ):







		def 							lowercase							(     self					)   ->   Union[str, Any]:


							'''simple docstring'''

							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()







		def 							lowercase							(     self					)   ->   int:


							'''simple docstring'''

							_snake_case							:       Tuple												= load_image(
							    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
							    "/paint_by_example/dog_in_bucket.png"					)
							_snake_case							:       Optional[Any]												= load_image(
							    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
							    "/paint_by_example/mask.png"					)
							_snake_case							:       Optional[int]												= load_image(
							    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
							    "/paint_by_example/panda.jpg"					)

							_snake_case							:       Any												= PaintByExamplePipeline.from_pretrained("Fantasy-Studio/Paint-by-Example"					)
							_snake_case							:       Any												= pipe.to(__snake_case					)
							pipe.set_progress_bar_config(disable=__snake_case					)

							_snake_case							:       Union[str, Any]												= torch.manual_seed(3_2_1					)
							_snake_case							:       int												= pipe(
							    image=__snake_case			,    mask_image=__snake_case			,    example_image=__snake_case			,    generator=__snake_case			,    guidance_scale=5.0			,    num_inference_steps=5_0			,    output_type="np"			,    )

							_snake_case							:       str												= output.images

							_snake_case							:       Optional[int]												= image[0, -3:, -3:, -1]

							assert image.shape == (1, 5_1_2, 5_1_2, 3)
							_snake_case							:       int												= np.array([0.48_34, 0.48_11, 0.48_74, 0.51_22, 0.50_81, 0.51_44, 0.52_91, 0.52_90, 0.53_74]					)

							assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2