


'''simple docstring'''







import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, 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 MaskFormerForInstanceSegmentation, MaskFormerModel

  if is_vision_available():
    from transformers import MaskFormerImageProcessor

if is_vision_available():
  from PIL import Image
class 					lowercase_     :


    def __init__(     self  ,					a  ,					a=2  ,					a=True  ,					a=False  ,					a=10  ,					a=3  ,					a=32 * 4  ,					a=32 * 6  ,					a=4  ,					a=32  ,					):
          UpperCamelCase__										=				parent
          UpperCamelCase__										=				batch_size
          UpperCamelCase__										=				is_training
          UpperCamelCase__										=				use_auxiliary_loss
          UpperCamelCase__										=				num_queries
          UpperCamelCase__										=				num_channels
          UpperCamelCase__										=				min_size
          UpperCamelCase__										=				max_size
          UpperCamelCase__										=				num_labels
          UpperCamelCase__										=				mask_feature_size


    def    __a							(     self    ):
          UpperCamelCase__										=				floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]    ).to(
              a    )

          UpperCamelCase__										=				torch.ones([self.batch_size, self.min_size, self.max_size]  ,					device=a    )

          UpperCamelCase__										=				(
              torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]  ,					device=a    ) > 0.5
          ).float()
          UpperCamelCase__										=				(torch.rand((self.batch_size, self.num_labels)  ,					device=a    ) > 0.5).long()

          UpperCamelCase__										=				self.get_config()
          return config, pixel_values, pixel_mask, mask_labels, class_labels


    def    __a							(     self    ):
          return MaskFormerConfig.from_backbone_and_decoder_configs(
              backbone_config=SwinConfig(
                  depths=[1, 1, 1, 1]  ,					)  ,					decoder_config=DetrConfig(
                  decoder_ffn_dim=1_28  ,					num_queries=self.num_queries  ,					decoder_attention_heads=2  ,					d_model=self.mask_feature_size  ,					)  ,					mask_feature_size=self.mask_feature_size  ,					fpn_feature_size=self.mask_feature_size  ,					num_channels=self.num_channels  ,					num_labels=self.num_labels  ,					)


    def    __a							(     self    ):
          UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__										=				self.prepare_config_and_inputs()
          UpperCamelCase__										=				{"pixel_values": pixel_values, "pixel_mask": pixel_mask}
          return config, inputs_dict


    def    __a							(     self  ,					a  ,					a    ):
          UpperCamelCase__										=				output.encoder_hidden_states
          UpperCamelCase__										=				output.pixel_decoder_hidden_states
          UpperCamelCase__										=				output.transformer_decoder_hidden_states

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


    def    __a							(     self  ,					a  ,					a  ,					a  ,					a=False    ):
          with torch.no_grad():
                UpperCamelCase__										=				MaskFormerModel(config=a    )
                model.to(a    )
                model.eval()

                UpperCamelCase__										=				model(pixel_values=a  ,					pixel_mask=a    )
                UpperCamelCase__										=				model(a  ,					output_hidden_states=a    )
          # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
          # encoder and pixel decoder
          self.parent.assertEqual(
              output.transformer_decoder_last_hidden_state.shape  ,					(self.batch_size, self.num_queries, self.mask_feature_size)  ,					)
          # 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(a  ,					a    )


    def    __a							(     self  ,					a  ,					a  ,					a  ,					a  ,					a    ):
          UpperCamelCase__										=				MaskFormerForInstanceSegmentation(config=a    )
          model.to(a    )
          model.eval()

          def comm_check_on_output(a    ):
                # 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():
                UpperCamelCase__										=				model(pixel_values=a  ,					pixel_mask=a    )
                UpperCamelCase__										=				model(a    )

                comm_check_on_output(a    )

                UpperCamelCase__										=				model(
                    pixel_values=a  ,					pixel_mask=a  ,					mask_labels=a  ,					class_labels=a    )

          comm_check_on_output(a    )

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

