"""simple docstring"""







from __future__ import annotations

import inspect
import unittest

from transformers import MobileViTConfig
from transformers.file_utils import is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import numpy as np
				import tensorflow as tf

				from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
				from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileViTImageProcessor


class      _lowercase						(				_a					):

				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.config_class(**self.inputs_dict       )
										self.parent.assertTrue(hasattr(snake_case_    ,      """hidden_sizes"""       )       )
										self.parent.assertTrue(hasattr(snake_case_    ,      """neck_hidden_sizes"""       )       )
										self.parent.assertTrue(hasattr(snake_case_    ,      """num_attention_heads"""       )       )


class      _lowercase						:

				def __init__(       self    :      List[str]    ,      _lowercase    :      List[str]    ,      _lowercase    :      List[str]=1_3    ,      _lowercase    :      Optional[int]=3_2    ,      _lowercase    :      Optional[int]=2    ,      _lowercase    :      Tuple=3    ,      _lowercase    :      Optional[int]=6_4_0    ,      _lowercase    :      Any=4    ,      _lowercase    :      Dict="silu"    ,      _lowercase    :      Dict=3    ,      _lowercase    :      str=3_2    ,      _lowercase    :      Optional[int]=0.1    ,      _lowercase    :      Any=0.1    ,      _lowercase    :      List[Any]=0.1    ,      _lowercase    :      Union[str, Any]=0.02    ,      _lowercase    :      List[Any]=True    ,      _lowercase    :      Union[str, Any]=True    ,      _lowercase    :      Tuple=1_0    ,      _lowercase    :      Any=None    ,      ):


										'''simple docstring'''
										UpperCAmelCase__   		=						parent
										UpperCAmelCase__   		=						batch_size
										UpperCAmelCase__   		=						image_size
										UpperCAmelCase__   		=						patch_size
										UpperCAmelCase__   		=						num_channels
										UpperCAmelCase__   		=						last_hidden_size
										UpperCAmelCase__   		=						num_attention_heads
										UpperCAmelCase__   		=						hidden_act
										UpperCAmelCase__   		=						conv_kernel_size
										UpperCAmelCase__   		=						output_stride
										UpperCAmelCase__   		=						hidden_dropout_prob
										UpperCAmelCase__   		=						attention_probs_dropout_prob
										UpperCAmelCase__   		=						classifier_dropout_prob
										UpperCAmelCase__   		=						use_labels
										UpperCAmelCase__   		=						is_training
										UpperCAmelCase__   		=						num_labels
										UpperCAmelCase__   		=						initializer_range
										UpperCAmelCase__   		=						scope

				def     A	(       self    :      List[str]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

										UpperCAmelCase__   		=						None
										UpperCAmelCase__   		=						None
										if self.use_labels:
																UpperCAmelCase__   		=						ids_tensor([self.batch_size]    ,      self.num_labels       )
																UpperCAmelCase__   		=						ids_tensor([self.batch_size, self.image_size, self.image_size]    ,      self.num_labels       )

										UpperCAmelCase__   		=						self.get_config()

										return config, pixel_values, labels, pixel_labels

				def     A	(       self    :      int       ):


										'''simple docstring'''
										return MobileViTConfig(
										    image_size=self.image_size    ,      patch_size=self.patch_size    ,      num_channels=self.num_channels    ,      num_attention_heads=self.num_attention_heads    ,      hidden_act=self.hidden_act    ,      conv_kernel_size=self.conv_kernel_size    ,      output_stride=self.output_stride    ,      hidden_dropout_prob=self.hidden_dropout_prob    ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,      classifier_dropout_prob=self.classifier_dropout_prob    ,      initializer_range=self.initializer_range    ,      )

				def     A	(       self    :      Optional[Any]    ,      _lowercase    :      Any    ,      _lowercase    :      str    ,      _lowercase    :      List[str]    ,      _lowercase    :      Optional[int]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFMobileViTModel(config=snake_case_       )
										UpperCAmelCase__   		=						model(snake_case_    ,      training=snake_case_       )
										UpperCAmelCase__   		=						self.image_size // self.output_stride
										self.parent.assertEqual(
										    result.last_hidden_state.shape    ,      (self.batch_size, self.last_hidden_size, expected_height, expected_width)       )

				def     A	(       self    :      Tuple    ,      _lowercase    :      str    ,      _lowercase    :      Union[str, Any]    ,      _lowercase    :      str    ,      _lowercase    :      int       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.num_labels
										UpperCAmelCase__   		=						TFMobileViTForImageClassification(snake_case_       )
										UpperCAmelCase__   		=						model(snake_case_    ,      labels=snake_case_    ,      training=snake_case_       )
										self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.num_labels)       )

				def     A	(       self    :      Any    ,      _lowercase    :      Union[str, Any]    ,      _lowercase    :      Optional[int]    ,      _lowercase    :      Optional[int]    ,      _lowercase    :      Any       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.num_labels
										UpperCAmelCase__   		=						TFMobileViTForSemanticSegmentation(snake_case_       )
										UpperCAmelCase__   		=						self.image_size // self.output_stride

										UpperCAmelCase__   		=						model(snake_case_    ,      training=snake_case_       )
										self.parent.assertEqual(
										    result.logits.shape    ,      (self.batch_size, self.num_labels, expected_height, expected_width)       )

										UpperCAmelCase__   		=						model(snake_case_    ,      labels=snake_case_    ,      training=snake_case_       )
										self.parent.assertEqual(
										    result.logits.shape    ,      (self.batch_size, self.num_labels, expected_height, expected_width)       )

				def     A	(       self    :      Any       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.prepare_config_and_inputs()
										UpperCAmelCase__   		=						config_and_inputs
										UpperCAmelCase__   		=						{"""pixel_values""": pixel_values}
										return config, inputs_dict


@require_tf
class      _lowercase						(				_a , _a , unittest.TestCase					):
				lowerCamelCase__									=    (
				    (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
				    if is_tf_available()
				    else ()
				)
				lowerCamelCase__									=    (
				    {"""feature-extraction""": TFMobileViTModel, """image-classification""": TFMobileViTForImageClassification}
				    if is_tf_available()
				    else {}
				)

				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False

				def     A	(       self    :      List[str]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFMobileViTModelTester(self       )
										UpperCAmelCase__   		=						TFMobileViTConfigTester(self    ,      config_class=snake_case_    ,      has_text_modality=snake_case_       )

				def     A	(       self    :      List[str]       ):


										'''simple docstring'''
										self.config_tester.run_common_tests()

				@unittest.skip(reason="""MobileViT does not use inputs_embeds"""       )
				def     A	(       self    :      str       ):


										'''simple docstring'''
										pass

				@unittest.skip(reason="""MobileViT does not support input and output embeddings"""       )
				def     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										pass

				@unittest.skip(reason="""MobileViT does not output attentions"""       )
				def     A	(       self    :      List[Any]       ):


										'''simple docstring'''
										pass

				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																UpperCAmelCase__   		=						model_class(snake_case_       )
																UpperCAmelCase__   		=						inspect.signature(model.call       )
																# signature.parameters is an OrderedDict => so arg_names order is deterministic
																UpperCAmelCase__   		=						[*signature.parameters.keys()]

																UpperCAmelCase__   		=						["""pixel_values"""]
																self.assertListEqual(arg_names[:1]    ,      snake_case_       )

				def     A	(       self    :      Dict       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*snake_case_       )

				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										def check_hidden_states_output(_lowercase    :      Tuple    ,      _lowercase    :      Optional[Any]    ,      _lowercase    :      int       ):
																UpperCAmelCase__   		=						model_class(snake_case_       )

																UpperCAmelCase__   		=						model(**self._prepare_for_class(snake_case_    ,      snake_case_       )       )

																UpperCAmelCase__   		=						outputs.hidden_states

																UpperCAmelCase__   		=						5
																self.assertEqual(len(snake_case_       )    ,      snake_case_       )

																# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
																# with the width and height being successively divided by 2.
																UpperCAmelCase__   		=						2
																for i in range(len(snake_case_       )       ):
																						self.assertListEqual(
																						    list(hidden_states[i].shape[-2:]       )    ,      [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]    ,      )
																						divisor *= 2

																self.assertEqual(self.model_tester.output_stride    ,      divisor // 2       )

										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																UpperCAmelCase__   		=						True
																check_hidden_states_output(snake_case_    ,      snake_case_    ,      snake_case_       )

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																UpperCAmelCase__   		=						True

																check_hidden_states_output(snake_case_    ,      snake_case_    ,      snake_case_       )

				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*snake_case_       )

				def     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_semantic_segmentation(*snake_case_       )

				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""       )       ) == 0    ,      reason="""TF does not support backprop for grouped convolutions on CPU."""    ,      )
				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										super().test_dataset_conversion()

				def     A	(       self    :      Dict    ,      _lowercase    :      str    ,      _lowercase    :      Any    ,      _lowercase    :      str=2e-1    ,      _lowercase    :      Optional[int]=2e-1       ):


										'''simple docstring'''
										self.assertTrue(np.allclose(snake_case_    ,      snake_case_    ,      atol=snake_case_    ,      rtol=snake_case_       )       )

				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""       )       ) == 0    ,      reason="""TF does not support backprop for grouped convolutions on CPU."""    ,      )
				@slow
				def     A	(       self    :      str       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																# Since `TFMobileViTModel` cannot operate with the default `fit()` method.
																if model_class.__name__ != "TFMobileViTModel":
																						UpperCAmelCase__   		=						model_class(snake_case_       )
																						if getattr(snake_case_    ,      """hf_compute_loss"""    ,      snake_case_       ):
																												super().test_keras_fit()

				def     A	(       self    :      List[Any]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()
										for model_class in self.all_model_classes:
																# set an ignore index to correctly test the masked loss used in
																# `TFMobileViTForSemanticSegmentation`.
																if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
																						UpperCAmelCase__   		=						5

																UpperCAmelCase__   		=						model_class(snake_case_       )
																if getattr(snake_case_    ,      """hf_compute_loss"""    ,      snake_case_       ):
																						# The number of elements in the loss should be the same as the number of elements in the label
																						UpperCAmelCase__   		=						self._prepare_for_class(inputs_dict.copy()    ,      snake_case_    ,      return_labels=snake_case_       )
																						UpperCAmelCase__   		=						prepared_for_class[
																						    sorted(prepared_for_class.keys() - inputs_dict.keys()    ,      reverse=snake_case_       )[0]
																						]
																						UpperCAmelCase__   		=						added_label.shape.as_list()[:1]

																						# Test that model correctly compute the loss with kwargs
																						UpperCAmelCase__   		=						self._prepare_for_class(inputs_dict.copy()    ,      snake_case_    ,      return_labels=snake_case_       )
																						UpperCAmelCase__   		=						{"""input_ids""", """pixel_values""", """input_features"""}
																						UpperCAmelCase__   		=						possible_input_names.intersection(set(snake_case_       )       ).pop()
																						UpperCAmelCase__   		=						prepared_for_class.pop(snake_case_       )

																						UpperCAmelCase__   		=						model(snake_case_    ,      **snake_case_       )[0]
																						self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]       )

																						# Test that model correctly compute the loss when we mask some positions
																						UpperCAmelCase__   		=						self._prepare_for_class(inputs_dict.copy()    ,      snake_case_    ,      return_labels=snake_case_       )
																						UpperCAmelCase__   		=						{"""input_ids""", """pixel_values""", """input_features"""}
																						UpperCAmelCase__   		=						possible_input_names.intersection(set(snake_case_       )       ).pop()
																						UpperCAmelCase__   		=						prepared_for_class.pop(snake_case_       )
																						if "labels" in prepared_for_class:
																												UpperCAmelCase__   		=						prepared_for_class["""labels"""].numpy()
																												if len(labels.shape       ) > 1 and labels.shape[1] != 1:
																																		# labels[0] = -100
																																		UpperCAmelCase__   		=						tf.convert_to_tensor(snake_case_       )
																																		UpperCAmelCase__   		=						model(snake_case_    ,      **snake_case_       )[0]
																																		self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]       )
																																		self.assertTrue(not np.any(np.isnan(loss.numpy()       )       )       )

																												 # Test that model correctly compute the loss with a dict
																						UpperCAmelCase__   		=						self._prepare_for_class(inputs_dict.copy()    ,      snake_case_    ,      return_labels=snake_case_       )
																						UpperCAmelCase__   		=						model(snake_case_       )[0]
																						self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]       )

																						# Test that model correctly compute the loss with a tuple
																						UpperCAmelCase__   		=						self._prepare_for_class(inputs_dict.copy()    ,      snake_case_    ,      return_labels=snake_case_       )

																						# Get keys that were added with the _prepare_for_class function
																						UpperCAmelCase__   		=						prepared_for_class.keys() - inputs_dict.keys()
																						UpperCAmelCase__   		=						inspect.signature(model.call       ).parameters
																						UpperCAmelCase__   		=						list(signature.keys()       )

																						# Create a dictionary holding the location of the tensors in the tuple
																						UpperCAmelCase__   		=						{0: input_name}
																						for label_key in label_keys:
																												UpperCAmelCase__   		=						signature_names.index(snake_case_       )
																												UpperCAmelCase__   		=						label_key
																						UpperCAmelCase__   		=						sorted(tuple_index_mapping.items()       )
																						# Initialize a list with their default values, update the values and convert to a tuple
																						UpperCAmelCase__   		=						[]

																						for name in signature_names:
																												if name != "kwargs":
																																		list_input.append(signature[name].default       )

																						for index, value in sorted_tuple_index_mapping:
																												UpperCAmelCase__   		=						prepared_for_class[value]

																						UpperCAmelCase__   		=						tuple(snake_case_       )

																						# Send to model
																						UpperCAmelCase__   		=						model(tuple_input[:-1]       )[0]

																						self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]       )

				@slow
				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																UpperCAmelCase__   		=						TFMobileViTModel.from_pretrained(snake_case_       )
																self.assertIsNotNone(snake_case_       )


