


"""simple docstring"""






class       lowerCamelCase_		:





				"""simple docstring"""







				class       lowerCamelCase_		:





								"""simple docstring"""







								_lowerCAmelCase   :   Dict   				=       "_prev", "_data", "_next"



								def __init__(    self							,		UpperCAmelCase__							,		UpperCAmelCase__							,		UpperCAmelCase__  ):
												SCREAMING_SNAKE_CASE__  				=					link_p
												SCREAMING_SNAKE_CASE__  				=					element
												SCREAMING_SNAKE_CASE__  				=					link_n






								def 	lowerCAmelCase__		(    self  ):
												return (
												    f''' Prev -> {self._prev is not None}, Next -> {self._next is not None}'''
												)



				def __init__(    self  ):
								SCREAMING_SNAKE_CASE__  				=					self._Node(UpperCAmelCase__							,		UpperCAmelCase__							,		UpperCAmelCase__  )
								SCREAMING_SNAKE_CASE__  				=					self._Node(UpperCAmelCase__							,		UpperCAmelCase__							,		UpperCAmelCase__  )
								SCREAMING_SNAKE_CASE__  				=					self._trailer
								SCREAMING_SNAKE_CASE__  				=					self._header
								SCREAMING_SNAKE_CASE__  				=					0



				def __len__(    self  ):
								return self._size



				def 	lowerCAmelCase__		(    self  ):
								return self.__len__() == 0



				def 	lowerCAmelCase__		(    self							,		UpperCAmelCase__							,		UpperCAmelCase__							,		UpperCAmelCase__  ):
								# Create new_node by setting it's prev.link -> header
								# setting it's next.link -> trailer
								SCREAMING_SNAKE_CASE__  				=					self._Node(UpperCAmelCase__							,		UpperCAmelCase__							,		UpperCAmelCase__  )
								SCREAMING_SNAKE_CASE__  				=					new_node
								SCREAMING_SNAKE_CASE__  				=					new_node
								self._size += 1
								return self






				def 	lowerCAmelCase__		(    self							,		UpperCAmelCase__  ):
								SCREAMING_SNAKE_CASE__  				=					node._prev
								SCREAMING_SNAKE_CASE__  				=					node._next

								SCREAMING_SNAKE_CASE__  				=					successor
								SCREAMING_SNAKE_CASE__  				=					predecessor
								self._size -= 1
								SCREAMING_SNAKE_CASE__  				=					node._data
								SCREAMING_SNAKE_CASE__  				=					SCREAMING_SNAKE_CASE__  				=					SCREAMING_SNAKE_CASE__  				=					None
								del node
								return temp


class       lowerCamelCase_		(      _DoublyLinkedBase ):





				"""simple docstring"""







				def 	lowerCAmelCase__		(    self  ):
								if self.is_empty():
												raise Exception("List is empty"  )
								return self._header._next._data



				def 	lowerCAmelCase__		(    self  ):
								if self.is_empty():
												raise Exception("List is empty"  )
								return self._trailer._prev._data



				def 	lowerCAmelCase__		(    self							,		UpperCAmelCase__  ):
								return self._insert(self._header							,		UpperCAmelCase__							,		self._header._next  )



				def 	lowerCAmelCase__		(    self							,		UpperCAmelCase__  ):
								return self._insert(self._trailer._prev							,		UpperCAmelCase__							,		self._trailer  )



				def 	lowerCAmelCase__		(    self  ):
								if self.is_empty():
												raise IndexError("remove_first from empty list"  )
								return self._delete(self._header._next  )






				def 	lowerCAmelCase__		(    self  ):
								if self.is_empty():
												raise IndexError("remove_first from empty list"  )
								return self._delete(self._trailer._prev  )




"""simple docstring"""






import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


_lowerCamelCase  =	False


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





				"""simple docstring"""







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



				def 	lowerCAmelCase__		(    self  ):
								SCREAMING_SNAKE_CASE__  				=					VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"  )
								# remove text_unet
								pipe.remove_unused_weights()
								pipe.to(UpperCAmelCase__  )
								pipe.set_progress_bar_config(disable=UpperCAmelCase__  )

								SCREAMING_SNAKE_CASE__  				=					load_image(
								    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"  )

								SCREAMING_SNAKE_CASE__  				=					torch.manual_seed(0  )
								SCREAMING_SNAKE_CASE__  				=					pipe(
								    prompt="first prompt"							,		image=UpperCAmelCase__							,		text_to_image_strength=0.75							,		generator=UpperCAmelCase__							,		guidance_scale=7.5							,		num_inference_steps=2							,		output_type="numpy"							,		).images

								with tempfile.TemporaryDirectory() as tmpdirname:
												pipe.save_pretrained(UpperCAmelCase__  )
												SCREAMING_SNAKE_CASE__  				=					VersatileDiffusionDualGuidedPipeline.from_pretrained(UpperCAmelCase__  )

								pipe.to(UpperCAmelCase__  )
								pipe.set_progress_bar_config(disable=UpperCAmelCase__  )

								SCREAMING_SNAKE_CASE__  				=					generator.manual_seed(0  )
								SCREAMING_SNAKE_CASE__  				=					pipe(
								    prompt="first prompt"							,		image=UpperCAmelCase__							,		text_to_image_strength=0.75							,		generator=UpperCAmelCase__							,		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  ):
								SCREAMING_SNAKE_CASE__  				=					VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"  )
								pipe.remove_unused_weights()
								pipe.to(UpperCAmelCase__  )
								pipe.set_progress_bar_config(disable=UpperCAmelCase__  )

								SCREAMING_SNAKE_CASE__  				=					"cyberpunk 2077"
								SCREAMING_SNAKE_CASE__  				=					load_image(
								    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"  )
								SCREAMING_SNAKE_CASE__  				=					torch.manual_seed(0  )
								SCREAMING_SNAKE_CASE__  				=					pipe(
								    prompt=UpperCAmelCase__							,		image=UpperCAmelCase__							,		text_to_image_strength=0.75							,		generator=UpperCAmelCase__							,		guidance_scale=7.5							,		num_inference_steps=50							,		output_type="numpy"							,		).images

								SCREAMING_SNAKE_CASE__  				=					image[0, 253:256, 253:256, -1]

								assert image.shape == (1, 512, 512, 3)
								SCREAMING_SNAKE_CASE__  				=					np.array([0.0_787, 0.0_849, 0.0_826, 0.0_812, 0.0_807, 0.0_795, 0.0_818, 0.0_798, 0.0_779]  )

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