@require_torch
class 					lowercase_     (    a__  ,						a__  ,						unittest.TestCase   ):
    __UpperCAmelCase   			=	(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
    __UpperCAmelCase   			=	(
        {'feature-extraction': MaskFormerModel, 'image-segmentation': MaskFormerForInstanceSegmentation}
        if is_torch_available()
        else {}
    )

    __UpperCAmelCase   			=	False
    __UpperCAmelCase   			=	False
    __UpperCAmelCase   			=	False
    __UpperCAmelCase   			=	False


    def    __a							(     self    ):
          UpperCamelCase__										=				MaskFormerModelTester(self    )
          UpperCamelCase__										=				ConfigTester(self  ,					config_class=a  ,					has_text_modality=a    )


    def    __a							(     self    ):
          self.config_tester.run_common_tests()


    def    __a							(     self    ):
          UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs_for_common()
          self.model_tester.create_and_check_maskformer_model(a  ,					**a  ,					output_hidden_states=a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*a    )


    @unittest.skip(reason="MaskFormer does not use inputs_embeds"    )
    def    __a							(     self    ):
          pass


    @unittest.skip(reason="MaskFormer does not have a get_input_embeddings method"    )
    def    __a							(     self    ):
          pass


    @unittest.skip(reason="MaskFormer is not a generative model"    )
    def    __a							(     self    ):
          pass


    @unittest.skip(reason="MaskFormer does not use token embeddings"    )
    def    __a							(     self    ):
          pass


    @require_torch_multi_gpu
    @unittest.skip(
        reason="MaskFormer has some layers using `add_module` which doesn't work well with `nn.DataParallel`"    )
    def    __a							(     self    ):
          pass


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


    def    __a							(     self    ):
          UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs_for_common()

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

                UpperCamelCase__										=				["pixel_values"]
                self.assertListEqual(arg_names[:1]  ,					a    )


    @slow
    def    __a							(     self    ):
          for model_name in ["facebook/maskformer-swin-small-coco"]:
                UpperCamelCase__										=				MaskFormerModel.from_pretrained(a    )
                self.assertIsNotNone(a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				(self.model_tester.min_size,) * 2
          UpperCamelCase__										=				{
              "pixel_values": torch.randn((2, 3, *size)  ,					device=a    ),
              "mask_labels": torch.randn((2, 10, *size)  ,					device=a    ),
              "class_labels": torch.zeros(2  ,					10  ,					device=a    ).long(),
          }

          UpperCamelCase__										=				MaskFormerForInstanceSegmentation(MaskFormerConfig()    ).to(a    )
          UpperCamelCase__										=				model(**a    )
          self.assertTrue(outputs.loss is not None    )


    def    __a							(     self    ):
          UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs_for_common()
          self.model_tester.create_and_check_maskformer_model(a  ,					**a  ,					output_hidden_states=a    )


    def    __a							(     self    ):
          UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
                UpperCamelCase__										=				model_class(a    ).to(a    )
                UpperCamelCase__										=				model(**a  ,					output_attentions=a    )
                self.assertTrue(outputs.attentions is not None    )


    def    __a							(     self    ):
          if not self.model_tester.is_training:
                return
          # only MaskFormerForInstanceSegmentation has the loss
          UpperCamelCase__										=				self.all_model_classes[1]
          UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()

          UpperCamelCase__										=				model_class(a    )
          model.to(a    )
          model.train()

          UpperCamelCase__										=				model(a  ,					mask_labels=a  ,					class_labels=a    ).loss
          loss.backward()


    def    __a							(     self    ):
          # only MaskFormerForInstanceSegmentation has the loss
          UpperCamelCase__										=				self.all_model_classes[1]
          UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          UpperCamelCase__										=				True
          UpperCamelCase__										=				True

          UpperCamelCase__										=				model_class(a    )
          model.to(a    )
          model.train()

          UpperCamelCase__										=				model(a  ,					mask_labels=a  ,					class_labels=a    )

          UpperCamelCase__										=				outputs.encoder_hidden_states[0]
          encoder_hidden_states.retain_grad()

          UpperCamelCase__										=				outputs.pixel_decoder_hidden_states[0]
          pixel_decoder_hidden_states.retain_grad()
          # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
          UpperCamelCase__										=				outputs.transformer_decoder_hidden_states[0]
          transformer_decoder_hidden_states.retain_grad()

          UpperCamelCase__										=				outputs.attentions[0]
          attentions.retain_grad()

          outputs.loss.backward(retain_graph=a    )

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

a__  :					Tuple        =       1E-4







def _UpperCamelCase       (     )							->		List[str]:


      '''simple docstring'''



      UpperCamelCase__										=				Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
      return image



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


    @cached_property
    def    __a							(     self    ):
          return (
              MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"    )
              if is_vision_available()
              else None
          )


    def    __a							(     self    ):
          UpperCamelCase__										=				MaskFormerModel.from_pretrained("facebook/maskformer-swin-small-coco"    ).to(a    )
          UpperCamelCase__										=				self.default_image_processor
          UpperCamelCase__										=				prepare_img()
          UpperCamelCase__										=				image_processor(a  ,					return_tensors="pt"    ).to(a    )
          UpperCamelCase__										=				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(a  ,					(1, 3, 8_00, 10_88)    )

          with torch.no_grad():
                UpperCamelCase__										=				model(**a    )

          UpperCamelCase__										=				torch.tensor(
              [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]    ).to(a    )
          self.assertTrue(
              torch.allclose(
                  outputs.encoder_last_hidden_state[0, 0, :3, :3]  ,					a  ,					atol=a    )    )

          UpperCamelCase__										=				torch.tensor(
              [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]    ).to(a    )
          self.assertTrue(
              torch.allclose(
                  outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]  ,					a  ,					atol=a    )    )

          UpperCamelCase__										=				torch.tensor(
              [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]    ).to(a    )
          self.assertTrue(
              torch.allclose(
                  outputs.transformer_decoder_last_hidden_state[0, :3, :3]  ,					a  ,					atol=a    )    )


    def    __a							(     self    ):
          UpperCamelCase__										=				(
              MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
              .to(a    )
              .eval()
          )
          UpperCamelCase__										=				self.default_image_processor
          UpperCamelCase__										=				prepare_img()
          UpperCamelCase__										=				image_processor(a  ,					return_tensors="pt"    ).to(a    )
          UpperCamelCase__										=				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(a  ,					(1, 3, 8_00, 10_88)    )

          with torch.no_grad():
                UpperCamelCase__										=				model(**a    )
          # masks_queries_logits
          UpperCamelCase__										=				outputs.masks_queries_logits
          self.assertEqual(
              masks_queries_logits.shape  ,					(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)  ,					)
          UpperCamelCase__										=				[
              [-1.373_7124, -1.772_4937, -1.936_4233],
              [-1.597_7281, -1.986_7939, -2.152_3695],
              [-1.579_5398, -1.926_9832, -2.09_3942],
          ]
          UpperCamelCase__										=				torch.tensor(a    ).to(a    )
          self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]  ,					a  ,					atol=a    )    )
          # class_queries_logits
          UpperCamelCase__										=				outputs.class_queries_logits
          self.assertEqual(
              class_queries_logits.shape  ,					(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
          UpperCamelCase__										=				torch.tensor(
              [
                  [1.65_12e00, -5.25_72e00, -3.35_19e00],
                  [3.61_69e-02, -5.90_25e00, -2.93_13e00],
                  [1.07_66e-04, -7.76_30e00, -5.12_63e00],
              ]    ).to(a    )
          self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]  ,					a  ,					atol=a    )    )


    def    __a							(     self    ):
          UpperCamelCase__										=				(
              MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-resnet101-coco-stuff"    )
              .to(a    )
              .eval()
          )
          UpperCamelCase__										=				self.default_image_processor
          UpperCamelCase__										=				prepare_img()
          UpperCamelCase__										=				image_processor(a  ,					return_tensors="pt"    ).to(a    )
          UpperCamelCase__										=				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(a  ,					(1, 3, 8_00, 10_88)    )

          with torch.no_grad():
                UpperCamelCase__										=				model(**a    )
          # masks_queries_logits
          UpperCamelCase__										=				outputs.masks_queries_logits
          self.assertEqual(
              masks_queries_logits.shape  ,					(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)  ,					)
          UpperCamelCase__										=				[[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
          UpperCamelCase__										=				torch.tensor(a    ).to(a    )
          self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]  ,					a  ,					atol=a    )    )
          # class_queries_logits
          UpperCamelCase__										=				outputs.class_queries_logits
          self.assertEqual(
              class_queries_logits.shape  ,					(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
          UpperCamelCase__										=				torch.tensor(
              [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]    ).to(a    )
          self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]  ,					a  ,					atol=a    )    )


    def    __a							(     self    ):
          UpperCamelCase__										=				(
              MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
              .to(a    )
              .eval()
          )
          UpperCamelCase__										=				self.default_image_processor

          UpperCamelCase__										=				image_processor(
              [np.zeros((3, 8_00, 13_33)    ), np.zeros((3, 8_00, 13_33)    )]  ,					segmentation_maps=[np.zeros((3_84, 3_84)    ).astype(np.floataa    ), np.zeros((3_84, 3_84)    ).astype(np.floataa    )]  ,					return_tensors="pt"  ,					)

          UpperCamelCase__										=				inputs["pixel_values"].to(a    )
          UpperCamelCase__										=				[el.to(a    ) for el in inputs["mask_labels"]]
          UpperCamelCase__										=				[el.to(a    ) for el in inputs["class_labels"]]

          with torch.no_grad():
                UpperCamelCase__										=				model(**a    )

          self.assertTrue(outputs.loss is not None    )







