





'''simple docstring'''



import math
import warnings
from dataclasses import dataclass
from typing import List, Optional, Tuple, Union

import numpy as np
import torch
from scipy import integrate

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin






@dataclass
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->LMSDiscrete
class 							__lowercase				(					lowerCAmelCase__  ):







	'''simple docstring'''

	a			: torch.FloatTensor
	a			: Optional[torch.FloatTensor]      =				None





def       _lowerCAmelCase  ( lowerCamelCase_	:     str						,				lowerCamelCase_	:     Dict=0.9_99						,				lowerCamelCase_	:     List[str]="cosine"						,				):
			if alpha_transform_type == "cosine":

						def alpha_bar_fn(lowerCamelCase_	:     List[Any] ):
									return math.cos((t + 0.0_08) / 1.0_08 * math.pi / 2 ) ** 2

			elif alpha_transform_type == "exp":

						def alpha_bar_fn(lowerCamelCase_	:     List[Any] ):
									return math.exp(t * -12.0 )

			else:
						raise ValueError(f"Unsupported alpha_tranform_type: {alpha_transform_type}" )

			__lowercase   =							[]
			for i in range(lowerCamelCase_ ):
						__lowercase   =							i / num_diffusion_timesteps
						__lowercase   =							(i + 1) / num_diffusion_timesteps
						betas.append(min(1 - alpha_bar_fn(lowerCamelCase_ ) / alpha_bar_fn(lowerCamelCase_ )						,				lowerCamelCase_ ) )
			return torch.tensor(lowerCamelCase_						,				dtype=torch.floataa )






