





import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_         =						logging.get_logger(__name__)

lowercase_         =						{
    """microsoft/unispeech-sat-base-100h-libri-ft""": (
        """https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"""
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}
class 							SCREAMING_SNAKE_CASE  (UpperCAmelCase_ ):
   _UpperCamelCase       :						Dict					   =			'''unispeech-sat'''


   def __init__(       self     :							List[Any]     ,	a     :							List[str]=32     ,	a     :							Optional[int]=768     ,	a     :							int=12     ,	a     :							Union[str, Any]=12     ,	a     :							Optional[Any]=3_072     ,	a     :							List[str]="gelu"     ,	a     :							List[str]=0.1     ,	a     :							int=0.1     ,	a     :							Optional[int]=0.1     ,	a     :							Any=0.0     ,	a     :							List[Any]=0.0     ,	a     :							List[str]=0.1     ,	a     :							List[str]=0.1     ,	a     :							Optional[Any]=0.02     ,	a     :							Dict=1E-5     ,	a     :							List[Any]="group"     ,	a     :							Union[str, Any]="gelu"     ,	a     :							Dict=(512, 512, 512, 512, 512, 512, 512)     ,	a     :							Dict=(5, 2, 2, 2, 2, 2, 2)     ,	a     :							Optional[Any]=(10, 3, 3, 3, 3, 2, 2)     ,	a     :							Tuple=False     ,	a     :							int=128     ,	a     :							Optional[int]=16     ,	a     :							int=False     ,	a     :							List[Any]=True     ,	a     :							List[str]=0.05     ,	a     :							List[str]=10     ,	a     :							str=2     ,	a     :							Union[str, Any]=0.0     ,	a     :							Optional[Any]=10     ,	a     :							Tuple=0     ,	a     :							Union[str, Any]=320     ,	a     :							str=2     ,	a     :							List[Any]=0.1     ,	a     :							Optional[int]=100     ,	a     :							Optional[int]=256     ,	a     :							Dict=256     ,	a     :							List[str]=0.1     ,	a     :							List[Any]="mean"     ,	a     :							str=False     ,	a     :							Tuple=False     ,	a     :							str=256     ,	a     :							Dict=(512, 512, 512, 512, 1_500)     ,	a     :							Optional[Any]=(5, 3, 3, 1, 1)     ,	a     :							Any=(1, 2, 3, 1, 1)     ,	a     :							List[str]=512     ,	a     :							Union[str, Any]=0     ,	a     :							Any=1     ,	a     :							Union[str, Any]=2     ,	a     :							List[str]=504     ,	**a     :							Tuple     ,	)->  int:





     """simple docstring"""







     super().__init__(**lowerCamelCase__     ,	pad_token_id=lowerCamelCase__     ,	bos_token_id=lowerCamelCase__     ,	eos_token_id=lowerCamelCase__			)
     lowercase__           =    hidden_size
     lowercase__           =    feat_extract_norm
     lowercase__           =    feat_extract_activation
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    conv_bias
     lowercase__           =    num_conv_pos_embeddings
     lowercase__           =    num_conv_pos_embedding_groups
     lowercase__           =    len(self.conv_dim			)
     lowercase__           =    num_hidden_layers
     lowercase__           =    intermediate_size
     lowercase__           =    hidden_act
     lowercase__           =    num_attention_heads
     lowercase__           =    hidden_dropout
     lowercase__           =    attention_dropout
     lowercase__           =    activation_dropout
     lowercase__           =    feat_proj_dropout
     lowercase__           =    final_dropout
     lowercase__           =    layerdrop
     lowercase__           =    layer_norm_eps
     lowercase__           =    initializer_range
     lowercase__           =    vocab_size
     lowercase__           =    num_clusters
     lowercase__           =    do_stable_layer_norm
     lowercase__           =    use_weighted_layer_sum

     if (
         (len(self.conv_stride			) != self.num_feat_extract_layers)
         or (len(self.conv_kernel			) != self.num_feat_extract_layers)
         or (len(self.conv_dim			) != self.num_feat_extract_layers)
     ):
       raise ValueError(
           'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
           ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
           f""" {len(self.conv_dim			)}`, `len(config.conv_stride) = {len(self.conv_stride			)}`,"""
           f""" `len(config.conv_kernel) = {len(self.conv_kernel			)}`."""			)

     # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
     lowercase__           =    apply_spec_augment
     lowercase__           =    mask_time_prob
     lowercase__           =    mask_time_length
     lowercase__           =    mask_time_min_masks
     lowercase__           =    mask_feature_prob
     lowercase__           =    mask_feature_length
     lowercase__           =    mask_feature_min_masks

     # parameters for pretraining with codevector quantized representations
     lowercase__           =    num_codevectors_per_group
     lowercase__           =    num_codevector_groups
     lowercase__           =    contrastive_logits_temperature
     lowercase__           =    feat_quantizer_dropout
     lowercase__           =    num_negatives
     lowercase__           =    codevector_dim
     lowercase__           =    proj_codevector_dim
     lowercase__           =    diversity_loss_weight

     # ctc loss
     lowercase__           =    ctc_loss_reduction
     lowercase__           =    ctc_zero_infinity

     # SequenceClassification-specific parameter. Feel free to ignore for other classes.
     lowercase__           =    classifier_proj_size

     # XVector-specific parameters. Feel free to ignore for other classes.
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    list(lowerCamelCase__			)
     lowercase__           =    xvector_output_dim


   @property
   def 			SCREAMING_SNAKE_CASE_				(       self     :							Optional[int]			)->  Optional[int]:





     """simple docstring"""







     return functools.reduce(operator.mul     ,	self.conv_stride     ,	1			)










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


UpperCamelCase    							=      'CompVis/stable-diffusion-v1-1'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-2'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-3'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-4'







class 		_A						( UpperCAmelCase_ ):

  def __init__(    self						:	List[str]   ,				lowerCamelCase__						:	AutoencoderKL   ,				lowerCamelCase__						:	CLIPTextModel   ,				lowerCamelCase__						:	CLIPTokenizer   ,				lowerCamelCase__						:	UNetaDConditionModel   ,				lowerCamelCase__						:	Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]   ,				lowerCamelCase__						:	StableDiffusionSafetyChecker   ,				lowerCamelCase__						:	CLIPImageProcessor   ,				lowerCamelCase__						:	bool = True   ,				):
     """simple docstring"""

     super()._init_()

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

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

  @property
  def    a					(    self						:	Optional[Any]			):
     """simple docstring"""

     return {k: getattr(self   ,				lowerCamelCase__			) for k in self.config.keys() if not k.startswith("""_"""			)}

  def    a					(    self						:	List[str]   ,				lowerCamelCase__						:	Optional[Union[str, int]] = "auto"			):
     """simple docstring"""

     if slice_size == "auto":
        # half the attention head size is usually a good trade-off between
        # speed and memory
        __UpperCamelCase	:			Dict					=					self.unet.config.attention_head_dim // 2
     self.unet.set_attention_slice(lowerCamelCase__			)

  def    a					(    self						:	str			):
     """simple docstring"""

     self.enable_attention_slicing(lowerCamelCase__			)

  @torch.no_grad()
  def    a					(    self						:	Any   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	str   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Union[str, Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Dict   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Union[str, Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Any   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Dict   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	List[Any]   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Optional[Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Dict   ,				):
     """simple docstring"""

     __UpperCamelCase	:			Optional[Any]					=					"""cuda""" if torch.cuda.is_available() else """cpu"""
     self.to(lowerCamelCase__			)

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

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

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

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

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