import unittest

import numpy as np
import torch
from torch import nn
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import KandinskyVaaPriorPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import enable_full_determinism, skip_mps

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




class  lowerCamelCase__							(				__lowercase     ,						unittest.TestCase):




	'''simple docstring'''




	_A								=     KandinskyVaaPriorPipeline
	_A								=     ['prompt']
	_A								=     ['prompt', 'negative_prompt']
	_A								=     [
	    'num_images_per_prompt',
	    'generator',
	    'num_inference_steps',
	    'latents',
	    'negative_prompt',
	    'guidance_scale',
	    'output_type',
	    'return_dict',
	]
	_A								=     False







	@property
	def    _lowerCamelCase				(					self		:Tuple						)		-> Optional[Any]:
								return 3_2







	@property
	def    _lowerCamelCase				(					self		:List[str]						)		-> List[str]:
								return 3_2







	@property
	def    _lowerCamelCase				(					self		:Union[str, Any]						)		-> Tuple:
								return self.time_input_dim







	@property
	def    _lowerCamelCase				(					self		:Union[str, Any]						)		-> Any:
								return self.time_input_dim * 4







	@property
	def    _lowerCamelCase				(					self		:Tuple						)		-> str:
								return 1_0_0







	@property
	def    _lowerCamelCase				(					self		:Union[str, Any]						)		-> Any:
								__UpperCamelCase	:   int			   =					CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"						)
								return tokenizer







	@property
	def    _lowerCamelCase				(					self		:str						)		-> int:
								torch.manual_seed(0						)
								__UpperCamelCase	:   Optional[int]			   =					CLIPTextConfig(
								    bos_token_id=0     ,   eos_token_id=2     ,   hidden_size=self.text_embedder_hidden_size     ,   projection_dim=self.text_embedder_hidden_size     ,   intermediate_size=3_7     ,   layer_norm_eps=1E-0_5     ,   num_attention_heads=4     ,   num_hidden_layers=5     ,   pad_token_id=1     ,   vocab_size=1_0_0_0     ,   )
								return CLIPTextModelWithProjection(a						)







	@property
	def    _lowerCamelCase				(					self		:int						)		-> Optional[Any]:
								torch.manual_seed(0						)

								__UpperCamelCase	:   Optional[int]			   =					{
								    "num_attention_heads": 2,
								    "attention_head_dim": 1_2,
								    "embedding_dim": self.text_embedder_hidden_size,
								    "num_layers": 1,
								}

								__UpperCamelCase	:   List[Any]			   =					PriorTransformer(**a						)
								# clip_std and clip_mean is initialized to be 0 so PriorTransformer.post_process_latents will always return 0 - set clip_std to be 1 so it won't return 0
								__UpperCamelCase	:   Optional[int]			   =					nn.Parameter(torch.ones(model.clip_std.shape						)						)
								return model







	@property
	def    _lowerCamelCase				(					self		:Dict						)		-> Union[str, Any]:
								torch.manual_seed(0						)
								__UpperCamelCase	:   Union[str, Any]			   =					CLIPVisionConfig(
								    hidden_size=self.text_embedder_hidden_size     ,   image_size=2_2_4     ,   projection_dim=self.text_embedder_hidden_size     ,   intermediate_size=3_7     ,   num_attention_heads=4     ,   num_channels=3     ,   num_hidden_layers=5     ,   patch_size=1_4     ,   )

								__UpperCamelCase	:   int			   =					CLIPVisionModelWithProjection(a						)
								return model







	@property
	def    _lowerCamelCase				(					self		:Dict						)		-> Optional[Any]:
								__UpperCamelCase	:   List[str]			   =					CLIPImageProcessor(
								    crop_size=2_2_4     ,   do_center_crop=a     ,   do_normalize=a     ,   do_resize=a     ,   image_mean=[0.48145466, 0.4578275, 0.40821073]     ,   image_std=[0.26862954, 0.26130258, 0.27577711]     ,   resample=3     ,   size=2_2_4     ,   )

								return image_processor







	def    _lowerCamelCase				(					self		:str						)		-> Optional[int]:
								__UpperCamelCase	:   str			   =					self.dummy_prior
								__UpperCamelCase	:   int			   =					self.dummy_image_encoder
								__UpperCamelCase	:   Tuple			   =					self.dummy_text_encoder
								__UpperCamelCase	:   int			   =					self.dummy_tokenizer
								__UpperCamelCase	:   Optional[Any]			   =					self.dummy_image_processor

								__UpperCamelCase	:   int			   =					UnCLIPScheduler(
								    variance_type="fixed_small_log"     ,   prediction_type="sample"     ,   num_train_timesteps=1_0_0_0     ,   clip_sample=a     ,   clip_sample_range=10.0     ,   )

								__UpperCamelCase	:   List[Any]			   =					{
								    "prior": prior,
								    "image_encoder": image_encoder,
								    "text_encoder": text_encoder,
								    "tokenizer": tokenizer,
								    "scheduler": scheduler,
								    "image_processor": image_processor,
								}

								return components







	def    _lowerCamelCase				(					self		:Optional[Any]     ,   a		:int     ,   a		:Union[str, Any]=0						)		-> Any:
								if str(a						).startswith("mps"						):
															__UpperCamelCase	:   int			   =					torch.manual_seed(a						)
								else:
															__UpperCamelCase	:   List[Any]			   =					torch.Generator(device=a						).manual_seed(a						)
								__UpperCamelCase	:   int			   =					{
								    "prompt": "horse",
								    "generator": generator,
								    "guidance_scale": 4.0,
								    "num_inference_steps": 2,
								    "output_type": "np",
								}
								return inputs







	def    _lowerCamelCase				(					self		:List[Any]						)		-> Dict:
								__UpperCamelCase	:   int			   =					"cpu"

								__UpperCamelCase	:   List[str]			   =					self.get_dummy_components()

								__UpperCamelCase	:   List[str]			   =					self.pipeline_class(**a						)
								__UpperCamelCase	:   Tuple			   =					pipe.to(a						)

								pipe.set_progress_bar_config(disable=a						)

								__UpperCamelCase	:   int			   =					pipe(**self.get_dummy_inputs(a						)						)
								__UpperCamelCase	:   int			   =					output.image_embeds

								__UpperCamelCase	:   Optional[int]			   =					pipe(
								    **self.get_dummy_inputs(a						)     ,   return_dict=a     ,   )[0]

								__UpperCamelCase	:   Union[str, Any]			   =					image[0, -1_0:]
								__UpperCamelCase	:   List[str]			   =					image_from_tuple[0, -1_0:]

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

								__UpperCamelCase	:   List[Any]			   =					np.array(
								    [-0.0532, 1.7120, 0.3656, -1.0852, -0.8946, -1.1756, 0.4348, 0.2482, 0.5146, -0.1156]						)

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







	@skip_mps
	def    _lowerCamelCase				(					self		:int						)		-> Union[str, Any]:
								__UpperCamelCase	:   str			   =					torch_device == "cpu"
								__UpperCamelCase	:   List[str]			   =					True
								__UpperCamelCase	:   List[Any]			   =					False

								self._test_inference_batch_single_identical(
								    test_max_difference=a     ,   relax_max_difference=a     ,   test_mean_pixel_difference=a     ,   )







	@skip_mps
	def    _lowerCamelCase				(					self		:Any						)		-> int:
								__UpperCamelCase	:   Optional[Any]			   =					torch_device == "cpu"
								__UpperCamelCase	:   Dict			   =					False

								self._test_attention_slicing_forward_pass(
								    test_max_difference=a     ,   test_mean_pixel_difference=a     ,   )