


import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import MODEL_MAPPING, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
			from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import DPTImageProcessor

class        a	:




							"""simple docstring"""


							def __init__(							self :						Optional[int]					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						List[str]=2					,			lowerCamelCase :						List[Any]=32					,			lowerCamelCase :						Dict=16					,			lowerCamelCase :						Union[str, Any]=3					,			lowerCamelCase :						Optional[int]=True					,			lowerCamelCase :						List[str]=True					,			lowerCamelCase :						Dict=32					,			lowerCamelCase :						Any=4					,			lowerCamelCase :						Tuple=[0, 1, 2, 3]					,			lowerCamelCase :						Optional[int]=4					,			lowerCamelCase :						Dict=37					,			lowerCamelCase :						Optional[Any]="gelu"					,			lowerCamelCase :						List[Any]=0.1					,			lowerCamelCase :						Tuple=0.1					,			lowerCamelCase :						Optional[int]=0.02					,			lowerCamelCase :						Optional[Any]=3					,			lowerCamelCase :						int=[1, 384, 24, 24]					,			lowerCamelCase :						List[Any]=True					,			lowerCamelCase :						Optional[int]=None					,			)			->					Tuple:
														__snake_case	:    Optional[Any]											=     parent
														__snake_case	:    List[Any]											=     batch_size
														__snake_case	:    Dict											=     image_size
														__snake_case	:    List[Any]											=     patch_size
														__snake_case	:    Any											=     num_channels
														__snake_case	:    List[str]											=     is_training
														__snake_case	:    Union[str, Any]											=     use_labels
														__snake_case	:    int											=     hidden_size
														__snake_case	:    Tuple											=     num_hidden_layers
														__snake_case	:    str											=     backbone_out_indices
														__snake_case	:    List[str]											=     num_attention_heads
														__snake_case	:    str											=     intermediate_size
														__snake_case	:    Dict											=     hidden_act
														__snake_case	:    List[Any]											=     hidden_dropout_prob
														__snake_case	:    Tuple											=     attention_probs_dropout_prob
														__snake_case	:    Union[str, Any]											=     initializer_range
														__snake_case	:    Any											=     num_labels
														__snake_case	:    Optional[int]											=     backbone_featmap_shape
														__snake_case	:    Dict											=     scope
														__snake_case	:    List[str]											=     is_hybrid
														# sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
														__snake_case	:    Optional[int]											=     (image_size // patch_size) ** 2
														__snake_case	:    Union[str, Any]											=     num_patches + 1

							def 					__snake_case      (							self :						Any       )			->					Dict:
														__snake_case	:    Union[str, Any]											=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

														__snake_case	:    int											=     None
														if self.use_labels:
																					__snake_case	:    List[str]											=     ids_tensor([self.batch_size, self.image_size, self.image_size]					,			self.num_labels       )

														__snake_case	:    List[str]											=     self.get_config()

														return config, pixel_values, labels

							def 					__snake_case      (							self :						Union[str, Any]       )			->					Dict:
														__snake_case	:    Union[str, Any]											=     {
														    "global_padding": "same",
														    "layer_type": "bottleneck",
														    "depths": [3, 4, 9],
														    "out_features": ["stage1", "stage2", "stage3"],
														    "embedding_dynamic_padding": True,
														    "hidden_sizes": [96, 192, 384, 768],
														    "num_groups": 2,
														}

														return DPTConfig(
														    image_size=self.image_size					,			patch_size=self.patch_size					,			num_channels=self.num_channels					,			hidden_size=self.hidden_size					,			num_hidden_layers=self.num_hidden_layers					,			backbone_out_indices=self.backbone_out_indices					,			num_attention_heads=self.num_attention_heads					,			intermediate_size=self.intermediate_size					,			hidden_act=self.hidden_act					,			hidden_dropout_prob=self.hidden_dropout_prob					,			attention_probs_dropout_prob=self.attention_probs_dropout_prob					,			is_decoder=lowerCamelCase					,			initializer_range=self.initializer_range					,			is_hybrid=self.is_hybrid					,			backbone_config=lowerCamelCase					,			backbone_featmap_shape=self.backbone_featmap_shape					,			)

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						int					,			lowerCamelCase :						int					,			lowerCamelCase :						Optional[Any]       )			->					Tuple:
														__snake_case	:    Optional[Any]											=     DPTModel(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    str											=     model(lowerCamelCase       )
														self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, self.seq_length, self.hidden_size)       )

							def 					__snake_case      (							self :						str					,			lowerCamelCase :						int					,			lowerCamelCase :						Any					,			lowerCamelCase :						Any       )			->					Union[str, Any]:
														__snake_case	:    Tuple											=     self.num_labels
														__snake_case	:    str											=     DPTForDepthEstimation(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Union[str, Any]											=     model(lowerCamelCase       )
														self.parent.assertEqual(result.predicted_depth.shape					,			(self.batch_size, self.image_size, self.image_size)       )

							def 					__snake_case      (							self :						List[Any]					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						Union[str, Any]					,			lowerCamelCase :						Optional[Any]       )			->					int:
														__snake_case	:    Optional[Any]											=     self.num_labels
														__snake_case	:    str											=     DPTForSemanticSegmentation(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    int											=     model(lowerCamelCase					,			labels=lowerCamelCase       )
														self.parent.assertEqual(
														    result.logits.shape					,			(self.batch_size, self.num_labels, self.image_size, self.image_size)       )






							def 					__snake_case      (							self :						List[str]       )			->					str:
														__snake_case	:    List[str]											=     self.prepare_config_and_inputs()
														__snake_case				,    __snake_case				,    __snake_case	:    Union[str, Any]											=     config_and_inputs
														__snake_case	:    List[Any]											=     {"pixel_values": pixel_values}
														return config, inputs_dict

@require_torch
class        a	(_lowerCAmelCase  ,       _lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							List[Any]  						=						(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
							__UpperCAmelCase					:							int  						=						(
							    {
							        "depth-estimation": DPTForDepthEstimation,
							        "feature-extraction": DPTModel,
							        "image-segmentation": DPTForSemanticSegmentation,
							    }
							    if is_torch_available()
							    else {}
							)

							__UpperCAmelCase					:							int  						=						False
							__UpperCAmelCase					:							Tuple  						=						False
							__UpperCAmelCase					:							Tuple  						=						False

							def 					__snake_case      (							self :						Dict       )			->					Dict:
														__snake_case	:    int											=     DPTModelTester(self       )
														__snake_case	:    Dict											=     ConfigTester(self					,			config_class=lowerCamelCase					,			has_text_modality=lowerCamelCase					,			hidden_size=37       )

							def 					__snake_case      (							self :						Optional[Any]       )			->					Union[str, Any]:
														self.config_tester.run_common_tests()

							@unittest.skip(reason="DPT does not use inputs_embeds"       )
							def 					__snake_case      (							self :						str       )			->					int:
														pass

							def 					__snake_case      (							self :						Any       )			->					str:
														__snake_case				,    __snake_case	:    Tuple											=     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					__snake_case	:    Union[str, Any]											=     model_class(lowerCamelCase       )
																					self.assertIsInstance(model.get_input_embeddings()					,			(nn.Module)       )
																					__snake_case	:    Dict											=     model.get_output_embeddings()
																					self.assertTrue(x is None or isinstance(lowerCamelCase					,			nn.Linear       )       )

							def 					__snake_case      (							self :						Tuple       )			->					List[str]:
														__snake_case				,    __snake_case	:    Optional[int]											=     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					__snake_case	:    Any											=     model_class(lowerCamelCase       )
																					__snake_case	:    str											=     inspect.signature(model.forward       )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					__snake_case	:    List[str]											=     [*signature.parameters.keys()]

																					__snake_case	:    Optional[Any]											=     ["pixel_values"]
																					self.assertListEqual(arg_names[:1]					,			lowerCamelCase       )

							def 					__snake_case      (							self :						str       )			->					Tuple:
														__snake_case	:    List[Any]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCamelCase       )

							def 					__snake_case      (							self :						Any       )			->					Optional[Any]:
														__snake_case	:    Union[str, Any]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_depth_estimation(*lowerCamelCase       )

							def 					__snake_case      (							self :						str       )			->					Optional[Any]:
														__snake_case	:    str											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[Any]       )			->					Optional[Any]:
														for model_class in self.all_model_classes:
																					if model_class.__name__ == "DPTForDepthEstimation":
																												continue

																					__snake_case				,    __snake_case	:    List[Any]											=     self.model_tester.prepare_config_and_inputs_for_common()
																					__snake_case	:    int											=     True

																					if model_class in get_values(lowerCamelCase       ):
																												continue

																					__snake_case	:    int											=     model_class(lowerCamelCase       )
																					model.to(lowerCamelCase       )
																					model.train()
																					__snake_case	:    Dict											=     self._prepare_for_class(lowerCamelCase					,			lowerCamelCase					,			return_labels=lowerCamelCase       )
																					__snake_case	:    Dict											=     model(**lowerCamelCase       ).loss
																					loss.backward()

							def 					__snake_case      (							self :						str       )			->					Optional[int]:
														for model_class in self.all_model_classes:
																					if model_class.__name__ == "DPTForDepthEstimation":
																												continue

																					__snake_case				,    __snake_case	:    List[str]											=     self.model_tester.prepare_config_and_inputs_for_common()
																					__snake_case	:    int											=     False
																					__snake_case	:    Optional[int]											=     True

																					if model_class in get_values(lowerCamelCase       ) or not model_class.supports_gradient_checkpointing:
																												continue
																					__snake_case	:    str											=     model_class(lowerCamelCase       )
																					model.to(lowerCamelCase       )
																					model.gradient_checkpointing_enable()
																					model.train()
																					__snake_case	:    Optional[Any]											=     self._prepare_for_class(lowerCamelCase					,			lowerCamelCase					,			return_labels=lowerCamelCase       )
																					__snake_case	:    str											=     model(**lowerCamelCase       ).loss
																					loss.backward()

							def 					__snake_case      (							self :						Dict       )			->					Dict:
														__snake_case				,    __snake_case	:    List[Any]											=     self.model_tester.prepare_config_and_inputs_for_common()

														__snake_case	:    Optional[int]											=     _config_zero_init(lowerCamelCase       )
														for model_class in self.all_model_classes:
																					__snake_case	:    int											=     model_class(config=lowerCamelCase       )
																					# Skip the check for the backbone
																					__snake_case	:    Optional[Any]											=     []
																					for name, module in model.named_modules():
																												if module.__class__.__name__ == "DPTViTHybridEmbeddings":
																																			__snake_case	:    Optional[Any]											=     [F'{name}.{key}' for key in module.state_dict().keys()]
																																			break

																					for name, param in model.named_parameters():
																												if param.requires_grad:
																																			if name in backbone_params:
																																										continue
																																			self.assertIn(
																																			    ((param.data.mean() * 1E9).round() / 1E9).item()					,			[0.0, 1.0]					,			msg=F'Parameter {name} of model {model_class} seems not properly initialized'					,			)

							@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."       )
							def 					__snake_case      (							self :						Any       )			->					Dict:
														pass

							@slow
							def 					__snake_case      (							self :						List[str]       )			->					Any:
														for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[1:]:
																					__snake_case	:    Any											=     DPTModel.from_pretrained(lowerCamelCase       )
																					self.assertIsNotNone(lowerCamelCase       )






							def 					__snake_case      (							self :						Optional[Any]       )			->					str:
														# We do this test only for DPTForDepthEstimation since it is the only model that uses readout_type
														__snake_case				,    __snake_case	:    List[str]											=     self.model_tester.prepare_config_and_inputs_for_common()
														__snake_case	:    Optional[int]											=     "add"
														with self.assertRaises(lowerCamelCase       ):
																					__snake_case	:    Optional[Any]											=     DPTForDepthEstimation(lowerCamelCase       )







def        lowerCAmelCase_  (      ):
							__snake_case	:    Any											=     Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			)
							return image

@require_torch
@require_vision
@slow
class        a	(unittest.TestCase   ):




							"""simple docstring"""


							def 					__snake_case      (							self :						Optional[int]       )			->					Tuple:
														__snake_case	:    Tuple											=     DPTImageProcessor.from_pretrained("Intel/dpt-hybrid-midas"       )
														__snake_case	:    List[str]											=     DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas"       ).to(lowerCamelCase       )

														__snake_case	:    List[str]											=     prepare_img()
														__snake_case	:    List[str]											=     image_processor(images=lowerCamelCase					,			return_tensors="pt"       ).to(lowerCamelCase       )

														# forward pass
														with torch.no_grad():
																					__snake_case	:    List[str]											=     model(**lowerCamelCase       )
																					__snake_case	:    Union[str, Any]											=     outputs.predicted_depth

														# verify the predicted depth
														__snake_case	:    List[str]											=     torch.Size((1, 384, 384)       )
														self.assertEqual(predicted_depth.shape					,			lowerCamelCase       )

														__snake_case	:    List[str]											=     torch.tensor(
														    [[[5.64_37, 5.61_46, 5.65_11], [5.43_71, 5.56_49, 5.59_58], [5.52_15, 5.51_84, 5.52_93]]]       ).to(lowerCamelCase       )

														self.assertTrue(torch.allclose(outputs.predicted_depth[:3, :3, :3] / 100					,			lowerCamelCase					,			atol=1E-4       )       )





import gc
import random
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DiffusionPipeline,
    EulerDiscreteScheduler,
    StableDiffusionXLImgaImgPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import floats_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()

class        a	(_lowerCAmelCase  ,       _lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Optional[Any]  						=						StableDiffusionXLImgaImgPipeline
							__UpperCAmelCase					:							Any  						=						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"height", "width"}
							__UpperCAmelCase					:							Dict  						=						PipelineTesterMixin.required_optional_params - {"latents"}
							__UpperCAmelCase					:							Union[str, Any]  						=						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
							__UpperCAmelCase					:							Tuple  						=						IMAGE_TO_IMAGE_IMAGE_PARAMS
							__UpperCAmelCase					:							str  						=						IMAGE_TO_IMAGE_IMAGE_PARAMS

							def 					__snake_case      (							self :						Optional[Any]       )			->					Tuple:
														torch.manual_seed(0       )
														__snake_case	:    Optional[int]											=     UNetaDConditionModel(
														    block_out_channels=(32, 64)					,			layers_per_block=2					,			sample_size=32					,			in_channels=4					,			out_channels=4					,			down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")					,			up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")					,			attention_head_dim=(2, 4)					,			use_linear_projection=lowerCamelCase					,			addition_embed_type="text_time"					,			addition_time_embed_dim=8					,			transformer_layers_per_block=(1, 2)					,			projection_class_embeddings_input_dim=80					,			cross_attention_dim=64					,			)
														__snake_case	:    Tuple											=     EulerDiscreteScheduler(
														    beta_start=0.0_00_85					,			beta_end=0.0_12					,			steps_offset=1					,			beta_schedule="scaled_linear"					,			timestep_spacing="leading"					,			)
														torch.manual_seed(0       )
														__snake_case	:    int											=     AutoencoderKL(
														    block_out_channels=[32, 64]					,			in_channels=3					,			out_channels=3					,			down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]					,			up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]					,			latent_channels=4					,			sample_size=128					,			)
														torch.manual_seed(0       )
														__snake_case	:    Optional[int]											=     CLIPTextConfig(
														    bos_token_id=0					,			eos_token_id=2					,			hidden_size=32					,			intermediate_size=37					,			layer_norm_eps=1E-05					,			num_attention_heads=4					,			num_hidden_layers=5					,			pad_token_id=1					,			vocab_size=1000					,			hidden_act="gelu"					,			projection_dim=32					,			)
														__snake_case	:    List[str]											=     CLIPTextModel(lowerCamelCase       )
														__snake_case	:    Any											=     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"					,			local_files_only=lowerCamelCase       )

														__snake_case	:    List[str]											=     CLIPTextModelWithProjection(lowerCamelCase       )
														__snake_case	:    List[Any]											=     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"					,			local_files_only=lowerCamelCase       )

														__snake_case	:    Optional[int]											=     {
														    "unet": unet,
														    "scheduler": scheduler,
														    "vae": vae,
														    "text_encoder": text_encoder,
														    "tokenizer": tokenizer,
														    "text_encoder_2": text_encoder_a,
														    "tokenizer_2": tokenizer_a,
														    # "safety_checker": None,
														    # "feature_extractor": None,
														}
														return components

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						List[Any]=0       )			->					Union[str, Any]:
														__snake_case	:    int											=     floats_tensor((1, 3, 32, 32)					,			rng=random.Random(lowerCamelCase       )       ).to(lowerCamelCase       )
														__snake_case	:    Any											=     image / 2 + 0.5
														if str(lowerCamelCase       ).startswith("mps"       ):
																					__snake_case	:    Dict											=     torch.manual_seed(lowerCamelCase       )
														else:
																					__snake_case	:    int											=     torch.Generator(device=lowerCamelCase       ).manual_seed(lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     {
														    "prompt": "A painting of a squirrel eating a burger",
														    "image": image,
														    "generator": generator,
														    "num_inference_steps": 2,
														    "guidance_scale": 5.0,
														    "output_type": "numpy",
														    "strength": 0.75,
														}
														return inputs

							def 					__snake_case      (							self :						Dict       )			->					Any:
														__snake_case	:    Dict											=     "cpu"  # ensure determinism for the device-dependent torch.Generator
														__snake_case	:    Any											=     self.get_dummy_components()
														__snake_case	:    int											=     StableDiffusionXLImgaImgPipeline(**lowerCamelCase       )
														__snake_case	:    List[str]											=     sd_pipe.to(lowerCamelCase       )
														sd_pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    Tuple											=     self.get_dummy_inputs(lowerCamelCase       )
														__snake_case	:    Dict											=     sd_pipe(**lowerCamelCase       ).images
														__snake_case	:    Dict											=     image[0, -3:, -3:, -1]

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

														__snake_case	:    str											=     np.array([0.46_56, 0.48_40, 0.44_39, 0.66_98, 0.55_74, 0.45_24, 0.57_99, 0.59_43, 0.51_65]       )

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

							def 					__snake_case      (							self :						str       )			->					Optional[Any]:
														super().test_attention_slicing_forward_pass(expected_max_diff=3E-3       )

							def 					__snake_case      (							self :						Any       )			->					Dict:
														super().test_inference_batch_single_identical(expected_max_diff=3E-3       )

							def 					__snake_case      (							self :						str       )			->					Optional[int]:
														pass






							def 					__snake_case      (							self :						Tuple       )			->					Union[str, Any]:
														__snake_case	:    str											=     self.get_dummy_components()
														__snake_case	:    List[Any]											=     StableDiffusionXLImgaImgPipeline(**lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     sd_pipe.to(lowerCamelCase       )
														__snake_case	:    int											=     sd_pipe.to(lowerCamelCase       )
														sd_pipe.set_progress_bar_config(disable=lowerCamelCase       )

														# forward without prompt embeds
														__snake_case	:    List[str]											=     self.get_dummy_inputs(lowerCamelCase       )
														__snake_case	:    str											=     3 * ["this is a negative prompt"]
														__snake_case	:    Any											=     negative_prompt
														__snake_case	:    Optional[Any]											=     3 * [inputs["prompt"]]

														__snake_case	:    int											=     sd_pipe(**lowerCamelCase       )
														__snake_case	:    List[Any]											=     output.images[0, -3:, -3:, -1]

														# forward with prompt embeds
														__snake_case	:    List[Any]											=     self.get_dummy_inputs(lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     3 * ["this is a negative prompt"]
														__snake_case	:    int											=     3 * [inputs.pop("prompt"       )]

														(
														    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    (
														    __snake_case
														)				,    
														)	:    Dict											=     sd_pipe.encode_prompt(lowerCamelCase					,			negative_prompt=lowerCamelCase       )

														__snake_case	:    Tuple											=     sd_pipe(
														    **lowerCamelCase					,			prompt_embeds=lowerCamelCase					,			negative_prompt_embeds=lowerCamelCase					,			pooled_prompt_embeds=lowerCamelCase					,			negative_pooled_prompt_embeds=lowerCamelCase					,			)
														__snake_case	:    List[str]											=     output.images[0, -3:, -3:, -1]

														# make sure that it's equal
														assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()       ).max() < 1E-4

@slow
@require_torch_gpu
class        a	(unittest.TestCase   ):




							"""simple docstring"""


							def 					__snake_case      (							self :						Optional[int]       )			->					Dict:
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()

							def 					__snake_case      (							self :						Optional[Any]					,			lowerCamelCase :						Any					,			lowerCamelCase :						Optional[Any]="cpu"					,			lowerCamelCase :						str=torch.floataa					,			lowerCamelCase :						int=0       )			->					Dict:
														__snake_case	:    int											=     torch.Generator(device=lowerCamelCase       ).manual_seed(lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     np.random.RandomState(lowerCamelCase       ).standard_normal((1, 4, 64, 64)       )
														__snake_case	:    Optional[Any]											=     torch.from_numpy(lowerCamelCase       ).to(device=lowerCamelCase					,			dtype=lowerCamelCase       )
														__snake_case	:    List[str]											=     {
														    "prompt": "a photograph of an astronaut riding a horse",
														    "latents": latents,
														    "generator": generator,
														    "num_inference_steps": 3,
														    "guidance_scale": 7.5,
														    "output_type": "numpy",
														}
														return inputs






							def 					__snake_case      (							self :						str       )			->					Any:
														__snake_case	:    List[str]											=     DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-base"       )
														pipe.to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    int											=     self.get_inputs(lowerCamelCase       )
														__snake_case	:    Optional[Any]											=     pipe(**lowerCamelCase       ).images
														__snake_case	:    Any											=     image[0, -3:, -3:, -1].flatten()

														assert image.shape == (1, 512, 512, 3)
														__snake_case	:    Optional[int]											=     np.array([0.4_94_93, 0.4_78_96, 0.4_07_98, 0.5_42_14, 0.5_32_12, 0.4_82_02, 0.4_76_56, 0.4_63_29, 0.4_85_06]       )
														assert np.abs(image_slice - expected_slice       ).max() < 7E-3

