



from __future__ import annotations

import unittest

from transformers import EsmConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import numpy
				import tensorflow as tf

				from transformers.models.esm.modeling_tf_esm import (
				    TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFEsmForMaskedLM,
				    TFEsmForSequenceClassification,
				    TFEsmForTokenClassification,
				    TFEsmModel,
				)



class        lowerCAmelCase__					:


				def __init__(							self      :  Union[str, Any]						, __UpperCamelCase      :  Union[str, Any]						, )		->     int:
											A      						=    parent
											A      						=    13
											A      						=    7
											A      						=    True
											A      						=    True
											A      						=    True
											A      						=    99
											A      						=    32
											A      						=    2
											A      						=    4
											A      						=    37
											A      						=    'gelu'
											A      						=    0.1
											A      						=    0.1
											A      						=    512
											A      						=    16
											A      						=    2
											A      						=    0.0_2
											A      						=    3
											A      						=    4
											A      						=    None


				def __UpperCamelCase						(							self      :  List[Any]       )		->     Any:
											A      						=    ids_tensor([self.batch_size, self.seq_length]						, self.vocab_size       )

											A      						=    None
											if self.use_input_mask:
																		A      						=    random_attention_mask([self.batch_size, self.seq_length]       )

											A      						=    None
											A      						=    None
											A      						=    None
											if self.use_labels:
																		A      						=    ids_tensor([self.batch_size]						, self.type_sequence_label_size       )
																		A      						=    ids_tensor([self.batch_size, self.seq_length]						, self.num_labels       )
																		A      						=    ids_tensor([self.batch_size]						, self.num_choices       )

											A      						=    EsmConfig(
											    vocab_size=self.vocab_size						, hidden_size=self.hidden_size						, num_hidden_layers=self.num_hidden_layers						, pad_token_id=1						, num_attention_heads=self.num_attention_heads						, intermediate_size=self.intermediate_size						, hidden_act=self.hidden_act						, hidden_dropout_prob=self.hidden_dropout_prob						, attention_probs_dropout_prob=self.attention_probs_dropout_prob						, max_position_embeddings=self.max_position_embeddings						, type_vocab_size=self.type_vocab_size						, initializer_range=self.initializer_range						, )

											return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


				def __UpperCamelCase						(							self      :  Tuple       )		->     Any:
											(
											    (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   
											)      						=    self.prepare_config_and_inputs()

											A      						=    True
											A      						=    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]       )
											A      						=    ids_tensor([self.batch_size, self.seq_length]						, vocab_size=2       )

											return (
											    config,
											    input_ids,
											    input_mask,
											    sequence_labels,
											    token_labels,
											    choice_labels,
											    encoder_hidden_states,
											    encoder_attention_mask,
											)


				def __UpperCamelCase						(							self      :  str						, __UpperCamelCase      :  Optional[Any]						, __UpperCamelCase      :  Dict						, __UpperCamelCase      :  Optional[int]						, __UpperCamelCase      :  List[Any]						, __UpperCamelCase      :  Any						, __UpperCamelCase      :  Optional[Any]       )		->     str:
											A      						=    TFEsmModel(config=__UpperCamelCase       )
											A      						=    {'input_ids': input_ids, 'attention_mask': input_mask}
											A      						=    model(__UpperCamelCase       )

											A      						=    [input_ids, input_mask]
											A      						=    model(__UpperCamelCase       )

											A      						=    model(__UpperCamelCase       )

											self.parent.assertEqual(result.last_hidden_state.shape						, (self.batch_size, self.seq_length, self.hidden_size)       )


				def __UpperCamelCase						(							self      :  int						, __UpperCamelCase      :  str						, __UpperCamelCase      :  str						, __UpperCamelCase      :  List[str]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Any						, __UpperCamelCase      :  Tuple						, __UpperCamelCase      :  Any						, __UpperCamelCase      :  str						, )		->     Tuple:
											A      						=    True

											A      						=    TFEsmModel(config=__UpperCamelCase       )
											A      						=    {
											    'input_ids': input_ids,
											    'attention_mask': input_mask,
											    'encoder_hidden_states': encoder_hidden_states,
											    'encoder_attention_mask': encoder_attention_mask,
											}
											A      						=    model(__UpperCamelCase       )

											A      						=    [input_ids, input_mask]
											A      						=    model(__UpperCamelCase						, encoder_hidden_states=__UpperCamelCase       )

											# Also check the case where encoder outputs are not passed
											A      						=    model(__UpperCamelCase						, attention_mask=__UpperCamelCase       )

											self.parent.assertEqual(result.last_hidden_state.shape						, (self.batch_size, self.seq_length, self.hidden_size)       )


				def __UpperCamelCase						(							self      :  str						, __UpperCamelCase      :  int						, __UpperCamelCase      :  Tuple						, __UpperCamelCase      :  Tuple						, __UpperCamelCase      :  Optional[Any]						, __UpperCamelCase      :  str						, __UpperCamelCase      :  Union[str, Any]       )		->     Union[str, Any]:
											A      						=    TFEsmForMaskedLM(config=__UpperCamelCase       )
											A      						=    model([input_ids, input_mask]       )
											self.parent.assertEqual(result.logits.shape						, (self.batch_size, self.seq_length, self.vocab_size)       )


				def __UpperCamelCase						(							self      :  int						, __UpperCamelCase      :  Dict						, __UpperCamelCase      :  List[str]						, __UpperCamelCase      :  List[str]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Optional[Any]						, __UpperCamelCase      :  Any       )		->     Optional[int]:
											A      						=    self.num_labels
											A      						=    TFEsmForTokenClassification(config=__UpperCamelCase       )
											A      						=    {'input_ids': input_ids, 'attention_mask': input_mask}
											A      						=    model(__UpperCamelCase       )
											self.parent.assertEqual(result.logits.shape						, (self.batch_size, self.seq_length, self.num_labels)       )


				def __UpperCamelCase						(							self      :  Optional[Any]       )		->     List[str]:
											A      						=    self.prepare_config_and_inputs()
											(
											    (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   (
											    A
											)						,   
											)      						=    config_and_inputs
											A      						=    {'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict





@require_tf
class        lowerCAmelCase__					(  _lowerCamelCase ,				_lowerCamelCase ,				unittest.TestCase       ):
				A_   :     Tuple								=     (
				    (
				        TFEsmModel,
				        TFEsmForMaskedLM,
				        TFEsmForSequenceClassification,
				        TFEsmForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				A_   :     List[Any]								=     (
				    {
				        'feature-extraction': TFEsmModel,
				        'fill-mask': TFEsmForMaskedLM,
				        'text-classification': TFEsmForSequenceClassification,
				        'token-classification': TFEsmForTokenClassification,
				        'zero-shot': TFEsmForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				A_   :     Any								=     False
				A_   :     str								=     False


				def __UpperCamelCase						(							self      :  int       )		->     List[str]:
											A      						=    TFEsmModelTester(self       )
											A      						=    ConfigTester(self						, config_class=__UpperCamelCase						, hidden_size=37       )


				def __UpperCamelCase						(							self      :  Any       )		->     Union[str, Any]:
											self.config_tester.run_common_tests()


				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Union[str, Any]:
											A      						=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__UpperCamelCase       )


				def __UpperCamelCase						(							self      :  List[str]       )		->     List[str]:
											A      						=    self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_model_as_decoder(*__UpperCamelCase       )


				def __UpperCamelCase						(							self      :  List[Any]       )		->     int:
											A      						=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase       )


				def __UpperCamelCase						(							self      :  Dict       )		->     str:
											A      						=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase       )


				@slow
				def __UpperCamelCase						(							self      :  Tuple       )		->     str:
											for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		A      						=    TFEsmModel.from_pretrained(__UpperCamelCase       )
																		self.assertIsNotNone(__UpperCamelCase       )


				@unittest.skip('Protein models do not support embedding resizing.'       )
				def __UpperCamelCase						(							self      :  int       )		->     Union[str, Any]:
											pass


				@unittest.skip('Protein models do not support embedding resizing.'       )
				def __UpperCamelCase						(							self      :  List[Any]       )		->     Optional[int]:
											pass


				def __UpperCamelCase						(							self      :  Dict       )		->     Tuple:
											A						,   A      						=    self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		A      						=    model_class(__UpperCamelCase       )
																		assert isinstance(model.get_input_embeddings()						, tf.keras.layers.Layer       )
																		if model_class is TFEsmForMaskedLM:
																									# Output embedding test differs from the main test because they're a matrix, not a layer
																									A      						=    model.get_bias()
																									assert isinstance(__UpperCamelCase						, __UpperCamelCase       )
																									for k, v in name.items():
																																assert isinstance(__UpperCamelCase						, tf.Variable       )
																		else:
																									A      						=    model.get_output_embeddings()
																									assert x is None
																									A      						=    model.get_bias()
																									assert name is None





@require_tf
class        lowerCAmelCase__					(  unittest.TestCase       ):


				@slow
				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Optional[int]:
											A      						=    TFEsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D'       )

											A      						=    tf.constant([[0, 1, 2, 3, 4, 5]]       )
											A      						=    model(__UpperCamelCase       )[0]
											A      						=    [1, 6, 33]
											self.assertEqual(list(output.numpy().shape       )						, __UpperCamelCase       )
											# compare the actual values for a slice.
											A      						=    tf.constant(
											    [
											        [
											            [8.9_2_1_5_1_8, -1_0.5_8_9_8_1_4, -6.4_6_7_1_3_0_7],
											            [-6.3_9_6_7_1_5_6, -1_3.9_1_1_3_7_7, -1.1_2_1_1_9_1_5],
											            [-7.7_8_1_2_4_7, -1_3.9_5_1_5_5_7, -3.7_4_0_5_9_2],
											        ]
											    ]       )
											self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()						, expected_slice.numpy()						, atol=1e-2       )       )


				@slow
				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     List[Any]:
											A      						=    TFEsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D'       )

											A      						=    tf.constant([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]       )
											A      						=    model(__UpperCamelCase       )[0]
											# compare the actual values for a slice.
											A      						=    tf.constant(
											    [
											        [
											            [0.1_4_4_4_3_0_9_2, 0.5_4_1_2_5_3_2_7, 0.3_2_4_7_7_3_9],
											            [0.3_0_3_4_0_4_8_4, 0.0_0_5_2_6_6_7_6, 0.3_1_0_7_7_7_2_2],
											            [0.3_2_2_7_8_0_4_3, -0.2_4_9_8_7_0_9_6, 0.3_4_1_4_6_2_8],
											        ]
											    ]       )
											self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()						, expected_slice.numpy()						, atol=1e-4       )       )







