



'''simple docstring'''






import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin

@skip_mps
class 				SCREAMING_SNAKE_CASE(							A__							,		A__							,		unittest.TestCase			):







	"""simple docstring"""






	lowerCamelCase__			 =       IFImgaImgSuperResolutionPipeline
	lowerCamelCase__			 =       TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
	lowerCamelCase__			 =       TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"""original_image"""}			)
	lowerCamelCase__			 =       PipelineTesterMixin.required_optional_params - {"""latents"""}







	def      A	(						self			:     int		)			->		List[str]:
								return self._get_superresolution_dummy_components()







	def      A	(						self			:     Union[str, Any]		,			__snake_case			:     Optional[Any]		,			__snake_case			:     Any=0		)			->		Union[str, Any]:
								if str(__snake_case		).startswith('''mps'''		):
															UpperCAmelCase :       Union[str, Any] 							=		torch.manual_seed(__snake_case		)
								else:
															UpperCAmelCase :       Optional[int] 							=		torch.Generator(device=__snake_case		).manual_seed(__snake_case		)

								UpperCAmelCase :       List[Any] 							=		floats_tensor((1, 3, 32, 32)		,			rng=random.Random(__snake_case		)		).to(__snake_case		)
								UpperCAmelCase :       Dict 							=		floats_tensor((1, 3, 16, 16)		,			rng=random.Random(__snake_case		)		).to(__snake_case		)

								UpperCAmelCase :       List[str] 							=		{
								    '''prompt''': '''A painting of a squirrel eating a burger''',
								    '''image''': image,
								    '''original_image''': original_image,
								    '''generator''': generator,
								    '''num_inference_steps''': 2,
								    '''output_type''': '''numpy''',
								}

								return inputs







	@unittest.skipIf(
	    torch_device != '''cuda''' or not is_xformers_available()		,			reason='''XFormers attention is only available with CUDA and `xformers` installed'''		,			)
	def      A	(						self			:     int		)			->		Optional[int]:
								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)







	def      A	(						self			:     List[Any]		)			->		Dict:
								self._test_save_load_optional_components()







	@unittest.skipIf(torch_device != '''cuda'''		,			reason='''float16 requires CUDA'''		)
	def      A	(						self			:     Any		)			->		Any:
								# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
								super().test_save_load_floataa(expected_max_diff=1E-1		)







	def      A	(						self			:     Dict		)			->		Any:
								self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)







	def      A	(						self			:     Optional[int]		)			->		Any:
								self._test_save_load_local()







	def      A	(						self			:     Tuple		)			->		List[Any]:
								self._test_inference_batch_single_identical(
								    expected_max_diff=1E-2		,			)










'''simple docstring'''






# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import sys

import transformers


UpperCamelCase__:   Optional[int]								=			"3"

print("Python version:", sys.version)
print("transformers version:", transformers.__version__)

try:
						import torch

						print("Torch version:", torch.__version__)
						print("Cuda available:", torch.cuda.is_available())
						print("Cuda version:", torch.version.cuda)
						print("CuDNN version:", torch.backends.cudnn.version())
						print("Number of GPUs available:", torch.cuda.device_count())
						print("NCCL version:", torch.cuda.nccl.version())
except ImportError:
						print("Torch version:", None)

try:
						import deepspeed

						print("DeepSpeed version:", deepspeed.__version__)
except ImportError:
						print("DeepSpeed version:", None)

try:
						import tensorflow as tf

						print("TensorFlow version:", tf.__version__)
						print("TF GPUs available:", bool(tf.config.list_physical_devices("GPU")))
						print("Number of TF GPUs available:", len(tf.config.list_physical_devices("GPU")))
except ImportError:
						print("TensorFlow version:", None)





