



"""simple docstring"""

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


	'''simple docstring'''







	@property
	def  _lowerCAmelCase    (			self							:					str						)	->  str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Dict 							=    1
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    3
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    (32, 32)

					SCREAMING_SNAKE_CASE	:       Any 							=    floats_tensor((batch_size, num_channels) + sizes    ,					rng=random.Random(0						)						).to(_SCREAMING_SNAKE_CASE						)
					return image





	@property
	def  _lowerCAmelCase    (			self							:					int						)	->  Optional[Any]:





					"""simple docstring"""


					torch.manual_seed(0						)
					SCREAMING_SNAKE_CASE	:       int 							=    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  _lowerCAmelCase    (			self							:					Dict						)	->  str:





					"""simple docstring"""


					torch.manual_seed(0						)
					SCREAMING_SNAKE_CASE	:       Dict 							=    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  _lowerCAmelCase    (			self							:					Any						)	->  List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    'cpu'
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    self.dummy_uncond_unet
					SCREAMING_SNAKE_CASE	:       List[str] 							=    DDIMScheduler()
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    self.dummy_vq_model

					SCREAMING_SNAKE_CASE	:       Any 							=    LDMSuperResolutionPipeline(unet=_SCREAMING_SNAKE_CASE    ,					vqvae=_SCREAMING_SNAKE_CASE    ,					scheduler=_SCREAMING_SNAKE_CASE						)
					ldm.to(_SCREAMING_SNAKE_CASE						)
					ldm.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       Dict 							=    self.dummy_image.to(_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       List[Any] 							=    torch.Generator(device=_SCREAMING_SNAKE_CASE						).manual_seed(0						)
					SCREAMING_SNAKE_CASE	:       Any 							=    ldm(image=_SCREAMING_SNAKE_CASE    ,					generator=_SCREAMING_SNAKE_CASE    ,					num_inference_steps=2    ,					output_type='numpy'						).images

					SCREAMING_SNAKE_CASE	:       str 							=    image[0, -3:, -3:, -1]

					assert image.shape == (1, 64, 64, 3)
					SCREAMING_SNAKE_CASE	:       Dict 							=    np.array([0.8_6_7_8, 0.8_2_4_5, 0.6_3_8_1, 0.6_8_3_0, 0.4_3_8_5, 0.5_5_9_9, 0.4_6_4_1, 0.6_2_0_1, 0.5_1_5_0]						)

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







	@unittest.skipIf(torch_device != 'cuda'    ,					'This test requires a GPU'						)
	def  _lowerCAmelCase    (			self							:					Any						)	->  List[str]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Tuple 							=    self.dummy_uncond_unet
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    DDIMScheduler()
					SCREAMING_SNAKE_CASE	:       Any 							=    self.dummy_vq_model

					# put models in fp16
					SCREAMING_SNAKE_CASE	:       List[str] 							=    unet.half()
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    vqvae.half()

					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    LDMSuperResolutionPipeline(unet=_SCREAMING_SNAKE_CASE    ,					vqvae=_SCREAMING_SNAKE_CASE    ,					scheduler=_SCREAMING_SNAKE_CASE						)
					ldm.to(_SCREAMING_SNAKE_CASE						)
					ldm.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.dummy_image.to(_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    ldm(_SCREAMING_SNAKE_CASE    ,					num_inference_steps=2    ,					output_type='numpy'						).images

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




@slow
@require_torch
class 						lowerCAmelCase__	(  unittest.TestCase   ):


	'''simple docstring'''







	def  _lowerCAmelCase    (			self							:					int						)	->  Any:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Any 							=    load_image(
					    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
					    '/vq_diffusion/teddy_bear_pool.png'						)
					SCREAMING_SNAKE_CASE	:       List[str] 							=    init_image.resize((64, 64)    ,					resample=PIL_INTERPOLATION['lanczos']						)

					SCREAMING_SNAKE_CASE	:       List[str] 							=    LDMSuperResolutionPipeline.from_pretrained('duongna/ldm-super-resolution'    ,					device_map='auto'						)
					ldm.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       Any 							=    torch.manual_seed(0						)
					SCREAMING_SNAKE_CASE	:       List[str] 							=    ldm(image=_SCREAMING_SNAKE_CASE    ,					generator=_SCREAMING_SNAKE_CASE    ,					num_inference_steps=20    ,					output_type='numpy'						).images

					SCREAMING_SNAKE_CASE	:       List[str] 							=    image[0, -3:, -3:, -1]

					assert image.shape == (1, 256, 256, 3)
					SCREAMING_SNAKE_CASE	:       int 							=    np.array([0.7_6_4_4, 0.7_6_7_9, 0.7_6_4_2, 0.7_6_3_3, 0.7_6_6_6, 0.7_5_6_0, 0.7_4_2_5, 0.7_2_5_7, 0.6_9_0_7]						)

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










"""simple docstring"""

import platform
from argparse import ArgumentParser

import huggingface_hub
import pandas
import pyarrow

from datasets import __version__ as version
from datasets.commands import BaseDatasetsCLICommand
def    __snake_case       (  __A			:	Union[str, Any]    )    ->					Tuple:






				'''simple docstring'''
				return EnvironmentCommand()







class 						lowerCAmelCase__	(  _lowerCamelCase   ):


	'''simple docstring'''







	@staticmethod
	def  _lowerCAmelCase    (			_SCREAMING_SNAKE_CASE							:					ArgumentParser						)	->  str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       int 							=    parser.add_parser('env'    ,					help='Print relevant system environment info.'						)
					download_parser.set_defaults(func=_SCREAMING_SNAKE_CASE						)





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       int 							=    {
					    '`datasets` version': version,
					    'Platform': platform.platform(),
					    'Python version': platform.python_version(),
					    'Huggingface_hub version': huggingface_hub.__version__,
					    'PyArrow version': pyarrow.__version__,
					    'Pandas version': pandas.__version__,
					}

					print('\nCopy-and-paste the text below in your GitHub issue.\n'						)
					print(self.format_dict(_SCREAMING_SNAKE_CASE						)						)

					return info







	@staticmethod
	def  _lowerCAmelCase    (			_SCREAMING_SNAKE_CASE							:					Optional[Any]						)	->  List[Any]:





					"""simple docstring"""


					return "\n".join([f"""- {prop}: {val}""" for prop, val in d.items()]						) + "\n"





