
import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

				if is_vision_available():
								from transformers import MaskaFormerImageProcessor

if is_vision_available():
				from PIL import Image







class 				UpperCAmelCase						:

					def __init__(      self   :       Optional[Any]			,   lowerCAmelCase   :       List[str]			,   lowerCAmelCase   :       List[str]=2			,   lowerCAmelCase   :       Tuple=True			,   lowerCAmelCase   :       Any=False			,   lowerCAmelCase   :       Dict=10			,   lowerCAmelCase   :       List[str]=3			,   lowerCAmelCase   :       List[Any]=32 * 8			,   lowerCAmelCase   :       Optional[Any]=32 * 8			,   lowerCAmelCase   :       Optional[int]=4			,   lowerCAmelCase   :       int=64			,   ):
											lowercase							:     List[Any]									=	parent
											lowercase							:     Optional[Any]									=	batch_size
											lowercase							:     Any									=	is_training
											lowercase							:     str									=	use_auxiliary_loss
											lowercase							:     Dict									=	num_queries
											lowercase							:     List[Any]									=	num_channels
											lowercase							:     List[Any]									=	min_size
											lowercase							:     int									=	max_size
											lowercase							:     Dict									=	num_labels
											lowercase							:     str									=	hidden_dim
											lowercase							:     Optional[int]									=	hidden_dim

					def 							_lowerCAmelCase						(      self   :       Union[str, Any]       ):
											lowercase							:     Union[str, Any]									=	floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]       ).to(
											    _UpperCAmelCase       )

											lowercase							:     int									=	torch.ones([self.batch_size, self.min_size, self.max_size]			,   device=_UpperCAmelCase       )

											lowercase							:     List[Any]									=	(
											    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]			,   device=_UpperCAmelCase       ) > 0.5
											).float()
											lowercase							:     str									=	(torch.rand((self.batch_size, self.num_labels)			,   device=_UpperCAmelCase       ) > 0.5).long()

											lowercase							:     Union[str, Any]									=	self.get_config()
											return config, pixel_values, pixel_mask, mask_labels, class_labels

					def 							_lowerCAmelCase						(      self   :       List[str]       ):
											lowercase							:     int									=	MaskaFormerConfig(
											    hidden_size=self.hidden_dim			,   )
											lowercase							:     List[str]									=	self.num_queries
											lowercase							:     List[Any]									=	self.num_labels

											lowercase							:     str									=	[1, 1, 1, 1]
											lowercase							:     List[Any]									=	self.num_channels

											lowercase							:     Optional[int]									=	64
											lowercase							:     List[str]									=	128
											lowercase							:     Union[str, Any]									=	self.hidden_dim
											lowercase							:     Optional[Any]									=	self.hidden_dim
											lowercase							:     Optional[int]									=	self.hidden_dim
											return config

					def 							_lowerCAmelCase						(      self   :       str       ):
											lowercase							:     Tuple									=	self.prepare_config_and_inputs()
											lowercase							:     List[Any]									=	{'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
											return config, inputs_dict

					def 							_lowerCAmelCase						(      self   :       List[str]			,   lowerCAmelCase   :       int			,   lowerCAmelCase   :       Any       ):
											lowercase							:     Optional[Any]									=	output.encoder_hidden_states
											lowercase							:     List[str]									=	output.pixel_decoder_hidden_states
											lowercase							:     Dict									=	output.transformer_decoder_hidden_states

											self.parent.assertTrue(len(_UpperCAmelCase       )			,   len(config.backbone_config.depths       )       )
											self.parent.assertTrue(len(_UpperCAmelCase       )			,   len(config.backbone_config.depths       )       )
											self.parent.assertTrue(len(_UpperCAmelCase       )			,   config.decoder_layers       )

					def 							_lowerCAmelCase						(      self   :       Any			,   lowerCAmelCase   :       Union[str, Any]			,   lowerCAmelCase   :       int			,   lowerCAmelCase   :       Optional[int]			,   lowerCAmelCase   :       Optional[Any]=False       ):
											with torch.no_grad():
																	lowercase							:     Union[str, Any]									=	MaskaFormerModel(config=_UpperCAmelCase       )
																	model.to(_UpperCAmelCase       )
																	model.eval()

																	lowercase							:     Tuple									=	model(pixel_values=_UpperCAmelCase			,   pixel_mask=_UpperCAmelCase       )
																	lowercase							:     Tuple									=	model(_UpperCAmelCase			,   output_hidden_states=_UpperCAmelCase       )

											self.parent.assertEqual(
											    output.transformer_decoder_last_hidden_state.shape			,   (self.batch_size, self.num_queries, self.hidden_dim)			,   )
											# let's ensure the other two hidden state exists
											self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None       )
											self.parent.assertTrue(output.encoder_last_hidden_state is not None       )

											if output_hidden_states:
																	self.check_output_hidden_state(_UpperCAmelCase			,   _UpperCAmelCase       )




					def 							_lowerCAmelCase						(      self   :       List[Any]			,   lowerCAmelCase   :       Dict			,   lowerCAmelCase   :       int			,   lowerCAmelCase   :       Union[str, Any]			,   lowerCAmelCase   :       str			,   lowerCAmelCase   :       Any       ):
											lowercase							:     List[Any]									=	MaskaFormerForUniversalSegmentation(config=_UpperCAmelCase       )
											model.to(_UpperCAmelCase       )
											model.eval()

											def comm_check_on_output(lowerCAmelCase   :       Tuple       ):
																	# let's still check that all the required stuff is there
																	self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None       )
																	self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None       )
																	self.parent.assertTrue(result.encoder_last_hidden_state is not None       )
																	# okay, now we need to check the logits shape
																	# due to the encoder compression, masks have a //4 spatial size
																	self.parent.assertEqual(
																	    result.masks_queries_logits.shape			,   (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)			,   )
																	# + 1 for null class
																	self.parent.assertEqual(
																	    result.class_queries_logits.shape			,   (self.batch_size, self.num_queries, self.num_labels + 1)       )

											with torch.no_grad():
																	lowercase							:     str									=	model(pixel_values=_UpperCAmelCase			,   pixel_mask=_UpperCAmelCase       )
																	lowercase							:     int									=	model(_UpperCAmelCase       )

																	comm_check_on_output(_UpperCAmelCase       )

																	lowercase							:     str									=	model(
																	    pixel_values=_UpperCAmelCase			,   pixel_mask=_UpperCAmelCase			,   mask_labels=_UpperCAmelCase			,   class_labels=_UpperCAmelCase       )

											comm_check_on_output(_UpperCAmelCase       )

											self.parent.assertTrue(result.loss is not None       )
											self.parent.assertEqual(result.loss.shape			,   torch.Size([1]       )       )