def 					a__ (						)->		Tuple:
						UpperCAmelCase__   		=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
						return image







@require_tf
class      _lowercase						(				unittest.TestCase					):

				@slow
				def     A	(       self    :      Optional[Any]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFMobileViTForImageClassification.from_pretrained("""apple/mobilevit-xx-small"""       )

										UpperCAmelCase__   		=						MobileViTImageProcessor.from_pretrained("""apple/mobilevit-xx-small"""       )
										UpperCAmelCase__   		=						prepare_img()
										UpperCAmelCase__   		=						image_processor(images=snake_case_    ,      return_tensors="""tf"""       )

										# forward pass
										UpperCAmelCase__   		=						model(**snake_case_    ,      training=snake_case_       )

										# verify the logits
										UpperCAmelCase__   		=						tf.TensorShape((1, 1_0_0_0)       )
										self.assertEqual(outputs.logits.shape    ,      snake_case_       )

										UpperCAmelCase__   		=						tf.constant([-1.9364, -1.2327, -0.4653]       )

										tf.debugging.assert_near(outputs.logits[0, :3]    ,      snake_case_    ,      atol=1e-4    ,      rtol=1e-04       )

				@slow
				def     A	(       self    :      str       ):


										'''simple docstring'''
										# `from_pt` will be removed
										UpperCAmelCase__   		=						TFMobileViTForSemanticSegmentation.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""       )

										UpperCAmelCase__   		=						MobileViTImageProcessor.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""       )

										UpperCAmelCase__   		=						prepare_img()
										UpperCAmelCase__   		=						image_processor(images=snake_case_    ,      return_tensors="""tf"""       )

										# forward pass
										UpperCAmelCase__   		=						model(inputs.pixel_values    ,      training=snake_case_       )
										UpperCAmelCase__   		=						outputs.logits

										# verify the logits
										UpperCAmelCase__   		=						tf.TensorShape((1, 2_1, 3_2, 3_2)       )
										self.assertEqual(logits.shape    ,      snake_case_       )

										UpperCAmelCase__   		=						tf.constant(
										    [
										        [[6.9713, 6.9786, 7.2422], [7.2893, 7.2825, 7.4446], [7.6580, 7.8797, 7.9420]],
										        [[-10.6869, -10.3250, -10.3471], [-10.4228, -9.9868, -9.7132], [-11.0405, -11.0221, -10.7318]],
										        [[-3.3089, -2.8539, -2.6740], [-3.2706, -2.5621, -2.5108], [-3.2534, -2.6615, -2.6651]],
										    ]       )

										tf.debugging.assert_near(logits[0, :3, :3, :3]    ,      snake_case_    ,      rtol=1e-4    ,      atol=1e-4       )


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

				@property
				def     A	(       self    :      Any       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						1
										UpperCAmelCase__   		=						3
										UpperCAmelCase__   		=						(3_2, 3_2)

										UpperCAmelCase__   		=						floats_tensor((batch_size, num_channels) + sizes    ,      rng=random.Random(0       )       ).to(_lowercase       )
										return image

				@property
				def     A	(       self    :      List[str]       ):


										'''simple docstring'''
										torch.manual_seed(0       )
										UpperCAmelCase__   		=						UNetaDModel(
										    block_out_channels=(3_2, 6_4)    ,      layers_per_block=2    ,      sample_size=3_2    ,      in_channels=6    ,      out_channels=3    ,      down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")    ,      up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")    ,      )
										return model

				@property
				def     A	(       self    :      Tuple       ):


										'''simple docstring'''
										torch.manual_seed(0       )
										UpperCAmelCase__   		=						VQModel(
										    block_out_channels=[3_2, 6_4]    ,      in_channels=3    ,      out_channels=3    ,      down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]    ,      up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]    ,      latent_channels=3    ,      )
										return model

				def     A	(       self    :      Any       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						"""cpu"""
										UpperCAmelCase__   		=						self.dummy_uncond_unet
										UpperCAmelCase__   		=						DDIMScheduler()
										UpperCAmelCase__   		=						self.dummy_vq_model

										UpperCAmelCase__   		=						LDMSuperResolutionPipeline(unet=_lowercase    ,      vqvae=_lowercase    ,      scheduler=_lowercase       )
										ldm.to(_lowercase       )
										ldm.set_progress_bar_config(disable=_lowercase       )

										UpperCAmelCase__   		=						self.dummy_image.to(_lowercase       )

										UpperCAmelCase__   		=						torch.Generator(device=_lowercase       ).manual_seed(0       )
										UpperCAmelCase__   		=						ldm(image=_lowercase    ,      generator=_lowercase    ,      num_inference_steps=2    ,      output_type="""numpy"""       ).images

										UpperCAmelCase__   		=						image[0, -3:, -3:, -1]

										assert image.shape == (1, 6_4, 6_4, 3)
										UpperCAmelCase__   		=						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    :      Dict       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.dummy_uncond_unet
										UpperCAmelCase__   		=						DDIMScheduler()
										UpperCAmelCase__   		=						self.dummy_vq_model

										# put models in fp16
										UpperCAmelCase__   		=						unet.half()
										UpperCAmelCase__   		=						vqvae.half()

										UpperCAmelCase__   		=						LDMSuperResolutionPipeline(unet=_lowercase    ,      vqvae=_lowercase    ,      scheduler=_lowercase       )
										ldm.to(_lowercase       )
										ldm.set_progress_bar_config(disable=_lowercase       )

										UpperCAmelCase__   		=						self.dummy_image.to(_lowercase       )

										UpperCAmelCase__   		=						ldm(_lowercase    ,      num_inference_steps=2    ,      output_type="""numpy"""       ).images

										assert image.shape == (1, 6_4, 6_4, 3)


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

				def     A	(       self    :      List[Any]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						load_image(
										    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
										    """/vq_diffusion/teddy_bear_pool.png"""       )
										UpperCAmelCase__   		=						init_image.resize((6_4, 6_4)    ,      resample=PIL_INTERPOLATION["""lanczos"""]       )

										UpperCAmelCase__   		=						LDMSuperResolutionPipeline.from_pretrained("""duongna/ldm-super-resolution"""    ,      device_map="""auto"""       )
										ldm.set_progress_bar_config(disable=_lowercase       )

										UpperCAmelCase__   		=						torch.manual_seed(0       )
										UpperCAmelCase__   		=						ldm(image=_lowercase    ,      generator=_lowercase    ,      num_inference_steps=2_0    ,      output_type="""numpy"""       ).images

										UpperCAmelCase__   		=						image[0, -3:, -3:, -1]

										assert image.shape == (1, 2_5_6, 2_5_6, 3)
										UpperCAmelCase__   		=						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

