

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     __UpperCamelCase     :




	def __init__(		self						:    Optional[Any]		,						lowerCAmelCase						:    Optional[int]		,						lowerCAmelCase						:    Optional[Any]=2		,						lowerCAmelCase						:    Any=True		,						lowerCAmelCase						:    Optional[int]=False		,						lowerCAmelCase						:    Optional[Any]=10		,						lowerCAmelCase						:    Union[str, Any]=3		,						lowerCAmelCase						:    Any=32 * 4		,						lowerCAmelCase						:    Optional[Any]=32 * 6		,						lowerCAmelCase						:    Optional[Any]=4		,						lowerCAmelCase						:    Optional[int]=32		,						):


		'''simple docstring'''







		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						:    Optional[int]				):


		'''simple docstring'''







		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						:    Optional[Any]				):


		'''simple docstring'''







		return MaskFormerConfig.from_backbone_and_decoder_configs(
		    backbone_config=SwinConfig(
		        depths=[1, 1, 1, 1]		,						)		,						decoder_config=DetrConfig(
		        decoder_ffn_dim=128		,						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						:    int				):


		'''simple docstring'''







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




	def    __A       (		self						:    str		,						lowerCAmelCase						:    Optional[Any]		,						lowerCAmelCase						:    Tuple				):


		'''simple docstring'''







		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						:    Tuple		,						lowerCAmelCase						:    Tuple		,						lowerCAmelCase						:    List[Any]		,						lowerCAmelCase						:    Dict		,						lowerCAmelCase						:    Dict=False				):


		'''simple docstring'''







		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						:    Union[str, Any]		,						lowerCAmelCase						:    Any		,						lowerCAmelCase						:    Dict		,						lowerCAmelCase						:    Dict		,						lowerCAmelCase						:    Any		,						lowerCAmelCase						:    int				):


		'''simple docstring'''







		UpperCAmelCase_												=      MaskFormerForInstanceSegmentation(config=__a				)
		model.to(__a				)
		model.eval()

		def comm_check_on_output(lowerCAmelCase						:    Dict				):
			# 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     __UpperCamelCase     (       _UpperCamelCase  ,  _UpperCamelCase  ,  unittest.TestCase    ):
	SCREAMING_SNAKE_CASE__     					=  (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
	SCREAMING_SNAKE_CASE__     					=  (
	    {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
	    if is_torch_available()
	    else {}
	)

	SCREAMING_SNAKE_CASE__     					=  False
	SCREAMING_SNAKE_CASE__     					=  False
	SCREAMING_SNAKE_CASE__     					=  False
	SCREAMING_SNAKE_CASE__     					=  False




	def    __A       (		self						:    Any				):


		'''simple docstring'''







		UpperCAmelCase_												=      MaskFormerModelTester(self				)
		UpperCAmelCase_												=      ConfigTester(self		,						config_class=__a		,						has_text_modality=__a				)




	def    __A       (		self						:    str				):


		'''simple docstring'''







		self.config_tester.run_common_tests()




	def    __A       (		self						:    List[str]				):


		'''simple docstring'''







		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						:    Any				):


		'''simple docstring'''







		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						:    List[str]				):


		'''simple docstring'''







		pass




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


		'''simple docstring'''







		pass




	@unittest.skip(reason="MaskFormer is not a generative model"				)
	def    __A       (		self						:    Union[str, Any]				):


		'''simple docstring'''







		pass




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


		'''simple docstring'''







		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						:    str				):


		'''simple docstring'''







		pass




	@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."				)
	def    __A       (		self						:    Optional[int]				):


		'''simple docstring'''







		pass




	def    __A       (		self						:    List[str]				):


		'''simple docstring'''







		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						:    Tuple				):


		'''simple docstring'''







		for model_name in ["facebook/maskformer-swin-small-coco"]:
			UpperCAmelCase_												=      MaskFormerModel.from_pretrained(__a				)
			self.assertIsNotNone(__a				)




	def    __A       (		self						:    Optional[Any]				):


		'''simple docstring'''







		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						:    str				):


		'''simple docstring'''







		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						:    List[Any]				):


		'''simple docstring'''







		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						:    Tuple				):


		'''simple docstring'''







		if not self.model_tester.is_training:
			return
		# only MaskFormerForInstanceSegmentation has the loss
		UpperCAmelCase_												=      self.all_model_classes[1]
		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						:    List[Any]				):


		'''simple docstring'''







		UpperCAmelCase_												=      self.all_model_classes[1]
		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:     Optional[Any]							=      1e-4