class 							__lowercase				(					lowerCAmelCase__       ,					lowerCAmelCase__  ):







	'''simple docstring'''

	a			: Dict      =				[e.name for e in KarrasDiffusionSchedulers]
	a			: Dict      =				1


	@register_to_config
	def __init__(self   ,_lowerCamelCase = 1000   ,_lowerCamelCase = 0.0_0_0_1   ,_lowerCamelCase = 0.0_2   ,_lowerCamelCase = "linear"   ,_lowerCamelCase = None   ,_lowerCamelCase = False   ,_lowerCamelCase = "epsilon"   ,_lowerCamelCase = "linspace"   ,_lowerCamelCase = 0   ,)							->							Union[str, Any]:







				'''simple docstring'''





				if trained_betas is not None:
							__lowercase   =							torch.tensor(_lowerCamelCase   ,dtype=torch.floataa       )
				elif beta_schedule == "linear":
							__lowercase   =							torch.linspace(_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase   ,dtype=torch.floataa       )
				elif beta_schedule == "scaled_linear":
							# this schedule is very specific to the latent diffusion model.
							__lowercase   =							(
							    torch.linspace(beta_start**0.5   ,beta_end**0.5   ,_lowerCamelCase   ,dtype=torch.floataa       ) ** 2
							)
				elif beta_schedule == "squaredcos_cap_v2":
							# Glide cosine schedule
							__lowercase   =							betas_for_alpha_bar(_lowerCamelCase       )
				else:
							raise NotImplementedError(f"{beta_schedule} does is not implemented for {self.__class__}"       )

				__lowercase   =							1.0 - self.betas
				__lowercase   =							torch.cumprod(self.alphas   ,dim=0       )

				__lowercase   =							np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5       )
				__lowercase   =							np.concatenate([sigmas[::-1], [0.0]]       ).astype(np.floataa       )
				__lowercase   =							torch.from_numpy(_lowerCamelCase       )

				# setable values
				__lowercase   =							None
				__lowercase   =							use_karras_sigmas
				self.set_timesteps(_lowerCamelCase   ,_lowerCamelCase       )
				__lowercase   =							[]
				__lowercase   =							False


	@property
	def   _UpperCAmelCase   (self       )							->							Union[str, Any]:







				'''simple docstring'''





				if self.config.timestep_spacing in ["linspace", "trailing"]:
							return self.sigmas.max()

				return (self.sigmas.max() ** 2 + 1) ** 0.5


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase       )							->							torch.FloatTensor:







				'''simple docstring'''





				if isinstance(_lowerCamelCase   ,torch.Tensor       ):
							__lowercase   =							timestep.to(self.timesteps.device       )
				__lowercase   =							(self.timesteps == timestep).nonzero().item()
				__lowercase   =							self.sigmas[step_index]
				__lowercase   =							sample / ((sigma**2 + 1) ** 0.5)
				__lowercase   =							True
				return sample


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase       )							->							Tuple:







				'''simple docstring'''





				def lms_derivative(_lowerCamelCase       ):
							__lowercase   =							1.0
							for k in range(_lowerCamelCase       ):
										if current_order == k:
													continue
										prod *= (tau - self.sigmas[t - k]) / (self.sigmas[t - current_order] - self.sigmas[t - k])
							return prod

				__lowercase   =							integrate.quad(_lowerCamelCase   ,self.sigmas[t]   ,self.sigmas[t + 1]   ,epsrel=1E-4       )[0]

				return integrated_coeff


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase = None       )							->							List[str]:







				'''simple docstring'''





				__lowercase   =							num_inference_steps

				# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
				if self.config.timestep_spacing == "linspace":
							__lowercase   =							np.linspace(0   ,self.config.num_train_timesteps - 1   ,_lowerCamelCase   ,dtype=_lowerCamelCase       )[
							    ::-1
							].copy()
				elif self.config.timestep_spacing == "leading":
							__lowercase   =							self.config.num_train_timesteps // self.num_inference_steps
							# creates integer timesteps by multiplying by ratio
							# casting to int to avoid issues when num_inference_step is power of 3
							__lowercase   =							(np.arange(0   ,_lowerCamelCase       ) * step_ratio).round()[::-1].copy().astype(_lowerCamelCase       )
							timesteps += self.config.steps_offset
				elif self.config.timestep_spacing == "trailing":
							__lowercase   =							self.config.num_train_timesteps / self.num_inference_steps
							# creates integer timesteps by multiplying by ratio
							# casting to int to avoid issues when num_inference_step is power of 3
							__lowercase   =							(np.arange(self.config.num_train_timesteps   ,0   ,-step_ratio       )).round().copy().astype(_lowerCamelCase       )
							timesteps -= 1
				else:
							raise ValueError(
							    f"{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'."       )

				__lowercase   =							np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5       )
				__lowercase   =							np.log(_lowerCamelCase       )
				__lowercase   =							np.interp(_lowerCamelCase   ,np.arange(0   ,len(_lowerCamelCase       )       )   ,_lowerCamelCase       )

				if self.use_karras_sigmas:
							__lowercase   =							self._convert_to_karras(in_sigmas=_lowerCamelCase       )
							__lowercase   =							np.array([self._sigma_to_t(_lowerCamelCase   ,_lowerCamelCase       ) for sigma in sigmas]       )

				__lowercase   =							np.concatenate([sigmas, [0.0]]       ).astype(np.floataa       )

				__lowercase   =							torch.from_numpy(_lowerCamelCase       ).to(device=_lowerCamelCase       )
				if str(_lowerCamelCase       ).startswith('''mps'''       ):
							# mps does not support float64
							__lowercase   =							torch.from_numpy(_lowerCamelCase       ).to(_lowerCamelCase   ,dtype=torch.floataa       )
				else:
							__lowercase   =							torch.from_numpy(_lowerCamelCase       ).to(device=_lowerCamelCase       )

				__lowercase   =							[]


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase       )							->							Any:







				'''simple docstring'''





				__lowercase   =							np.log(_lowerCamelCase       )

				# get distribution
				__lowercase   =							log_sigma - log_sigmas[:, np.newaxis]

				# get sigmas range
				__lowercase   =							np.cumsum((dists >= 0)   ,axis=0       ).argmax(axis=0       ).clip(max=log_sigmas.shape[0] - 2       )
				__lowercase   =							low_idx + 1

				__lowercase   =							log_sigmas[low_idx]
				__lowercase   =							log_sigmas[high_idx]

				# interpolate sigmas
				__lowercase   =							(low - log_sigma) / (low - high)
				__lowercase   =							np.clip(_lowerCamelCase   ,0   ,1       )

				# transform interpolation to time range
				__lowercase   =							(1 - w) * low_idx + w * high_idx
				__lowercase   =							t.reshape(sigma.shape       )
				return t


	def   _UpperCAmelCase   (self   ,_lowerCamelCase       )							->							torch.FloatTensor:







				'''simple docstring'''





				__lowercase   =							in_sigmas[-1].item()
				__lowercase   =							in_sigmas[0].item()

				__lowercase   =							7.0  # 7.0 is the value used in the paper
				__lowercase   =							np.linspace(0   ,1   ,self.num_inference_steps       )
				__lowercase   =							sigma_min ** (1 / rho)
				__lowercase   =							sigma_max ** (1 / rho)
				__lowercase   =							(max_inv_rho + ramp * (min_inv_rho - max_inv_rho)) ** rho
				return sigmas


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase = 4   ,_lowerCamelCase = True   ,)							->							Union[LMSDiscreteSchedulerOutput, Tuple]:







				'''simple docstring'''





				if not self.is_scale_input_called:
							warnings.warn(
							    '''The `scale_model_input` function should be called before `step` to ensure correct denoising. '''
							    '''See `StableDiffusionPipeline` for a usage example.'''       )

				if isinstance(_lowerCamelCase   ,torch.Tensor       ):
							__lowercase   =							timestep.to(self.timesteps.device       )
				__lowercase   =							(self.timesteps == timestep).nonzero().item()
				__lowercase   =							self.sigmas[step_index]

				# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
				if self.config.prediction_type == "epsilon":
							__lowercase   =							sample - sigma * model_output
				elif self.config.prediction_type == "v_prediction":
							# * c_out + input * c_skip
							__lowercase   =							model_output * (-sigma / (sigma**2 + 1) ** 0.5) + (sample / (sigma**2 + 1))
				elif self.config.prediction_type == "sample":
							__lowercase   =							model_output
				else:
							raise ValueError(
							    f"prediction_type given as {self.config.prediction_type} must be one of `epsilon`, or `v_prediction`"       )

				# 2. Convert to an ODE derivative
				__lowercase   =							(sample - pred_original_sample) / sigma
				self.derivatives.append(_lowerCamelCase       )
				if len(self.derivatives       ) > order:
							self.derivatives.pop(0       )

				# 3. Compute linear multistep coefficients
				__lowercase   =							min(step_index + 1   ,_lowerCamelCase       )
				__lowercase   =							[self.get_lms_coefficient(_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase       ) for curr_order in range(_lowerCamelCase       )]

				# 4. Compute previous sample based on the derivatives path
				__lowercase   =							sample + sum(
				    coeff * derivative for coeff, derivative in zip(_lowerCamelCase   ,reversed(self.derivatives       )       )       )

				if not return_dict:
							return (prev_sample,)

				return LMSDiscreteSchedulerOutput(prev_sample=_lowerCamelCase   ,pred_original_sample=_lowerCamelCase       )


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase   ,_lowerCamelCase   ,)							->							torch.FloatTensor:







				'''simple docstring'''





				__lowercase   =							self.sigmas.to(device=original_samples.device   ,dtype=original_samples.dtype       )
				if original_samples.device.type == "mps" and torch.is_floating_point(_lowerCamelCase       ):
							# mps does not support float64
							__lowercase   =							self.timesteps.to(original_samples.device   ,dtype=torch.floataa       )
							__lowercase   =							timesteps.to(original_samples.device   ,dtype=torch.floataa       )
				else:
							__lowercase   =							self.timesteps.to(original_samples.device       )
							__lowercase   =							timesteps.to(original_samples.device       )

				__lowercase   =							[(schedule_timesteps == t).nonzero().item() for t in timesteps]

				__lowercase   =							sigmas[step_indices].flatten()
				while len(sigma.shape       ) < len(original_samples.shape       ):
							__lowercase   =							sigma.unsqueeze(-1       )

				__lowercase   =							original_samples + noise * sigma
				return noisy_samples


	def __len__(self       )							->							Optional[Any]:







				'''simple docstring'''





				return self.config.num_train_timesteps












