code: 
  
  
  import random
  import unittest
  
  import numpy as np
  import torch
  
  from diffusers import DDIMScheduler, LDMSuperResolutionPipeline, UNetaDModel, VQModel
  from diffusers.utils import PIL_INTERPOLATION, floats_tensor, load_image, slow, torch_device
  from diffusers.utils.testing_utils import enable_full_determinism, require_torch
  
  
  enable_full_determinism()
  
  
  
  
  
  class 					snake_case__  ( unittest.TestCase       ):
  
  
  
  
  
  	@property
  	def     A				(  self							)		->			Tuple:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Union[str, Any]			=	1
  								a_       :   Tuple			=	3
  								a_       :   str			=	(32, 32)
  
  								a_       :   Optional[Any]			=	floats_tensor((batch_size, num_channels) + sizes				,    rng=random.Random(0							)							).to(UpperCamelCase_							)
  								return image
  
  
  
  
  
  	@property
  	def     A				(  self							)		->			int:
  								"""simple docstring"""
  
  
  
  
  
  
  								torch.manual_seed(0							)
  								a_       :   Dict			=	UNetaDModel(
  								    block_out_channels=(32, 64)				,    layers_per_block=2				,    sample_size=32				,    in_channels=6				,    out_channels=3				,    down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")				,    up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")				,    )
  								return model
  
  
  
  
  
  	@property
  	def     A				(  self							)		->			List[str]:
  								"""simple docstring"""
  
  
  
  
  
  
  								torch.manual_seed(0							)
  								a_       :   Any			=	VQModel(
  								    block_out_channels=[32, 64]				,    in_channels=3				,    out_channels=3				,    down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]				,    up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]				,    latent_channels=3				,    )
  								return model
  
  
  
  
  
  	def     A				(  self							)		->			List[Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Optional[int]			=	"""cpu"""
  								a_       :   int			=	self.dummy_uncond_unet
  								a_       :   List[Any]			=	DDIMScheduler()
  								a_       :   List[Any]			=	self.dummy_vq_model
  
  								a_       :   Optional[int]			=	LDMSuperResolutionPipeline(unet=UpperCamelCase_				,    vqvae=UpperCamelCase_				,    scheduler=UpperCamelCase_							)
  								ldm.to(UpperCamelCase_							)
  								ldm.set_progress_bar_config(disable=UpperCamelCase_							)
  
  								a_       :   Dict			=	self.dummy_image.to(UpperCamelCase_							)
  
  								a_       :   List[str]			=	torch.Generator(device=UpperCamelCase_							).manual_seed(0							)
  								a_       :   List[Any]			=	ldm(image=UpperCamelCase_				,    generator=UpperCamelCase_				,    num_inference_steps=2				,    output_type="""numpy"""							).images
  
  								a_       :   List[str]			=	image[0, -3:, -3:, -1]
  
  								assert image.shape == (1, 64, 64, 3)
  								a_       :   Tuple			=	np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]							)
  
  								assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2
  
  
  
  
  
  	@unittest.skipIf(torch_device != """cuda"""				,    """This test requires a GPU"""							)
  	def     A				(  self							)		->			Union[str, Any]:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   Union[str, Any]			=	self.dummy_uncond_unet
  								a_       :   Dict			=	DDIMScheduler()
  								a_       :   Dict			=	self.dummy_vq_model
  
  								# put models in fp16
  								a_       :   Dict			=	unet.half()
  								a_       :   Dict			=	vqvae.half()
  
  								a_       :   Dict			=	LDMSuperResolutionPipeline(unet=UpperCamelCase_				,    vqvae=UpperCamelCase_				,    scheduler=UpperCamelCase_							)
  								ldm.to(UpperCamelCase_							)
  								ldm.set_progress_bar_config(disable=UpperCamelCase_							)
  
  								a_       :   Optional[Any]			=	self.dummy_image.to(UpperCamelCase_							)
  
  								a_       :   int			=	ldm(UpperCamelCase_				,    num_inference_steps=2				,    output_type="""numpy"""							).images
  
  								assert image.shape == (1, 64, 64, 3)
  
  
  
  
  
  @slow
  @require_torch
  class 					snake_case__  ( unittest.TestCase       ):
  
  
  
  
  
  	def     A				(  self							)		->			Any:
  								"""simple docstring"""
  
  
  
  
  
  
  								a_       :   List[Any]			=	load_image(
  								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
  								    """/vq_diffusion/teddy_bear_pool.png"""							)
  								a_       :   List[str]			=	init_image.resize((64, 64)				,    resample=PIL_INTERPOLATION["""lanczos"""]							)
  
  								a_       :   Optional[Any]			=	LDMSuperResolutionPipeline.from_pretrained("""duongna/ldm-super-resolution"""				,    device_map="""auto"""							)
  								ldm.set_progress_bar_config(disable=UpperCamelCase_							)
  
  								a_       :   Optional[int]			=	torch.manual_seed(0							)
  								a_       :   int			=	ldm(image=UpperCamelCase_				,    generator=UpperCamelCase_				,    num_inference_steps=20				,    output_type="""numpy"""							).images
  
  								a_       :   int			=	image[0, -3:, -3:, -1]
  
  								assert image.shape == (1, 256, 256, 3)
  								a_       :   Any			=	np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]							)
  
  								assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2
  
  
  
style_context: 
  
  
  def 						_lowerCamelCase		(							SCREAMING_SNAKE_CASE_				: list[int]      ):
  
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  							a_       :   List[Any]			=	len(SCREAMING_SNAKE_CASE_      )
  							if n in (0, 1):
  														return 0
  							return sum(query * (n - i - 1) for i, query in enumerate(sorted(SCREAMING_SNAKE_CASE_      )      )      )
  
  
  if __name__ == "__main__":
  	import doctest
  
  	doctest.testmod()
  
  
  