def    __lowerCAmelCase   (    ):
	UpperCAmelCase_												=      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
	return image




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




	@cached_property
	def    __A       (		self						:    Dict				):


		'''simple docstring'''







		return (
		    MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"				)
		    if is_vision_available()
		    else None
		)




	def    __A       (		self						:    Tuple				):


		'''simple docstring'''







		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, 800, 1_088)				)

		with torch.no_grad():
			UpperCAmelCase_												=      model(**__a				)

		UpperCAmelCase_												=      torch.tensor(
		    [[-0.0_482, 0.9_228, 0.4_951], [-0.2_547, 0.8_017, 0.8_527], [-0.0_069, 0.3_385, -0.0_089]]				).to(__a				)
		self.assertTrue(
		    torch.allclose(
		        outputs.encoder_last_hidden_state[0, 0, :3, :3]		,						__a		,						atol=__a				)				)

		UpperCAmelCase_												=      torch.tensor(
		    [[-0.8_422, -0.8_434, -0.9_718], [-1.0_144, -0.5_565, -0.4_195], [-1.0_038, -0.4_484, -0.1_961]]				).to(__a				)
		self.assertTrue(
		    torch.allclose(
		        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]		,						__a		,						atol=__a				)				)

		UpperCAmelCase_												=      torch.tensor(
		    [[0.2_852, -0.0_159, 0.9_735], [0.6_254, 0.1_858, 0.8_529], [-0.0_680, -0.4_116, 1.8_413]]				).to(__a				)
		self.assertTrue(
		    torch.allclose(
		        outputs.transformer_decoder_last_hidden_state[0, :3, :3]		,						__a		,						atol=__a				)				)




	def    __A       (		self						:    Union[str, Any]				):


		'''simple docstring'''







		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, 800, 1_088)				)

		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.3_737_124, -1.7_724_937, -1.9_364_233],
		    [-1.5_977_281, -1.9_867_939, -2.1_523_695],
		    [-1.5_795_398, -1.9_269_832, -2.093_942],
		]
		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.6_512e00, -5.2_572e00, -3.3_519e00],
		        [3.6_169e-02, -5.9_025e00, -2.9_313e00],
		        [1.0_766e-04, -7.7_630e00, -5.1_263e00],
		    ]				).to(__a				)
		self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]		,						__a		,						atol=__a				)				)




	def    __A       (		self						:    int				):


		'''simple docstring'''







		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, 800, 1_088)				)

		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.9_046, -2.6_366, -4.6_062], [-3.4_179, -5.7_890, -8.8_057], [-4.9_179, -7.6_560, -10.7_711]]
		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.7_188, -3.2_585, -2.8_857], [6.6_871, -2.9_181, -1.2_487], [7.2_449, -2.2_764, -2.1_874]]				).to(__a				)
		self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]		,						__a		,						atol=__a				)				)




	def    __A       (		self						:    Dict				):


		'''simple docstring'''







		UpperCAmelCase_												=      (
		    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"				)
		    .to(__a				)
		    .eval()
		)
		UpperCAmelCase_												=      self.default_image_processor

		UpperCAmelCase_												=      image_processor(
		    [np.zeros((3, 800, 1_333)				), np.zeros((3, 800, 1_333)				)]		,						segmentation_maps=[np.zeros((384, 384)				).astype(np.floataa				), np.zeros((384, 384)				).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				)






"""simple docstring"""


from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


lowerCamelCase__						= "CompVis/stable-diffusion-v1-1"
lowerCamelCase__						= "CompVis/stable-diffusion-v1-2"
lowerCamelCase__						= "CompVis/stable-diffusion-v1-3"
lowerCamelCase__						= "CompVis/stable-diffusion-v1-4"



class   __SCREAMING_SNAKE_CASE     (    _UpperCamelCase ):







  '''simple docstring'''


  def __init__(		self :							Union[str, Any]       , __a :							AutoencoderKL       , __a :							CLIPTextModel       , __a :							CLIPTokenizer       , __a :							UNetaDConditionModel       , __a :							Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]       , __a :							StableDiffusionSafetyChecker       , __a :							CLIPImageProcessor       , __a :							bool = True       , )		->					List[str]:
        super()._init_()

        _UpperCamelCase   :						Optional[int]    =							StableDiffusionPipeline.from_pretrained(__a						)
        _UpperCamelCase   :						int    =							StableDiffusionPipeline.from_pretrained(__a						)
        _UpperCamelCase   :						List[Any]    =							StableDiffusionPipeline.from_pretrained(__a						)
        _UpperCamelCase   :						int    =							StableDiffusionPipeline(
            vae=__a       , text_encoder=__a       , tokenizer=__a       , unet=__a       , scheduler=__a       , safety_checker=__a       , feature_extractor=__a       , requires_safety_checker=__a       , )

        self.register_modules(pipelinea=self.pipea       , pipelinea=self.pipea       , pipelinea=self.pipea       , pipelinea=self.pipea						)

  @property
  def  __SCREAMING_SNAKE_CASE					(		self :							Optional[int]						)		->					Dict[str, Any]:
        return {k: getattr(self       , __a						) for k in self.config.keys() if not k.startswith("_"						)}

  def  __SCREAMING_SNAKE_CASE					(		self :							Any       , __a :							Optional[Union[str, int]] = "auto"						)		->					Optional[Any]:
        if slice_size == "auto":
              # half the attention head size is usually a good trade-off between
              # speed and memory
              _UpperCamelCase   :						Tuple    =							self.unet.config.attention_head_dim // 2
        self.unet.set_attention_slice(__a						)

  def  __SCREAMING_SNAKE_CASE					(		self :							str						)		->					Any:
        self.enable_attention_slicing(__a						)

  @torch.no_grad()
  def  __SCREAMING_SNAKE_CASE					(		self :							List[str]       , __a :							Union[str, List[str]]       , __a :							int = 512       , __a :							int = 512       , __a :							int = 50       , __a :							float = 7.5       , __a :							Optional[Union[str, List[str]]] = None       , __a :							Optional[int] = 1       , __a :							float = 0.0       , __a :							Optional[torch.Generator] = None       , __a :							Optional[torch.FloatTensor] = None       , __a :							Optional[str] = "pil"       , __a :							bool = True       , __a :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       , __a :							int = 1       , **__a :							Any       , )		->					Optional[int]:
        return self.pipea(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

  @torch.no_grad()
  def  __SCREAMING_SNAKE_CASE					(		self :							List[Any]       , __a :							Union[str, List[str]]       , __a :							int = 512       , __a :							int = 512       , __a :							int = 50       , __a :							float = 7.5       , __a :							Optional[Union[str, List[str]]] = None       , __a :							Optional[int] = 1       , __a :							float = 0.0       , __a :							Optional[torch.Generator] = None       , __a :							Optional[torch.FloatTensor] = None       , __a :							Optional[str] = "pil"       , __a :							bool = True       , __a :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       , __a :							int = 1       , **__a :							Tuple       , )		->					str:
        return self.pipea(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

  @torch.no_grad()
  def  __SCREAMING_SNAKE_CASE					(		self :							List[Any]       , __a :							Union[str, List[str]]       , __a :							int = 512       , __a :							int = 512       , __a :							int = 50       , __a :							float = 7.5       , __a :							Optional[Union[str, List[str]]] = None       , __a :							Optional[int] = 1       , __a :							float = 0.0       , __a :							Optional[torch.Generator] = None       , __a :							Optional[torch.FloatTensor] = None       , __a :							Optional[str] = "pil"       , __a :							bool = True       , __a :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       , __a :							int = 1       , **__a :							Tuple       , )		->					Any:
        return self.pipea(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

  @torch.no_grad()
  def  __SCREAMING_SNAKE_CASE					(		self :							Dict       , __a :							Union[str, List[str]]       , __a :							int = 512       , __a :							int = 512       , __a :							int = 50       , __a :							float = 7.5       , __a :							Optional[Union[str, List[str]]] = None       , __a :							Optional[int] = 1       , __a :							float = 0.0       , __a :							Optional[torch.Generator] = None       , __a :							Optional[torch.FloatTensor] = None       , __a :							Optional[str] = "pil"       , __a :							bool = True       , __a :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       , __a :							int = 1       , **__a :							List[Any]       , )		->					Union[str, Any]:
        return self.pipea(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )


  @torch.no_grad()
  def  __SCREAMING_SNAKE_CASE					(		self :							str       , __a :							Union[str, List[str]]       , __a :							int = 512       , __a :							int = 512       , __a :							int = 50       , __a :							float = 7.5       , __a :							Optional[Union[str, List[str]]] = None       , __a :							Optional[int] = 1       , __a :							float = 0.0       , __a :							Optional[torch.Generator] = None       , __a :							Optional[torch.FloatTensor] = None       , __a :							Optional[str] = "pil"       , __a :							bool = True       , __a :							Optional[Callable[[int, int, torch.FloatTensor], None]] = None       , __a :							int = 1       , **__a :							int       , )		->					List[Any]:
        _UpperCamelCase   :						Tuple    =							"cuda" if torch.cuda.is_available() else "cpu"
        self.to(__a						)

        # Checks if the height and width are divisible by 8 or not
        if height % 8 != 0 or width % 8 != 0:
              raise ValueError(F'''`height` and `width` must be divisible by 8 but are {height} and {width}.'''						)

        # Get first result from Stable Diffusion Checkpoint v1.1
        _UpperCamelCase   :						List[str]    =							self.textaimg_sda_a(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

        # Get first result from Stable Diffusion Checkpoint v1.2
        _UpperCamelCase   :						Optional[Any]    =							self.textaimg_sda_a(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

        # Get first result from Stable Diffusion Checkpoint v1.3
        _UpperCamelCase   :						str    =							self.textaimg_sda_a(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

        # Get first result from Stable Diffusion Checkpoint v1.4
        _UpperCamelCase   :						str    =							self.textaimg_sda_a(
            prompt=__a       , height=__a       , width=__a       , num_inference_steps=__a       , guidance_scale=__a       , negative_prompt=__a       , num_images_per_prompt=__a       , eta=__a       , generator=__a       , latents=__a       , output_type=__a       , return_dict=__a       , callback=__a       , callback_steps=__a       , **__a       , )

        # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
        return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]						)
