



"""simple docstring"""


from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    get_resize_output_image_size,
    normalize,
    pad,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging
from ...utils.import_utils import is_vision_available


snake_case_								=			logging.get_logger(__name__)


if is_vision_available():
				import PIL







class  A_     (	SCREAMING_SNAKE_CASE_							):



						"""simple docstring"""
						__UpperCamelCase													=				["""pixel_values"""]






						def __init__(   self					:Tuple  ,    lowercase_					:bool = True  ,    lowercase_					:Dict[str, int] = None  ,    lowercase_					:PILImageResampling = PILImageResampling.BILINEAR  ,    lowercase_					:bool = True  ,    lowercase_					:bool = False  ,    lowercase_					:bool = True  ,    lowercase_					:bool = True  ,    lowercase_					:Union[int, float] = 1 / 2_55  ,    lowercase_					:bool = True  ,    lowercase_					:Optional[Union[float, List[float]]] = None  ,    lowercase_					:Optional[Union[float, List[float]]] = None  ,    **lowercase_					:Optional[int]  ,    )							->     None:
												super().__init__(**lowercase_   )

												UpperCAmelCase			 =					size if size is not None else {'height': 25_60, 'width': 19_20}
												if isinstance(lowercase_  ,    (tuple, list)   ):
																		# The previous feature extractor size parameter was in (width, height) format
																		UpperCAmelCase			 =					size[::-1]
												UpperCAmelCase			 =					get_size_dict(lowercase_   )

												UpperCAmelCase			 =					do_resize
												UpperCAmelCase			 =					size
												UpperCAmelCase			 =					resample
												UpperCAmelCase			 =					do_thumbnail
												UpperCAmelCase			 =					do_align_long_axis
												UpperCAmelCase			 =					do_pad
												UpperCAmelCase			 =					do_rescale
												UpperCAmelCase			 =					rescale_factor
												UpperCAmelCase			 =					do_normalize
												UpperCAmelCase			 =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
												UpperCAmelCase			 =					image_std if image_std is not None else IMAGENET_STANDARD_STD






						def       UpperCAmelCase__	(   self					:List[str]  ,    lowercase_					:np.ndarray  ,    lowercase_					:Dict[str, int]  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None   )							->     np.ndarray:
												UpperCAmelCase ,       UpperCAmelCase			 =					get_image_size(lowercase_   )
												UpperCAmelCase ,       UpperCAmelCase			 =					size['height'], size['width']

												if (output_width < output_height and input_width > input_height) or (
												    output_width > output_height and input_width < input_height
												):
																		UpperCAmelCase			 =					np.rotaa(lowercase_  ,    3   )

												if data_format is not None:
																		UpperCAmelCase			 =					to_channel_dimension_format(lowercase_  ,    lowercase_   )

												return image






						def       UpperCAmelCase__	(   self					:List[Any]  ,    lowercase_					:np.ndarray  ,    lowercase_					:Dict[str, int]  ,    lowercase_					:bool = False  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None  ,    )							->     np.ndarray:
												UpperCAmelCase ,       UpperCAmelCase			 =					size['height'], size['width']
												UpperCAmelCase ,       UpperCAmelCase			 =					get_image_size(lowercase_   )

												UpperCAmelCase			 =					output_width - input_width
												UpperCAmelCase			 =					output_height - input_height

												if random_padding:
																		UpperCAmelCase			 =					np.random.randint(low=0  ,    high=delta_height + 1   )
																		UpperCAmelCase			 =					np.random.randint(low=0  ,    high=delta_width + 1   )
												else:
																		UpperCAmelCase			 =					delta_height // 2
																		UpperCAmelCase			 =					delta_width // 2

												UpperCAmelCase			 =					delta_height - pad_top
												UpperCAmelCase			 =					delta_width - pad_left

												UpperCAmelCase			 =					((pad_top, pad_bottom), (pad_left, pad_right))
												return pad(lowercase_  ,    lowercase_  ,    data_format=lowercase_   )






						def       UpperCAmelCase__	(   self					:Union[str, Any]  ,    *lowercase_					:Dict  ,    **lowercase_					:int   )							->     int:
												logger.info('pad is deprecated and will be removed in version 4.27. Please use pad_image instead.'   )
												return self.pad_image(*lowercase_  ,    **lowercase_   )






						def       UpperCAmelCase__	(   self					:Tuple  ,    lowercase_					:np.ndarray  ,    lowercase_					:Dict[str, int]  ,    lowercase_					:PILImageResampling = PILImageResampling.BICUBIC  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None  ,    **lowercase_					:int  ,    )							->     np.ndarray:
												UpperCAmelCase ,       UpperCAmelCase			 =					get_image_size(lowercase_   )
												UpperCAmelCase ,       UpperCAmelCase			 =					size['height'], size['width']

												# We always resize to the smallest of either the input or output size.
												UpperCAmelCase			 =					min(lowercase_  ,    lowercase_   )
												UpperCAmelCase			 =					min(lowercase_  ,    lowercase_   )

												if height == input_height and width == input_width:
																		return image

												if input_height > input_width:
																		UpperCAmelCase			 =					int(input_width * height / input_height   )
												elif input_width > input_height:
																		UpperCAmelCase			 =					int(input_height * width / input_width   )

												return resize(
												    lowercase_  ,    size=(height, width)  ,    resample=lowercase_  ,    reducing_gap=2.0  ,    data_format=lowercase_  ,    **lowercase_   )






						def       UpperCAmelCase__	(   self					:Union[str, Any]  ,    lowercase_					:np.ndarray  ,    lowercase_					:Dict[str, int]  ,    lowercase_					:PILImageResampling = PILImageResampling.BICUBIC  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None  ,    **lowercase_					:int  ,    )							->     np.ndarray:
												UpperCAmelCase			 =					get_size_dict(lowercase_   )
												UpperCAmelCase			 =					min(size['height']  ,    size['width']   )
												UpperCAmelCase			 =					get_resize_output_image_size(lowercase_  ,    size=lowercase_  ,    default_to_square=lowercase_   )
												UpperCAmelCase			 =					resize(lowercase_  ,    size=lowercase_  ,    resample=lowercase_  ,    data_format=lowercase_  ,    **lowercase_   )
												return resized_image






						def       UpperCAmelCase__	(   self					:Optional[Any]  ,    lowercase_					:np.ndarray  ,    lowercase_					:Union[int, float]  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None  ,    **lowercase_					:List[Any]  ,    )							->     List[str]:
												return rescale(lowercase_  ,    scale=lowercase_  ,    data_format=lowercase_  ,    **lowercase_   )






						def       UpperCAmelCase__	(   self					:List[Any]  ,    lowercase_					:np.ndarray  ,    lowercase_					:Union[float, List[float]]  ,    lowercase_					:Union[float, List[float]]  ,    lowercase_					:Optional[Union[str, ChannelDimension]] = None  ,    **lowercase_					:Optional[int]  ,    )							->     np.ndarray:
												return normalize(lowercase_  ,    mean=lowercase_  ,    std=lowercase_  ,    data_format=lowercase_  ,    **lowercase_   )






						def       UpperCAmelCase__	(   self					:Any  ,    lowercase_					:ImageInput  ,    lowercase_					:bool = None  ,    lowercase_					:Dict[str, int] = None  ,    lowercase_					:PILImageResampling = None  ,    lowercase_					:bool = None  ,    lowercase_					:bool = None  ,    lowercase_					:bool = None  ,    lowercase_					:bool = False  ,    lowercase_					:bool = None  ,    lowercase_					:float = None  ,    lowercase_					:bool = None  ,    lowercase_					:Optional[Union[float, List[float]]] = None  ,    lowercase_					:Optional[Union[float, List[float]]] = None  ,    lowercase_					:Optional[Union[str, TensorType]] = None  ,    lowercase_					:Optional[ChannelDimension] = ChannelDimension.FIRST  ,    **lowercase_					:List[str]  ,    )							->     PIL.Image.Image:
												UpperCAmelCase			 =					do_resize if do_resize is not None else self.do_resize
												UpperCAmelCase			 =					size if size is not None else self.size
												if isinstance(lowercase_  ,    (tuple, list)   ):
																		# Previous feature extractor had size in (width, height) format
																		UpperCAmelCase			 =					size[::-1]
												UpperCAmelCase			 =					get_size_dict(lowercase_   )
												UpperCAmelCase			 =					resample if resample is not None else self.resample
												UpperCAmelCase			 =					do_thumbnail if do_thumbnail is not None else self.do_thumbnail
												UpperCAmelCase			 =					do_align_long_axis if do_align_long_axis is not None else self.do_align_long_axis
												UpperCAmelCase			 =					do_pad if do_pad is not None else self.do_pad
												UpperCAmelCase			 =					do_rescale if do_rescale is not None else self.do_rescale
												UpperCAmelCase			 =					rescale_factor if rescale_factor is not None else self.rescale_factor
												UpperCAmelCase			 =					do_normalize if do_normalize is not None else self.do_normalize
												UpperCAmelCase			 =					image_mean if image_mean is not None else self.image_mean
												UpperCAmelCase			 =					image_std if image_std is not None else self.image_std

												UpperCAmelCase			 =					make_list_of_images(lowercase_   )

												if not valid_images(lowercase_   ):
																		raise ValueError(
																		    'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
																		    'torch.Tensor, tf.Tensor or jax.ndarray.'   )

												if do_resize and size is None:
																		raise ValueError('Size must be specified if do_resize is True.'   )

												if do_rescale and rescale_factor is None:
																		raise ValueError('Rescale factor must be specified if do_rescale is True.'   )

												if do_pad and size is None:
																		raise ValueError('Size must be specified if do_pad is True.'   )

												if do_normalize and (image_mean is None or image_std is None):
																		raise ValueError('Image mean and std must be specified if do_normalize is True.'   )

												# All transformations expect numpy arrays.
												UpperCAmelCase			 =					[to_numpy_array(lowercase_   ) for image in images]

												if do_align_long_axis:
																		UpperCAmelCase			 =					[self.align_long_axis(lowercase_  ,    size=lowercase_   ) for image in images]

												if do_resize:
																		UpperCAmelCase			 =					[self.resize(image=lowercase_  ,    size=lowercase_  ,    resample=lowercase_   ) for image in images]

												if do_thumbnail:
																		UpperCAmelCase			 =					[self.thumbnail(image=lowercase_  ,    size=lowercase_   ) for image in images]

												if do_pad:
																		UpperCAmelCase			 =					[self.pad_image(image=lowercase_  ,    size=lowercase_  ,    random_padding=lowercase_   ) for image in images]

												if do_rescale:
																		UpperCAmelCase			 =					[self.rescale(image=lowercase_  ,    scale=lowercase_   ) for image in images]

												if do_normalize:
																		UpperCAmelCase			 =					[self.normalize(image=lowercase_  ,    mean=lowercase_  ,    std=lowercase_   ) for image in images]

												UpperCAmelCase			 =					[to_channel_dimension_format(lowercase_  ,    lowercase_   ) for image in images]

												UpperCAmelCase			 =					{'pixel_values': images}
												return BatchFeature(data=lowercase_  ,    tensor_type=lowercase_   )













