



"""simple docstring"""

def  __snake_case							(	__A      :						int     )     ->       int:






				'''simple docstring'''
				if not isinstance(__A							,		__A     ):
								raise ValueError('Input must be an integer'     )
				if input_num <= 0:
								raise ValueError('Input must be positive'     )
				return sum(
				    divisor for divisor in range(1							,		input_num // 2 + 1     ) if input_num % divisor == 0     )


if __name__ == "__main__":
							import doctest

							doctest.testmod()










"""simple docstring"""

import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


A_						:    Union[str, Any]				=      False
class     lowerCAmelCase__						(	unittest.TestCase ):


	'''simple docstring'''







	pass




@nightly
@require_torch_gpu
class     lowerCAmelCase__						(	unittest.TestCase ):


	'''simple docstring'''







	def 			_lowerCAmelCase     (      self				:       Any    )						->	List[str]:





					"""simple docstring"""


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





	def 			_lowerCAmelCase     (      self				:       Optional[Any]    )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     VersatileDiffusionTextToImagePipeline.from_pretrained('shi-labs/versatile-diffusion'    )
					# remove text_unet
					pipe.remove_unused_weights()
					pipe.to(_SCREAMING_SNAKE_CASE    )
					pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     'A painting of a squirrel eating a burger '
					SCREAMING_SNAKE_CASE						:							List[str]							=     torch.manual_seed(0    )
					SCREAMING_SNAKE_CASE						:							int							=     pipe(
					    prompt=_SCREAMING_SNAKE_CASE     ,       generator=_SCREAMING_SNAKE_CASE     ,       guidance_scale=7.5     ,       num_inference_steps=2     ,       output_type='numpy'    ).images

					with tempfile.TemporaryDirectory() as tmpdirname:
									pipe.save_pretrained(_SCREAMING_SNAKE_CASE    )
									SCREAMING_SNAKE_CASE						:							Dict							=     VersatileDiffusionTextToImagePipeline.from_pretrained(_SCREAMING_SNAKE_CASE    )
					pipe.to(_SCREAMING_SNAKE_CASE    )
					pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     generator.manual_seed(0    )
					SCREAMING_SNAKE_CASE						:							Tuple							=     pipe(
					    prompt=_SCREAMING_SNAKE_CASE     ,       generator=_SCREAMING_SNAKE_CASE     ,       guidance_scale=7.5     ,       num_inference_steps=2     ,       output_type='numpy'    ).images

					assert np.abs(image - new_image    ).sum() < 1E-5, "Models don't have the same forward pass"







	def 			_lowerCAmelCase     (      self				:       Dict    )						->	Dict:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							List[Any]							=     VersatileDiffusionTextToImagePipeline.from_pretrained(
					    'shi-labs/versatile-diffusion'     ,       torch_dtype=torch.floataa    )
					pipe.to(_SCREAMING_SNAKE_CASE    )
					pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Optional[int]							=     'A painting of a squirrel eating a burger '
					SCREAMING_SNAKE_CASE						:							Dict							=     torch.manual_seed(0    )
					SCREAMING_SNAKE_CASE						:							Any							=     pipe(
					    prompt=_SCREAMING_SNAKE_CASE     ,       generator=_SCREAMING_SNAKE_CASE     ,       guidance_scale=7.5     ,       num_inference_steps=50     ,       output_type='numpy'    ).images

					SCREAMING_SNAKE_CASE						:							Tuple							=     image[0, 253:256, 253:256, -1]

					assert image.shape == (1, 512, 512, 3)
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     np.array([0.3_3_6_7, 0.3_1_6_9, 0.2_6_5_6, 0.3_8_7_0, 0.4_7_9_0, 0.3_7_9_6, 0.4_0_0_9, 0.4_8_7_8, 0.4_7_7_8]    )

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