"""simple docstring"""
import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, PNDMScheduler, StableDiffusionInpaintPipeline, UNetaDConditionModel
from diffusers.utils import floats_tensor, load_image, load_numpy, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, slow

from ..pipeline_params import TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS, TEXT_GUIDED_IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()


class _lowerCAmelCase						(    __UpperCAmelCase   ,  __UpperCAmelCase   ,  __UpperCAmelCase   ,  unittest.TestCase       ):
						SCREAMING_SNAKE_CASE_:					Optional[Any] 					=				StableDiffusionInpaintPipeline
						SCREAMING_SNAKE_CASE_:					List[str] 					=				TEXT_GUIDED_IMAGE_INPAINTING_PARAMS
						SCREAMING_SNAKE_CASE_:					Dict 					=				TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
						SCREAMING_SNAKE_CASE_:					Any 					=				frozenset(
						    []       )  # TO-DO: update image_params once pipeline is refactored with VaeImageProcessor.preprocess
						SCREAMING_SNAKE_CASE_:					Any 					=				frozenset([]       )







						def 			A      (    self							)		->							Optional[Any]:
										torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    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   ,				attention_head_dim=(2, 4)   ,				use_linear_projection=lowerCAmelCase_   ,				)
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    PNDMScheduler(skip_prk_steps=lowerCAmelCase_							)
										torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		Dict       		=    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   ,				sample_size=1_2_8   ,				)
										torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    CLIPTextConfig(
										    bos_token_id=0   ,				eos_token_id=2   ,				hidden_size=3_2   ,				intermediate_size=3_7   ,				layer_norm_eps=1e-05   ,				num_attention_heads=4   ,				num_hidden_layers=5   ,				pad_token_id=1   ,				vocab_size=1_0_0_0   ,				hidden_act='gelu'   ,				projection_dim=5_1_2   ,				)
										_SCREAMING_SNAKE_CASE   :		Dict       		=    CLIPTextModel(lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'							)

										_SCREAMING_SNAKE_CASE   :		Tuple       		=    {
										    'unet': unet,
										    'scheduler': scheduler,
										    'vae': vae,
										    'text_encoder': text_encoder,
										    'tokenizer': tokenizer,
										    'safety_checker': None,
										    'feature_extractor': None,
										}
										return components







						def 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_=0							)		->							Optional[int]:
										# TODO: use tensor inputs instead of PIL, this is here just to leave the old expected_slices untouched
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    floats_tensor((1, 3, 3_2, 3_2)   ,				rng=random.Random(lowerCAmelCase_							)							).to(lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    image.cpu().permute(0   ,				2   ,				3   ,				1							)[0]
										_SCREAMING_SNAKE_CASE   :		Any       		=    Image.fromarray(np.uinta(lowerCAmelCase_							)							).convert('RGB'							).resize((6_4, 6_4)							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    Image.fromarray(np.uinta(image + 4							)							).convert('RGB'							).resize((6_4, 6_4)							)
										if str(lowerCAmelCase_							).startswith('mps'							):
														_SCREAMING_SNAKE_CASE   :		List[str]       		=    torch.manual_seed(lowerCAmelCase_							)
										else:
														_SCREAMING_SNAKE_CASE   :		Tuple       		=    torch.Generator(device=lowerCAmelCase_							).manual_seed(lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    {
										    'prompt': 'A painting of a squirrel eating a burger',
										    'image': init_image,
										    'mask_image': mask_image,
										    'generator': generator,
										    'num_inference_steps': 2,
										    'guidance_scale': 6.0,
										    'output_type': 'numpy',
										}
										return inputs







						def 			A      (    self							)		->							str:
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    'cpu'  # ensure determinism for the device-dependent torch.Generator
										_SCREAMING_SNAKE_CASE   :		str       		=    self.get_dummy_components()
										_SCREAMING_SNAKE_CASE   :		Any       		=    StableDiffusionInpaintPipeline(**lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    sd_pipe.to(lowerCAmelCase_							)
										sd_pipe.set_progress_bar_config(disable=lowerCAmelCase_							)

										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    self.get_dummy_inputs(lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    sd_pipe(**lowerCAmelCase_							).images
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    image[0, -3:, -3:, -1]

										assert image.shape == (1, 6_4, 6_4, 3)
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    np.array([0.4_727, 0.5_735, 0.3_941, 0.5_446, 0.5_926, 0.4_394, 0.5_062, 0.4_654, 0.4_476]							)

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







						def 			A      (    self							)		->							str:
										super().test_inference_batch_single_identical(expected_max_diff=3e-3							)







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







						def 			A      (    self							)		->							Any:
										# clean up the VRAM after each test
										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()







						def 			A      (    self							)		->							Optional[int]:
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
										    '/sd2-inpaint/init_image.png'							)
										_SCREAMING_SNAKE_CASE   :		Any       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png'							)
										_SCREAMING_SNAKE_CASE   :		Dict       		=    load_numpy(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint'
										    '/yellow_cat_sitting_on_a_park_bench.npy'							)

										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    'stabilityai/stable-diffusion-2-inpainting'
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    StableDiffusionInpaintPipeline.from_pretrained(lowerCAmelCase_   ,				safety_checker=lowerCAmelCase_							)
										pipe.to(lowerCAmelCase_							)
										pipe.set_progress_bar_config(disable=lowerCAmelCase_							)
										pipe.enable_attention_slicing()

										_SCREAMING_SNAKE_CASE   :		List[str]       		=    'Face of a yellow cat, high resolution, sitting on a park bench'

										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    pipe(
										    prompt=lowerCAmelCase_   ,				image=lowerCAmelCase_   ,				mask_image=lowerCAmelCase_   ,				generator=lowerCAmelCase_   ,				output_type='np'   ,				)
										_SCREAMING_SNAKE_CASE   :		int       		=    output.images[0]

										assert image.shape == (5_1_2, 5_1_2, 3)
										assert np.abs(expected_image - image							).max() < 9e-3







						def 			A      (    self							)		->							int:
										_SCREAMING_SNAKE_CASE   :		Dict       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
										    '/sd2-inpaint/init_image.png'							)
										_SCREAMING_SNAKE_CASE   :		str       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png'							)
										_SCREAMING_SNAKE_CASE   :		int       		=    load_numpy(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint'
										    '/yellow_cat_sitting_on_a_park_bench_fp16.npy'							)

										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    'stabilityai/stable-diffusion-2-inpainting'
										_SCREAMING_SNAKE_CASE   :		str       		=    StableDiffusionInpaintPipeline.from_pretrained(
										    lowerCAmelCase_   ,				torch_dtype=torch.floataa   ,				safety_checker=lowerCAmelCase_   ,				)
										pipe.to(lowerCAmelCase_							)
										pipe.set_progress_bar_config(disable=lowerCAmelCase_							)
										pipe.enable_attention_slicing()

										_SCREAMING_SNAKE_CASE   :		str       		=    'Face of a yellow cat, high resolution, sitting on a park bench'

										_SCREAMING_SNAKE_CASE   :		Tuple       		=    torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    pipe(
										    prompt=lowerCAmelCase_   ,				image=lowerCAmelCase_   ,				mask_image=lowerCAmelCase_   ,				generator=lowerCAmelCase_   ,				output_type='np'   ,				)
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    output.images[0]

										assert image.shape == (5_1_2, 5_1_2, 3)
										assert np.abs(expected_image - image							).max() < 5e-1







						def 			A      (    self							)		->							List[str]:
										torch.cuda.empty_cache()
										torch.cuda.reset_max_memory_allocated()
										torch.cuda.reset_peak_memory_stats()

										_SCREAMING_SNAKE_CASE   :		str       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
										    '/sd2-inpaint/init_image.png'							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    load_image(
										    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png'							)

										_SCREAMING_SNAKE_CASE   :		str       		=    'stabilityai/stable-diffusion-2-inpainting'
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    PNDMScheduler.from_pretrained(lowerCAmelCase_   ,				subfolder='scheduler'							)
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    StableDiffusionInpaintPipeline.from_pretrained(
										    lowerCAmelCase_   ,				safety_checker=lowerCAmelCase_   ,				scheduler=lowerCAmelCase_   ,				torch_dtype=torch.floataa   ,				)
										pipe.to(lowerCAmelCase_							)
										pipe.set_progress_bar_config(disable=lowerCAmelCase_							)
										pipe.enable_attention_slicing(1							)
										pipe.enable_sequential_cpu_offload()

										_SCREAMING_SNAKE_CASE   :		str       		=    'Face of a yellow cat, high resolution, sitting on a park bench'

										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    torch.manual_seed(0							)
										_SCREAMING_SNAKE_CASE   :		Dict       		=    pipe(
										    prompt=lowerCAmelCase_   ,				image=lowerCAmelCase_   ,				mask_image=lowerCAmelCase_   ,				generator=lowerCAmelCase_   ,				num_inference_steps=2   ,				output_type='np'   ,				)

										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    torch.cuda.max_memory_allocated()
										# make sure that less than 2.65 GB is allocated
										assert mem_bytes < 2.65 * 1_0**9