'''simple docstring'''







import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionModelEditingPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()




@skip_mps
class 					__UpperCAmelCase (		UpperCamelCase__      ,				UpperCamelCase__      ,				UpperCamelCase__      ,				unittest.TestCase	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    Optional[Any]				       =					StableDiffusionModelEditingPipeline
      SCREAMING_SNAKE_CASE				:    str				       =					TEXT_TO_IMAGE_PARAMS
      SCREAMING_SNAKE_CASE				:    Union[str, Any]				       =					TEXT_TO_IMAGE_BATCH_PARAMS
      SCREAMING_SNAKE_CASE				:    Dict				       =					TEXT_TO_IMAGE_IMAGE_PARAMS
      SCREAMING_SNAKE_CASE				:    Optional[int]				       =					TEXT_TO_IMAGE_IMAGE_PARAMS




      def 							lowerCamelCase     (					self						):
             torch.manual_seed(0						)
             UpperCAmelCase__	:   List[Any]												=	UNetaDConditionModel(
                 block_out_channels=(32, 64)  ,		layers_per_block=2  ,		sample_size=32  ,		in_channels=4  ,		out_channels=4  ,		down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')  ,		up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')  ,		cross_attention_dim=32  ,		)
             UpperCAmelCase__	:   List[str]												=	DDIMScheduler()
             torch.manual_seed(0						)
             UpperCAmelCase__	:   str												=	AutoencoderKL(
                 block_out_channels=[32, 64]  ,		in_channels=3  ,		out_channels=3  ,		down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']  ,		up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']  ,		latent_channels=4  ,		)
             torch.manual_seed(0						)
             UpperCAmelCase__	:   Optional[int]												=	CLIPTextConfig(
                 bos_token_id=0  ,		eos_token_id=2  ,		hidden_size=32  ,		intermediate_size=37  ,		layer_norm_eps=1E-05  ,		num_attention_heads=4  ,		num_hidden_layers=5  ,		pad_token_id=1  ,		vocab_size=1000  ,		)
             UpperCAmelCase__	:   Optional[int]												=	CLIPTextModel(_UpperCAmelCase						)
             UpperCAmelCase__	:   Optional[Any]												=	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''						)

             UpperCAmelCase__	:   List[str]												=	{
                 '''unet''': unet,
                 '''scheduler''': scheduler,
                 '''vae''': vae,
                 '''text_encoder''': text_encoder,
                 '''tokenizer''': tokenizer,
                 '''safety_checker''': None,
                 '''feature_extractor''': None,
             }
             return components




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase=0						):
             UpperCAmelCase__	:   Tuple												=	torch.manual_seed(_UpperCAmelCase						)
             UpperCAmelCase__	:   Dict												=	{
                 '''prompt''': '''A field of roses''',
                 '''generator''': generator,
                 # Setting height and width to None to prevent OOMs on CPU.
                 '''height''': None,
                 '''width''': None,
                 '''num_inference_steps''': 2,
                 '''guidance_scale''': 6.0,
                 '''output_type''': '''numpy''',
             }
             return inputs




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[str]												=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   Union[str, Any]												=	self.get_dummy_components()
             UpperCAmelCase__	:   Optional[int]												=	StableDiffusionModelEditingPipeline(**_UpperCAmelCase						)
             UpperCAmelCase__	:   Union[str, Any]												=	sd_pipe.to(_UpperCAmelCase						)
             sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

             UpperCAmelCase__	:   Any												=	self.get_dummy_inputs(_UpperCAmelCase						)
             UpperCAmelCase__	:   Dict												=	sd_pipe(**_UpperCAmelCase						).images
             UpperCAmelCase__	:   Tuple												=	image[0, -3:, -3:, -1]
             assert image.shape == (1, 64, 64, 3)

             UpperCAmelCase__	:   int												=	np.array([0.47_55, 0.51_32, 0.49_76, 0.39_04, 0.35_54, 0.47_65, 0.51_39, 0.51_58, 0.48_89]						)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   int												=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   List[str]												=	self.get_dummy_components()
             UpperCAmelCase__	:   Tuple												=	StableDiffusionModelEditingPipeline(**_UpperCAmelCase						)
             UpperCAmelCase__	:   List[Any]												=	sd_pipe.to(_UpperCAmelCase						)
             sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

             UpperCAmelCase__	:   str												=	self.get_dummy_inputs(_UpperCAmelCase						)
             UpperCAmelCase__	:   List[Any]												=	'''french fries'''
             UpperCAmelCase__	:   Any												=	sd_pipe(**_UpperCAmelCase  ,		negative_prompt=_UpperCAmelCase						)
             UpperCAmelCase__	:   Dict												=	output.images
             UpperCAmelCase__	:   Tuple												=	image[0, -3:, -3:, -1]

             assert image.shape == (1, 64, 64, 3)

             UpperCAmelCase__	:   str												=	np.array([0.49_92, 0.51_01, 0.50_04, 0.39_49, 0.36_04, 0.47_35, 0.52_16, 0.52_04, 0.49_13]						)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   List[Any]												=	self.get_dummy_components()
             UpperCAmelCase__	:   str												=	EulerAncestralDiscreteScheduler(
                 beta_start=0.0_00_85  ,		beta_end=0.0_12  ,		beta_schedule='''scaled_linear'''						)
             UpperCAmelCase__	:   Tuple												=	StableDiffusionModelEditingPipeline(**_UpperCAmelCase						)
             UpperCAmelCase__	:   Optional[int]												=	sd_pipe.to(_UpperCAmelCase						)
             sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

             UpperCAmelCase__	:   Optional[Any]												=	self.get_dummy_inputs(_UpperCAmelCase						)
             UpperCAmelCase__	:   int												=	sd_pipe(**_UpperCAmelCase						).images
             UpperCAmelCase__	:   List[str]												=	image[0, -3:, -3:, -1]

             assert image.shape == (1, 64, 64, 3)

             UpperCAmelCase__	:   Tuple												=	np.array([0.47_47, 0.53_72, 0.47_79, 0.49_82, 0.55_43, 0.48_16, 0.52_38, 0.49_04, 0.50_27]						)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   str												=	self.get_dummy_components()
             UpperCAmelCase__	:   List[Any]												=	PNDMScheduler()
             UpperCAmelCase__	:   Tuple												=	StableDiffusionModelEditingPipeline(**_UpperCAmelCase						)
             UpperCAmelCase__	:   Optional[int]												=	sd_pipe.to(_UpperCAmelCase						)
             sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

             UpperCAmelCase__	:   Tuple												=	self.get_dummy_inputs(_UpperCAmelCase						)
             # the pipeline does not expect pndm so test if it raises error.
             with self.assertRaises(_UpperCAmelCase						):
                    UpperCAmelCase__	:   List[Any]												=	sd_pipe(**_UpperCAmelCase						).images




      def 							lowerCamelCase     (					self						):
             super().test_inference_batch_single_identical(expected_max_diff=5E-3						)




      def 							lowerCamelCase     (					self						):
             super().test_attention_slicing_forward_pass(expected_max_diff=5E-3						)




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

      '''simple docstring'''





      def 							lowerCamelCase     (					self						):
             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase=0						):
             UpperCAmelCase__	:   Dict												=	torch.manual_seed(_UpperCAmelCase						)
             UpperCAmelCase__	:   Union[str, Any]												=	{
                 '''prompt''': '''A field of roses''',
                 '''generator''': generator,
                 '''num_inference_steps''': 3,
                 '''guidance_scale''': 7.5,
                 '''output_type''': '''numpy''',
             }
             return inputs




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[str]												=	'''CompVis/stable-diffusion-v1-4'''
             UpperCAmelCase__	:   List[str]												=	StableDiffusionModelEditingPipeline.from_pretrained(_UpperCAmelCase  ,		safety_checker=_UpperCAmelCase						)
             pipe.to(_UpperCAmelCase						)
             pipe.set_progress_bar_config(disable=_UpperCAmelCase						)
             pipe.enable_attention_slicing()

             UpperCAmelCase__	:   Union[str, Any]												=	self.get_inputs()
             UpperCAmelCase__	:   Union[str, Any]												=	pipe(**_UpperCAmelCase						).images
             UpperCAmelCase__	:   Optional[int]												=	image[0, -3:, -3:, -1].flatten()

             assert image.shape == (1, 512, 512, 3)

             UpperCAmelCase__	:   List[str]												=	np.array(
                 [0.6_74_94_96, 0.6_38_64_53, 0.51_44_32_67, 0.66_09_49_05, 0.61_92_12_15, 0.5_49_13_32, 0.5_74_44_17, 0.58_07_51_06, 0.5_17_46_58]						)

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

             # make sure image changes after editing
             pipe.edit_model('''A pack of roses'''  ,		'''A pack of blue roses'''						)

             UpperCAmelCase__	:   Optional[int]												=	pipe(**_UpperCAmelCase						).images
             UpperCAmelCase__	:   List[str]												=	image[0, -3:, -3:, -1].flatten()

             assert image.shape == (1, 512, 512, 3)

             assert np.abs(expected_slice - image_slice						).max() > 1E-1




      def 							lowerCamelCase     (					self						):
             torch.cuda.empty_cache()
             torch.cuda.reset_max_memory_allocated()
             torch.cuda.reset_peak_memory_stats()

             UpperCAmelCase__	:   Dict												=	'''CompVis/stable-diffusion-v1-4'''
             UpperCAmelCase__	:   int												=	DDIMScheduler.from_pretrained(_UpperCAmelCase  ,		subfolder='''scheduler'''						)
             UpperCAmelCase__	:   int												=	StableDiffusionModelEditingPipeline.from_pretrained(
                 _UpperCAmelCase  ,		scheduler=_UpperCAmelCase  ,		safety_checker=_UpperCAmelCase						)
             UpperCAmelCase__	:   Tuple												=	pipe.to(_UpperCAmelCase						)
             pipe.set_progress_bar_config(disable=_UpperCAmelCase						)
             pipe.enable_attention_slicing(1						)
             pipe.enable_sequential_cpu_offload()

             UpperCAmelCase__	:   Any												=	self.get_inputs()
             UpperCAmelCase__	:   Any												=	pipe(**_UpperCAmelCase						)

             UpperCAmelCase__	:   Any												=	torch.cuda.max_memory_allocated()
             # make sure that less than 4.4 GB is allocated
             assert mem_bytes < 4.4 * 10**9