
"""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 				A__ (			lowercase__):

  def __init__(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = True ,	):
   super()._init_()

   __lowerCAmelCase    :		Optional[Any]		    =   StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
   __lowerCAmelCase    :		Tuple		    =   StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
   __lowerCAmelCase    :		Dict		    =   StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
   __lowerCAmelCase    :		Any		    =   StableDiffusionPipeline(
       vae=_SCREAMING_SNAKE_CASE ,	text_encoder=_SCREAMING_SNAKE_CASE ,	tokenizer=_SCREAMING_SNAKE_CASE ,	unet=_SCREAMING_SNAKE_CASE ,	scheduler=_SCREAMING_SNAKE_CASE ,	safety_checker=_SCREAMING_SNAKE_CASE ,	feature_extractor=_SCREAMING_SNAKE_CASE ,	requires_safety_checker=_SCREAMING_SNAKE_CASE ,	)

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

  @property
  def 							__lowerCamelCase							(   self				):
   return {k: getattr(self ,	_SCREAMING_SNAKE_CASE				) for k in self.config.keys() if not k.startswith('_'				)}

  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE = "auto"				):
   if slice_size == "auto":
    # half the attention head size is usually a good trade-off between
    # speed and memory
    __lowerCAmelCase    :		str		    =   self.unet.config.attention_head_dim // 2
   self.unet.set_attention_slice(_SCREAMING_SNAKE_CASE				)

  def 							__lowerCamelCase							(   self				):
   self.enable_attention_slicing(_SCREAMING_SNAKE_CASE				)

  @torch.no_grad()
  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 50 ,	_SCREAMING_SNAKE_CASE = 7.5 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	_SCREAMING_SNAKE_CASE = 0.0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = "pil" ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	**_SCREAMING_SNAKE_CASE ,	):
   return self.pipea(
       prompt=_SCREAMING_SNAKE_CASE ,	height=_SCREAMING_SNAKE_CASE ,	width=_SCREAMING_SNAKE_CASE ,	num_inference_steps=_SCREAMING_SNAKE_CASE ,	guidance_scale=_SCREAMING_SNAKE_CASE ,	negative_prompt=_SCREAMING_SNAKE_CASE ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE ,	eta=_SCREAMING_SNAKE_CASE ,	generator=_SCREAMING_SNAKE_CASE ,	latents=_SCREAMING_SNAKE_CASE ,	output_type=_SCREAMING_SNAKE_CASE ,	return_dict=_SCREAMING_SNAKE_CASE ,	callback=_SCREAMING_SNAKE_CASE ,	callback_steps=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)

  @torch.no_grad()
  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 50 ,	_SCREAMING_SNAKE_CASE = 7.5 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	_SCREAMING_SNAKE_CASE = 0.0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = "pil" ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	**_SCREAMING_SNAKE_CASE ,	):
   return self.pipea(
       prompt=_SCREAMING_SNAKE_CASE ,	height=_SCREAMING_SNAKE_CASE ,	width=_SCREAMING_SNAKE_CASE ,	num_inference_steps=_SCREAMING_SNAKE_CASE ,	guidance_scale=_SCREAMING_SNAKE_CASE ,	negative_prompt=_SCREAMING_SNAKE_CASE ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE ,	eta=_SCREAMING_SNAKE_CASE ,	generator=_SCREAMING_SNAKE_CASE ,	latents=_SCREAMING_SNAKE_CASE ,	output_type=_SCREAMING_SNAKE_CASE ,	return_dict=_SCREAMING_SNAKE_CASE ,	callback=_SCREAMING_SNAKE_CASE ,	callback_steps=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)

  @torch.no_grad()
  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 50 ,	_SCREAMING_SNAKE_CASE = 7.5 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	_SCREAMING_SNAKE_CASE = 0.0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = "pil" ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	**_SCREAMING_SNAKE_CASE ,	):
   return self.pipea(
       prompt=_SCREAMING_SNAKE_CASE ,	height=_SCREAMING_SNAKE_CASE ,	width=_SCREAMING_SNAKE_CASE ,	num_inference_steps=_SCREAMING_SNAKE_CASE ,	guidance_scale=_SCREAMING_SNAKE_CASE ,	negative_prompt=_SCREAMING_SNAKE_CASE ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE ,	eta=_SCREAMING_SNAKE_CASE ,	generator=_SCREAMING_SNAKE_CASE ,	latents=_SCREAMING_SNAKE_CASE ,	output_type=_SCREAMING_SNAKE_CASE ,	return_dict=_SCREAMING_SNAKE_CASE ,	callback=_SCREAMING_SNAKE_CASE ,	callback_steps=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)

  @torch.no_grad()
  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 50 ,	_SCREAMING_SNAKE_CASE = 7.5 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	_SCREAMING_SNAKE_CASE = 0.0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = "pil" ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	**_SCREAMING_SNAKE_CASE ,	):
   return self.pipea(
       prompt=_SCREAMING_SNAKE_CASE ,	height=_SCREAMING_SNAKE_CASE ,	width=_SCREAMING_SNAKE_CASE ,	num_inference_steps=_SCREAMING_SNAKE_CASE ,	guidance_scale=_SCREAMING_SNAKE_CASE ,	negative_prompt=_SCREAMING_SNAKE_CASE ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE ,	eta=_SCREAMING_SNAKE_CASE ,	generator=_SCREAMING_SNAKE_CASE ,	latents=_SCREAMING_SNAKE_CASE ,	output_type=_SCREAMING_SNAKE_CASE ,	return_dict=_SCREAMING_SNAKE_CASE ,	callback=_SCREAMING_SNAKE_CASE ,	callback_steps=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)







  @torch.no_grad()
  def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 5_12 ,	_SCREAMING_SNAKE_CASE = 50 ,	_SCREAMING_SNAKE_CASE = 7.5 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	_SCREAMING_SNAKE_CASE = 0.0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = "pil" ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 1 ,	**_SCREAMING_SNAKE_CASE ,	):
   __lowerCAmelCase    :		int		    =   'cuda' if torch.cuda.is_available() else 'cpu'
   self.to(_SCREAMING_SNAKE_CASE				)

   # 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
   __lowerCAmelCase    :		List[Any]		    =   self.textaimg_sda_a(
       prompt=_SCREAMING_SNAKE_CASE ,	height=_SCREAMING_SNAKE_CASE ,	width=_SCREAMING_SNAKE_CASE ,	num_inference_steps=_SCREAMING_SNAKE_CASE ,	guidance_scale=_SCREAMING_SNAKE_CASE ,	negative_prompt=_SCREAMING_SNAKE_CASE ,	num_images_per_prompt=_SCREAMING_SNAKE_CASE ,	eta=_SCREAMING_SNAKE_CASE ,	generator=_SCREAMING_SNAKE_CASE ,	latents=_SCREAMING_SNAKE_CASE ,	output_type=_SCREAMING_SNAKE_CASE ,	return_dict=_SCREAMING_SNAKE_CASE ,	callback=_SCREAMING_SNAKE_CASE ,	callback_steps=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)

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

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

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

   # 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]]				)

"""simple docstring"""







import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
							from transformers.models.roberta.modeling_flax_roberta import (
							    FlaxRobertaForCausalLM,
							    FlaxRobertaForMaskedLM,
							    FlaxRobertaForMultipleChoice,
							    FlaxRobertaForQuestionAnswering,
							    FlaxRobertaForSequenceClassification,
							    FlaxRobertaForTokenClassification,
							    FlaxRobertaModel,
							)




class 				A__ (			unittest.TestCase):

		def __init__(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=13 ,	_SCREAMING_SNAKE_CASE=7 ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=99 ,	_SCREAMING_SNAKE_CASE=32 ,	_SCREAMING_SNAKE_CASE=5 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=37 ,	_SCREAMING_SNAKE_CASE="gelu" ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=5_12 ,	_SCREAMING_SNAKE_CASE=16 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=0.02 ,	_SCREAMING_SNAKE_CASE=4 ,	):
			__lowerCAmelCase    :		List[Any]		    =   parent
			__lowerCAmelCase    :		int		    =   batch_size
			__lowerCAmelCase    :		List[str]		    =   seq_length
			__lowerCAmelCase    :		str		    =   is_training
			__lowerCAmelCase    :		Optional[Any]		    =   use_attention_mask
			__lowerCAmelCase    :		Union[str, Any]		    =   use_token_type_ids
			__lowerCAmelCase    :		Dict		    =   use_labels
			__lowerCAmelCase    :		Union[str, Any]		    =   vocab_size
			__lowerCAmelCase    :		List[str]		    =   hidden_size
			__lowerCAmelCase    :		List[str]		    =   num_hidden_layers
			__lowerCAmelCase    :		Optional[int]		    =   num_attention_heads
			__lowerCAmelCase    :		Dict		    =   intermediate_size
			__lowerCAmelCase    :		Dict		    =   hidden_act
			__lowerCAmelCase    :		Optional[int]		    =   hidden_dropout_prob
			__lowerCAmelCase    :		Dict		    =   attention_probs_dropout_prob
			__lowerCAmelCase    :		Union[str, Any]		    =   max_position_embeddings
			__lowerCAmelCase    :		Any		    =   type_vocab_size
			__lowerCAmelCase    :		Tuple		    =   type_sequence_label_size
			__lowerCAmelCase    :		Union[str, Any]		    =   initializer_range
			__lowerCAmelCase    :		int		    =   num_choices

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.vocab_size				)

			__lowerCAmelCase    :		List[str]		    =   None
			if self.use_attention_mask:
				__lowerCAmelCase    :		str		    =   random_attention_mask([self.batch_size, self.seq_length]				)

			__lowerCAmelCase    :		Dict		    =   None
			if self.use_token_type_ids:
				__lowerCAmelCase    :		Tuple		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.type_vocab_size				)

			__lowerCAmelCase    :		str		    =   RobertaConfig(
			    vocab_size=self.vocab_size ,	hidden_size=self.hidden_size ,	num_hidden_layers=self.num_hidden_layers ,	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 ,	max_position_embeddings=self.max_position_embeddings ,	type_vocab_size=self.type_vocab_size ,	is_decoder=_SCREAMING_SNAKE_CASE ,	initializer_range=self.initializer_range ,	)

			return config, input_ids, token_type_ids, attention_mask

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Dict		    =   self.prepare_config_and_inputs()
			__lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    :		List[Any]		    =   config_and_inputs
			__lowerCAmelCase    :		List[Any]		    =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
			return config, inputs_dict







		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.prepare_config_and_inputs()
			__lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    :		Any		    =   config_and_inputs

			__lowerCAmelCase    :		int		    =   True
			__lowerCAmelCase    :		Any		    =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
			__lowerCAmelCase    :		int		    =   ids_tensor([self.batch_size, self.seq_length] ,	vocab_size=2				)

			return (
			    config,
			    input_ids,
			    token_type_ids,
			    encoder_hidden_states,
			    encoder_attention_mask,
			)




@require_flax
class 				A__ (			_lowerCamelCase ,  unittest.TestCase):
		A_		: List[Any]            =			True

		A_		: Optional[Any]            =			(
		    (
		        FlaxRobertaModel,
		        FlaxRobertaForCausalLM,
		        FlaxRobertaForMaskedLM,
		        FlaxRobertaForSequenceClassification,
		        FlaxRobertaForTokenClassification,
		        FlaxRobertaForMultipleChoice,
		        FlaxRobertaForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   FlaxRobertaModelTester(self				)







		@slow
		def 							__lowerCamelCase							(   self				):
			for model_class_name in self.all_model_classes:
				__lowerCAmelCase    :		str		    =   model_class_name.from_pretrained('roberta-base' ,	from_pt=_SCREAMING_SNAKE_CASE				)
				__lowerCAmelCase    :		Optional[int]		    =   model(np.ones((1, 1)				)				)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)