code: 
  
  
  '''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
  
  
  lowercase_								=    False
  
  
  
  
  @nightly
  @require_torch_gpu
  class 					_UpperCamelCase (      unittest.TestCase	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				str		):
  													# clean up the VRAM after each test
  													super().tearDown()
  													gc.collect()
  													torch.cuda.empty_cache()
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			VersatileDiffusionDualGuidedPipeline.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_		)
  
  													_a     =			load_image(
  													    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'		)
  
  													_a     =			torch.manual_seed(0		)
  													_a     =			pipe(
  													    prompt='first prompt'		,				image=SCREAMING_SNAKE_CASE_		,				text_to_image_strength=0.75		,				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_		)
  																			_a     =			VersatileDiffusionDualGuidedPipeline.from_pretrained(SCREAMING_SNAKE_CASE_		)
  
  													pipe.to(SCREAMING_SNAKE_CASE_		)
  													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_		)
  
  													_a     =			generator.manual_seed(0		)
  													_a     =			pipe(
  													    prompt='first prompt'		,				image=SCREAMING_SNAKE_CASE_		,				text_to_image_strength=0.75		,				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 		_UpperCAmelCase	(		self  :				int		):
  													_a     =			VersatileDiffusionDualGuidedPipeline.from_pretrained('shi-labs/versatile-diffusion'		)
  													pipe.remove_unused_weights()
  													pipe.to(SCREAMING_SNAKE_CASE_		)
  													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_		)
  
  													_a     =			'''cyberpunk 2077'''
  													_a     =			load_image(
  													    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'		)
  													_a     =			torch.manual_seed(0		)
  													_a     =			pipe(
  													    prompt=SCREAMING_SNAKE_CASE_		,				image=SCREAMING_SNAKE_CASE_		,				text_to_image_strength=0.75		,				generator=SCREAMING_SNAKE_CASE_		,				guidance_scale=7.5		,				num_inference_steps=5_0		,				output_type='numpy'		,				).images
  
  													_a     =			image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]
  
  													assert image.shape == (1, 5_1_2, 5_1_2, 3)
  													_a     =			np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]		)
  
  													assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2
  
  
  
style_context: 
  
  
  import numpy as np
  import PIL
  import torch
  import torchvision.transforms as T
  import torchvision.transforms.functional as TF
  from PIL import Image
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase							,     _UpperCAmelCase=256				)    ->  Dict:
  						_a     =			min(img.size				)
  
  						if s < target_image_size:
  												raise ValueError(f"""min dim for image {s} < {target_image_size}"""				)
  
  						_a     =			target_image_size / s
  						_a     =			(round(r * img.size[1]				), round(r * img.size[0]				))
  						_a     =			TF.resize(_UpperCAmelCase							,     _UpperCAmelCase							,     interpolation=PIL.Image.LANCZOS				)
  						_a     =			TF.center_crop(_UpperCAmelCase							,     output_size=2 * [target_image_size]				)
  						_a     =			torch.unsqueeze(T.ToTensor()(_UpperCAmelCase				)							,     0				)
  						return img
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  List[Any]:
  						_a     =			2.0 * x - 1.0
  						return x
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase							,     _UpperCAmelCase=True							,     _UpperCAmelCase="RGB"				)    ->  Optional[Any]:
  						_a     =			x.detach().cpu()
  						if process:
  												_a     =			post_process_tensor(_UpperCAmelCase				)
  						_a     =			x.numpy()
  						if process:
  												_a     =			(255 * x).astype(np.uinta				)
  						_a     =			Image.fromarray(_UpperCAmelCase				)
  						if not x.mode == mode:
  												_a     =			x.convert(_UpperCAmelCase				)
  						return x
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  Optional[Any]:
  						_a     =			torch.clamp(_UpperCAmelCase							,     -1.0							,     1.0				)
  						_a     =			(x + 1.0) / 2.0
  						_a     =			x.permute(1							,     2							,     0				)
  						return x
  
  
  
  
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  str:
  						_a     =			post_process_tensor(x.squeeze()				)
  						return x.permute(2							,     0							,     1				).unsqueeze(0				)
  
  
  