@require_torch
class 				UpperCAmelCase						( _UpperCamelCase    ,			_UpperCamelCase    ,			unittest.TestCase       ):
					a__:			Union[str, Any]      	=					(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
					a__:			Optional[Any]      	=					{'feature-extraction': MaskaFormerModel} if is_torch_available() else {}

					a__:			Any      	=					False
					a__:			Any      	=					False
					a__:			str      	=					False
					a__:			str      	=					False

					def 							_lowerCAmelCase						(      self   :       Dict       ):
											lowercase							:     int									=	MaskaFormerModelTester(self       )
											lowercase							:     Tuple									=	ConfigTester(self			,   config_class=_UpperCAmelCase			,   has_text_modality=_UpperCAmelCase       )

					def 							_lowerCAmelCase						(      self   :       Optional[Any]       ):
											self.config_tester.run_common_tests()

					def 							_lowerCAmelCase						(      self   :       Dict       ):
											lowercase							:     Union[str, Any]									=	self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.create_and_check_maskaformer_model(_UpperCAmelCase			,   **_UpperCAmelCase			,   output_hidden_states=_UpperCAmelCase       )

					def 							_lowerCAmelCase						(      self   :       Optional[int]       ):
											lowercase							:     List[Any]									=	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*_UpperCAmelCase       )

					@unittest.skip(reason='''Mask2Former does not use inputs_embeds'''       )
					def 							_lowerCAmelCase						(      self   :       Tuple       ):
											pass

					@unittest.skip(reason='''Mask2Former does not have a get_input_embeddings method'''       )
					def 							_lowerCAmelCase						(      self   :       Union[str, Any]       ):
											pass

					@unittest.skip(reason='''Mask2Former is not a generative model'''       )
					def 							_lowerCAmelCase						(      self   :       Tuple       ):
											pass

					@unittest.skip(reason='''Mask2Former does not use token embeddings'''       )
					def 							_lowerCAmelCase						(      self   :       Tuple       ):
											pass

					@require_torch_multi_gpu
					@unittest.skip(
					    reason='''Mask2Former has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''       )
					def 							_lowerCAmelCase						(      self   :       List[Any]       ):
											pass

					@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''       )
					def 							_lowerCAmelCase						(      self   :       int       ):
											pass

					def 							_lowerCAmelCase						(      self   :       Union[str, Any]       ):
											lowercase							:     List[Any]									=	self.model_tester.prepare_config_and_inputs_for_common()

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

																	lowercase							:     Optional[int]									=	['pixel_values']
																	self.assertListEqual(arg_names[:1]			,   _UpperCAmelCase       )

					@slow
					def 							_lowerCAmelCase						(      self   :       List[str]       ):
											for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
																	lowercase							:     Union[str, Any]									=	MaskaFormerModel.from_pretrained(_UpperCAmelCase       )
																	self.assertIsNotNone(_UpperCAmelCase       )

					def 							_lowerCAmelCase						(      self   :       Dict       ):
											lowercase							:     Dict									=	(self.model_tester.min_size,) * 2
											lowercase							:     Union[str, Any]									=	{
											    'pixel_values': torch.randn((2, 3, *size)			,   device=_UpperCAmelCase       ),
											    'mask_labels': torch.randn((2, 10, *size)			,   device=_UpperCAmelCase       ),
											    'class_labels': torch.zeros(2			,   10			,   device=_UpperCAmelCase       ).long(),
											}
											lowercase							:     Dict									=	self.model_tester.get_config()

											lowercase							:     List[str]									=	MaskaFormerForUniversalSegmentation(_UpperCAmelCase       ).to(_UpperCAmelCase       )
											lowercase							:     Tuple									=	model(**_UpperCAmelCase       )
											self.assertTrue(outputs.loss is not None       )

					def 							_lowerCAmelCase						(      self   :       List[Any]       ):
											lowercase							:     Dict									=	self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.create_and_check_maskaformer_model(_UpperCAmelCase			,   **_UpperCAmelCase			,   output_hidden_states=_UpperCAmelCase       )

					def 							_lowerCAmelCase						(      self   :       Union[str, Any]       ):
											lowercase							:     str									=	self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																	lowercase							:     List[Any]									=	model_class(_UpperCAmelCase       ).to(_UpperCAmelCase       )
																	lowercase							:     int									=	model(**_UpperCAmelCase			,   output_attentions=_UpperCAmelCase       )
																	self.assertTrue(outputs.attentions is not None       )

					def 							_lowerCAmelCase						(      self   :       List[Any]       ):
											if not self.model_tester.is_training:
																	return

											lowercase							:     List[Any]									=	self.all_model_classes[1]
											lowercase							:     int									=	self.model_tester.prepare_config_and_inputs()

											lowercase							:     Any									=	model_class(_UpperCAmelCase       )
											model.to(_UpperCAmelCase       )
											model.train()

											lowercase							:     int									=	model(_UpperCAmelCase			,   mask_labels=_UpperCAmelCase			,   class_labels=_UpperCAmelCase       ).loss
											loss.backward()




					def 							_lowerCAmelCase						(      self   :       Optional[Any]       ):
											lowercase							:     Optional[int]									=	self.all_model_classes[1]
											lowercase							:     Any									=	self.model_tester.prepare_config_and_inputs()
											lowercase							:     Optional[Any]									=	True
											lowercase							:     Tuple									=	True

											lowercase							:     int									=	model_class(_UpperCAmelCase       ).to(_UpperCAmelCase       )
											model.train()

											lowercase							:     int									=	model(_UpperCAmelCase			,   mask_labels=_UpperCAmelCase			,   class_labels=_UpperCAmelCase       )

											lowercase							:     List[Any]									=	outputs.encoder_hidden_states[0]
											encoder_hidden_states.retain_grad()

											lowercase							:     Tuple									=	outputs.pixel_decoder_hidden_states[0]
											pixel_decoder_hidden_states.retain_grad()

											lowercase							:     List[str]									=	outputs.transformer_decoder_hidden_states[0]
											transformer_decoder_hidden_states.retain_grad()

											lowercase							:     Optional[Any]									=	outputs.attentions[0]
											attentions.retain_grad()

											outputs.loss.backward(retain_graph=_UpperCAmelCase       )

											self.assertIsNotNone(encoder_hidden_states.grad       )
											self.assertIsNotNone(pixel_decoder_hidden_states.grad       )
											self.assertIsNotNone(transformer_decoder_hidden_states.grad       )
											self.assertIsNotNone(attentions.grad       )





snake_case__					=				1e-4

def 							lowerCamelCase_   (      ):
						lowercase							:     Union[str, Any]									=	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
						return image







@require_vision
@slow
class 				UpperCAmelCase						( unittest.TestCase       ):

					@cached_property
					def 							_lowerCAmelCase						(      self   :       Union[str, Any]       ):
											return "facebook/mask2former-swin-small-coco-instance"

					@cached_property
					def 							_lowerCAmelCase						(      self   :       List[Any]       ):
											return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints       ) if is_vision_available() else None

					def 							_lowerCAmelCase						(      self   :       int       ):
											lowercase							:     Tuple									=	MaskaFormerModel.from_pretrained(self.model_checkpoints       ).to(_UpperCAmelCase       )
											lowercase							:     Optional[int]									=	self.default_image_processor
											lowercase							:     List[str]									=	prepare_img()
											lowercase							:     int									=	image_processor(_UpperCAmelCase			,   return_tensors='''pt'''       ).to(_UpperCAmelCase       )
											lowercase							:     int									=	inputs['pixel_values'].shape
											# check size is divisible by 32
											self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0       )
											# check size
											self.assertEqual(_UpperCAmelCase			,   (1, 3, 384, 384)       )

											with torch.no_grad():
																	lowercase							:     List[str]									=	model(**_UpperCAmelCase       )

											lowercase							:     Dict									=	torch.tensor(
											    [[-0.27_90, -1.07_17, -1.16_68], [-0.51_28, -0.31_28, -0.49_87], [-0.58_32, 0.19_71, -0.01_97]]       ).to(_UpperCAmelCase       )
											self.assertTrue(
											    torch.allclose(
											        outputs.encoder_last_hidden_state[0, 0, :3, :3]			,   _UpperCAmelCase			,   atol=_UpperCAmelCase       )       )

											lowercase							:     List[str]									=	torch.tensor(
											    [[0.89_73, 1.18_47, 1.17_76], [1.19_34, 1.50_40, 1.51_28], [1.11_53, 1.44_86, 1.49_51]]       ).to(_UpperCAmelCase       )
											self.assertTrue(
											    torch.allclose(
											        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]			,   _UpperCAmelCase			,   atol=_UpperCAmelCase       )       )

											lowercase							:     Any									=	torch.tensor(
											    [[2.11_52, 1.70_00, -0.86_03], [1.58_08, 1.80_04, -0.93_53], [1.60_43, 1.74_95, -0.59_99]]       ).to(_UpperCAmelCase       )
											self.assertTrue(
											    torch.allclose(
											        outputs.transformer_decoder_last_hidden_state[0, :3, :3]			,   _UpperCAmelCase			,   atol=_UpperCAmelCase       )       )

					def 							_lowerCAmelCase						(      self   :       List[Any]       ):
											lowercase							:     Tuple									=	MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints       ).to(_UpperCAmelCase       ).eval()
											lowercase							:     List[str]									=	self.default_image_processor
											lowercase							:     Union[str, Any]									=	prepare_img()
											lowercase							:     Optional[Any]									=	image_processor(_UpperCAmelCase			,   return_tensors='''pt'''       ).to(_UpperCAmelCase       )
											lowercase							:     Any									=	inputs['pixel_values'].shape
											# check size is divisible by 32
											self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0       )
											# check size
											self.assertEqual(_UpperCAmelCase			,   (1, 3, 384, 384)       )

											with torch.no_grad():
																	lowercase							:     Any									=	model(**_UpperCAmelCase       )
											# masks_queries_logits
											lowercase							:     List[str]									=	outputs.masks_queries_logits
											self.assertEqual(
											    masks_queries_logits.shape			,   (1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       )
											lowercase							:     Optional[Any]									=	[
											    [-8.78_39, -9.00_56, -8.81_21],
											    [-7.41_04, -7.03_13, -6.54_01],
											    [-6.61_05, -6.34_27, -6.46_75],
											]
											lowercase							:     List[str]									=	torch.tensor(_UpperCAmelCase       ).to(_UpperCAmelCase       )
											self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			,   _UpperCAmelCase			,   atol=_UpperCAmelCase       )       )
											# class_queries_logits
											lowercase							:     Any									=	outputs.class_queries_logits
											self.assertEqual(class_queries_logits.shape			,   (1, model.config.num_queries, model.config.num_labels + 1)       )
											lowercase							:     Dict									=	torch.tensor(
											    [
											        [1.83_24, -8.08_35, -4.19_22],
											        [0.84_50, -9.00_50, -3.60_53],
											        [0.30_45, -7.72_93, -3.02_75],
											    ]       ).to(_UpperCAmelCase       )
											self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			,   _UpperCAmelCase			,   atol=_UpperCAmelCase       )       )




					def 							_lowerCAmelCase						(      self   :       Tuple       ):
											lowercase							:     str									=	MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints       ).to(_UpperCAmelCase       ).eval()
											lowercase							:     List[Any]									=	self.default_image_processor

											lowercase							:     Union[str, Any]									=	image_processor(
											    [np.zeros((3, 800, 1333)       ), np.zeros((3, 800, 1333)       )]			,   segmentation_maps=[np.zeros((384, 384)       ).astype(np.floataa       ), np.zeros((384, 384)       ).astype(np.floataa       )]			,   return_tensors='''pt'''			,   )

											lowercase							:     int									=	inputs['pixel_values'].to(_UpperCAmelCase       )
											lowercase							:     List[Any]									=	[el.to(_UpperCAmelCase       ) for el in inputs['mask_labels']]
											lowercase							:     Any									=	[el.to(_UpperCAmelCase       ) for el in inputs['class_labels']]

											with torch.no_grad():
																	lowercase							:     Optional[int]									=	model(**_UpperCAmelCase       )

											self.assertTrue(outputs.loss is not None       )







'''simple docstring'''

import unittest

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

from diffusers import DDIMScheduler, LDMPipeline, UNetaDModel, VQModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()

class       __magic_name__		(       unittest.TestCase  ):







							@property
							def 				__lowercase     (				self   :			int						):
									torch.manual_seed(0						)
									_a	: int								=				UNetaDModel(
									    block_out_channels=(32, 64)      ,layers_per_block=2      ,sample_size=32      ,in_channels=3      ,out_channels=3      ,down_block_types=('DownBlock2D', 'AttnDownBlock2D')      ,up_block_types=('AttnUpBlock2D', 'UpBlock2D')      ,)
									return model







							@property
							def 				__lowercase     (				self   :			Any						):
									torch.manual_seed(0						)
									_a	: int								=				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







							@property
							def 				__lowercase     (				self   :			Union[str, Any]						):
									torch.manual_seed(0						)
									_a	: Dict								=				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      ,)
									return CLIPTextModel(_UpperCAmelCase						)







							def 				__lowercase     (				self   :			Dict						):
									_a	: Union[str, Any]								=				self.dummy_uncond_unet
									_a	: Union[str, Any]								=				DDIMScheduler()
									_a	: Union[str, Any]								=				self.dummy_vq_model

									_a	: List[Any]								=				LDMPipeline(unet=_UpperCAmelCase      ,vqvae=_UpperCAmelCase      ,scheduler=_UpperCAmelCase						)
									ldm.to(_UpperCAmelCase						)
									ldm.set_progress_bar_config(disable=_UpperCAmelCase						)

									_a	: Dict								=				torch.manual_seed(0						)
									_a	: int								=				ldm(generator=_UpperCAmelCase      ,num_inference_steps=2      ,output_type='numpy'						).images

									_a	: Tuple								=				torch.manual_seed(0						)
									_a	: List[Any]								=				ldm(generator=_UpperCAmelCase      ,num_inference_steps=2      ,output_type='numpy'      ,return_dict=_UpperCAmelCase						)[0]

									_a	: Any								=				image[0, -3:, -3:, -1]
									_a	: List[Any]								=				image_from_tuple[0, -3:, -3:, -1]

									assert image.shape == (1, 64, 64, 3)
									_a	: Union[str, Any]								=				np.array([0.85_12, 0.8_18, 0.64_11, 0.68_08, 0.44_65, 0.56_18, 0.46, 0.62_31, 0.51_72]						)
									_a	: Any								=				1E-2 if torch_device != 'mps' else 3E-2

									assert np.abs(image_slice.flatten() - expected_slice						).max() < tolerance
									assert np.abs(image_from_tuple_slice.flatten() - expected_slice						).max() < tolerance

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







							def 				__lowercase     (				self   :			Optional[int]						):
									_a	: Dict								=				LDMPipeline.from_pretrained('CompVis/ldm-celebahq-256'						)
									ldm.to(_UpperCAmelCase						)
									ldm.set_progress_bar_config(disable=_UpperCAmelCase						)

									_a	: str								=				torch.manual_seed(0						)
									_a	: Optional[Any]								=				ldm(generator=_UpperCAmelCase      ,num_inference_steps=5      ,output_type='numpy'						).images

									_a	: Optional[Any]								=				image[0, -3:, -3:, -1]

									assert image.shape == (1, 256, 256, 3)
									_a	: Union[str, Any]								=				np.array([0.43_99, 0.4_49_75, 0.4_68_25, 0.4_74, 0.43_59, 0.45_81, 0.4_50_95, 0.43_41, 0.44_47]						)
									_a	: List[str]								=				1E-2 if torch_device != 'mps' else 3E-2

									assert np.abs(image_slice.flatten() - expected_slice						).max() < tolerance