'''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 							__lowercase				(					lowerCAmelCase__       ,					lowerCAmelCase__       ,					lowerCAmelCase__       ,					unittest.TestCase  ):







	'''simple docstring'''

	a			: str      =				StableDiffusionModelEditingPipeline
	a			: int      =				TEXT_TO_IMAGE_PARAMS
	a			: List[Any]      =				TEXT_TO_IMAGE_BATCH_PARAMS
	a			: Tuple      =				TEXT_TO_IMAGE_IMAGE_PARAMS
	a			: Any      =				TEXT_TO_IMAGE_IMAGE_PARAMS


	def   _UpperCAmelCase   (self       )							->							Dict:







				'''simple docstring'''





				torch.manual_seed(0       )
				__lowercase   =							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   ,)
				__lowercase   =							DDIMScheduler()
				torch.manual_seed(0       )
				__lowercase   =							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       )
				__lowercase   =							CLIPTextConfig(
				    bos_token_id=0   ,eos_token_id=2   ,hidden_size=32   ,intermediate_size=37   ,layer_norm_eps=1E-0_5   ,num_attention_heads=4   ,num_hidden_layers=5   ,pad_token_id=1   ,vocab_size=1000   ,)
				__lowercase   =							CLIPTextModel(_lowerCamelCase       )
				__lowercase   =							CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''       )

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


	def   _UpperCAmelCase   (self   ,_lowerCamelCase   ,_lowerCamelCase=0       )							->							Any:







				'''simple docstring'''





				__lowercase   =							torch.manual_seed(_lowerCamelCase       )
				__lowercase   =							{
				    '''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   _UpperCAmelCase   (self       )							->							Tuple:







				'''simple docstring'''





				__lowercase   =							'''cpu'''  # ensure determinism for the device-dependent torch.Generator
				__lowercase   =							self.get_dummy_components()
				__lowercase   =							StableDiffusionModelEditingPipeline(**_lowerCamelCase       )
				__lowercase   =							sd_pipe.to(_lowerCamelCase       )
				sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

				__lowercase   =							self.get_dummy_inputs(_lowerCamelCase       )
				__lowercase   =							sd_pipe(**_lowerCamelCase       ).images
				__lowercase   =							image[0, -3:, -3:, -1]
				assert image.shape == (1, 64, 64, 3)

				__lowercase   =							np.array([0.4_7_5_5, 0.5_1_3_2, 0.4_9_7_6, 0.3_9_0_4, 0.3_5_5_4, 0.4_7_6_5, 0.5_1_3_9, 0.5_1_5_8, 0.4_8_8_9]       )

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


	def   _UpperCAmelCase   (self       )							->							Optional[int]:







				'''simple docstring'''





				__lowercase   =							'''cpu'''  # ensure determinism for the device-dependent torch.Generator
				__lowercase   =							self.get_dummy_components()
				__lowercase   =							StableDiffusionModelEditingPipeline(**_lowerCamelCase       )
				__lowercase   =							sd_pipe.to(_lowerCamelCase       )
				sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

				__lowercase   =							self.get_dummy_inputs(_lowerCamelCase       )
				__lowercase   =							'''french fries'''
				__lowercase   =							sd_pipe(**_lowerCamelCase   ,negative_prompt=_lowerCamelCase       )
				__lowercase   =							output.images
				__lowercase   =							image[0, -3:, -3:, -1]

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

				__lowercase   =							np.array([0.4_9_9_2, 0.5_1_0_1, 0.5_0_0_4, 0.3_9_4_9, 0.3_6_0_4, 0.4_7_3_5, 0.5_2_1_6, 0.5_2_0_4, 0.4_9_1_3]       )

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


	def   _UpperCAmelCase   (self       )							->							Tuple:







				'''simple docstring'''





				__lowercase   =							'''cpu'''  # ensure determinism for the device-dependent torch.Generator
				__lowercase   =							self.get_dummy_components()
				__lowercase   =							EulerAncestralDiscreteScheduler(
				    beta_start=0.0_0_0_8_5   ,beta_end=0.0_1_2   ,beta_schedule='''scaled_linear'''       )
				__lowercase   =							StableDiffusionModelEditingPipeline(**_lowerCamelCase       )
				__lowercase   =							sd_pipe.to(_lowerCamelCase       )
				sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

				__lowercase   =							self.get_dummy_inputs(_lowerCamelCase       )
				__lowercase   =							sd_pipe(**_lowerCamelCase       ).images
				__lowercase   =							image[0, -3:, -3:, -1]

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

				__lowercase   =							np.array([0.4_7_4_7, 0.5_3_7_2, 0.4_7_7_9, 0.4_9_8_2, 0.5_5_4_3, 0.4_8_1_6, 0.5_2_3_8, 0.4_9_0_4, 0.5_0_2_7]       )

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


	def   _UpperCAmelCase   (self       )							->							Optional[int]:







				'''simple docstring'''





				__lowercase   =							'''cpu'''  # ensure determinism for the device-dependent torch.Generator
				__lowercase   =							self.get_dummy_components()
				__lowercase   =							PNDMScheduler()
				__lowercase   =							StableDiffusionModelEditingPipeline(**_lowerCamelCase       )
				__lowercase   =							sd_pipe.to(_lowerCamelCase       )
				sd_pipe.set_progress_bar_config(disable=_lowerCamelCase       )

				__lowercase   =							self.get_dummy_inputs(_lowerCamelCase       )
				# the pipeline does not expect pndm so test if it raises error.
				with self.assertRaises(_lowerCamelCase       ):
							__lowercase   =							sd_pipe(**_lowerCamelCase       ).images


	def   _UpperCAmelCase   (self       )							->							int:







				'''simple docstring'''





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


	def   _UpperCAmelCase   (self       )							->							str:







				'''simple docstring'''





				super().test_attention_slicing_forward_pass(expected_max_diff=5E-3       )






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







	'''simple docstring'''

	def   _UpperCAmelCase   (self       )							->							List[str]:







				'''simple docstring'''





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


	def   _UpperCAmelCase   (self   ,_lowerCamelCase=0       )							->							Any:







				'''simple docstring'''





				__lowercase   =							torch.manual_seed(_lowerCamelCase       )
				__lowercase   =							{
				    '''prompt''': '''A field of roses''',
				    '''generator''': generator,
				    '''num_inference_steps''': 3,
				    '''guidance_scale''': 7.5,
				    '''output_type''': '''numpy''',
				}
				return inputs


	def   _UpperCAmelCase   (self       )							->							str:







				'''simple docstring'''





				__lowercase   =							'''CompVis/stable-diffusion-v1-4'''
				__lowercase   =							StableDiffusionModelEditingPipeline.from_pretrained(_lowerCamelCase   ,safety_checker=_lowerCamelCase       )
				pipe.to(_lowerCamelCase       )
				pipe.set_progress_bar_config(disable=_lowerCamelCase       )
				pipe.enable_attention_slicing()

				__lowercase   =							self.get_inputs()
				__lowercase   =							pipe(**_lowerCamelCase       ).images
				__lowercase   =							image[0, -3:, -3:, -1].flatten()

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

				__lowercase   =							np.array(
				    [0.6_7_4_9_4_9_6, 0.6_3_8_6_4_5_3, 0.5_1_4_4_3_2_6_7, 0.6_6_0_9_4_9_0_5, 0.6_1_9_2_1_2_1_5, 0.5_4_9_1_3_3_2, 0.5_7_4_4_4_1_7, 0.5_8_0_7_5_1_0_6, 0.5_1_7_4_6_5_8]       )

				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'''       )

				__lowercase   =							pipe(**_lowerCamelCase       ).images
				__lowercase   =							image[0, -3:, -3:, -1].flatten()

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

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


	def   _UpperCAmelCase   (self       )							->							List[str]:







				'''simple docstring'''





				torch.cuda.empty_cache()
				torch.cuda.reset_max_memory_allocated()
				torch.cuda.reset_peak_memory_stats()

				__lowercase   =							'''CompVis/stable-diffusion-v1-4'''
				__lowercase   =							DDIMScheduler.from_pretrained(_lowerCamelCase   ,subfolder='''scheduler'''       )
				__lowercase   =							StableDiffusionModelEditingPipeline.from_pretrained(
				    _lowerCamelCase   ,scheduler=_lowerCamelCase   ,safety_checker=_lowerCamelCase       )
				__lowercase   =							pipe.to(_lowerCamelCase       )
				pipe.set_progress_bar_config(disable=_lowerCamelCase       )
				pipe.enable_attention_slicing(1       )
				pipe.enable_sequential_cpu_offload()

				__lowercase   =							self.get_inputs()
				__lowercase   =							pipe(**_lowerCamelCase       )

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





