





'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_distilbert import DistilBertTokenizer


A__    :       Optional[int]              =logging.get_logger(__name__)

A__    :       Tuple              ={'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A__    :       Dict              ={
    '''vocab_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/vocab.txt''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/vocab.txt''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-german-cased''': '''https://huggingface.co/distilbert-base-german-cased/resolve/main/vocab.txt''',
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/tokenizer.json''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/tokenizer.json''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-german-cased''': (
            '''https://huggingface.co/distilbert-base-german-cased/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/tokenizer.json'''
        ),
    },
}

A__    :       Dict              ={
    '''distilbert-base-uncased''': 5_12,
    '''distilbert-base-uncased-distilled-squad''': 5_12,
    '''distilbert-base-cased''': 5_12,
    '''distilbert-base-cased-distilled-squad''': 5_12,
    '''distilbert-base-german-cased''': 5_12,
    '''distilbert-base-multilingual-cased''': 5_12,
}


A__    :       int              ={
    '''distilbert-base-uncased''': {'''do_lower_case''': True},
    '''distilbert-base-uncased-distilled-squad''': {'''do_lower_case''': True},
    '''distilbert-base-cased''': {'''do_lower_case''': False},
    '''distilbert-base-cased-distilled-squad''': {'''do_lower_case''': False},
    '''distilbert-base-german-cased''': {'''do_lower_case''': False},
    '''distilbert-base-multilingual-cased''': {'''do_lower_case''': False},
}




class 			UpperCAmelCase					(      snake_case_       ):
      _lowercase:      int											=       VOCAB_FILES_NAMES
      _lowercase:      Optional[Any]											=       PRETRAINED_VOCAB_FILES_MAP
      _lowercase:      List[Any]											=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      _lowercase:      Any											=       PRETRAINED_INIT_CONFIGURATION
      _lowercase:      Any											=       ['''input_ids''', '''attention_mask''']
      _lowercase:      List[Any]											=       DistilBertTokenizer




      def __init__(      self      :			Tuple      ,      __snake_case      :			Dict=None      ,      __snake_case      :			Optional[Any]=None      ,      __snake_case      :			Optional[int]=True      ,      __snake_case      :			List[Any]="[UNK]"      ,      __snake_case      :			Any="[SEP]"      ,      __snake_case      :			List[str]="[PAD]"      ,      __snake_case      :			Optional[int]="[CLS]"      ,      __snake_case      :			str="[MASK]"      ,      __snake_case      :			List[str]=True      ,      __snake_case      :			str=None      ,      **__snake_case      :			Optional[Any]      ,      )    ->				Any:
            super().__init__(
                __snake_case      ,      tokenizer_file=__snake_case      ,      do_lower_case=__snake_case      ,      unk_token=__snake_case      ,      sep_token=__snake_case      ,      pad_token=__snake_case      ,      cls_token=__snake_case      ,      mask_token=__snake_case      ,      tokenize_chinese_chars=__snake_case      ,      strip_accents=__snake_case      ,      **__snake_case      ,      )

            _lowerCAmelCase												=							json.loads(self.backend_tokenizer.normalizer.__getstate__()  )
            if (
                normalizer_state.get("""lowercase"""      ,      __snake_case  ) != do_lower_case
                or normalizer_state.get("""strip_accents"""      ,      __snake_case  ) != strip_accents
                or normalizer_state.get("""handle_chinese_chars"""      ,      __snake_case  ) != tokenize_chinese_chars
            ):
                  _lowerCAmelCase												=							getattr(__snake_case      ,      normalizer_state.pop("""type"""  )  )
                  _lowerCAmelCase												=							do_lower_case
                  _lowerCAmelCase												=							strip_accents
                  _lowerCAmelCase												=							tokenize_chinese_chars
                  _lowerCAmelCase												=							normalizer_class(**__snake_case  )

            _lowerCAmelCase												=							do_lower_case




      def     lowercase__   (      self      :			Tuple      ,      __snake_case      :			Optional[int]      ,      __snake_case      :			List[Any]=None  )    ->				str:
            _lowerCAmelCase												=							[self.cls_token_id] + token_ids_a + [self.sep_token_id]

            if token_ids_a:
                  output += token_ids_a + [self.sep_token_id]

            return output




      def     lowercase__   (      self      :			Any      ,      __snake_case      :			List[int]      ,      __snake_case      :			Optional[List[int]] = None  )    ->				List[int]:
            _lowerCAmelCase												=							[self.sep_token_id]
            _lowerCAmelCase												=							[self.cls_token_id]
            if token_ids_a is None:
                  return len(cls + token_ids_a + sep  ) * [0]
            return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]




      def     lowercase__   (      self      :			Any      ,      __snake_case      :			str      ,      __snake_case      :			Optional[str] = None  )    ->				Tuple[str]:
            _lowerCAmelCase												=							self._tokenizer.model.save(__snake_case      ,      name=__snake_case  )
            return tuple(__snake_case  )













'''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


A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-1'''
A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-2'''
A__    :       List[str]              ='''CompVis/stable-diffusion-v1-3'''
A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-4'''




class 			UpperCAmelCase					(      snake_case_       ):




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

            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline(
                vae=__snake_case      ,      text_encoder=__snake_case      ,      tokenizer=__snake_case      ,      unet=__snake_case      ,      scheduler=__snake_case      ,      safety_checker=__snake_case      ,      feature_extractor=__snake_case      ,      requires_safety_checker=__snake_case      ,      )

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




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




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




      def     lowercase__   (      self      :			str  )    ->				int:
            self.enable_attention_slicing(__snake_case  )




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




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




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




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




      @torch.no_grad()
      def     lowercase__   (      self      :			Optional[int]      ,      __snake_case      :			Union[str, List[str]]      ,      __snake_case      :			int = 5_12      ,      __snake_case      :			int = 5_12      ,      __snake_case      :			int = 50      ,      __snake_case      :			float = 7.5      ,      __snake_case      :			Optional[Union[str, List[str]]] = None      ,      __snake_case      :			Optional[int] = 1      ,      __snake_case      :			float = 0.0      ,      __snake_case      :			Optional[torch.Generator] = None      ,      __snake_case      :			Optional[torch.FloatTensor] = None      ,      __snake_case      :			Optional[str] = "pil"      ,      __snake_case      :			bool = True      ,      __snake_case      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,      __snake_case      :			int = 1      ,      **__snake_case      :			Tuple      ,      )    ->				Optional[Any]:
            _lowerCAmelCase												=							"""cuda""" if torch.cuda.is_available() else """cpu"""
            self.to(__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												=							self.textaimg_sda_a(
                prompt=__snake_case      ,      height=__snake_case      ,      width=__snake_case      ,      num_inference_steps=__snake_case      ,      guidance_scale=__snake_case      ,      negative_prompt=__snake_case      ,      num_images_per_prompt=__snake_case      ,      eta=__snake_case      ,      generator=__snake_case      ,      latents=__snake_case      ,      output_type=__snake_case      ,      return_dict=__snake_case      ,      callback=__snake_case      ,      callback_steps=__snake_case      ,      **__snake_case      ,      )

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

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

            # Get first result from Stable Diffusion Checkpoint v1.4
            _lowerCAmelCase												=							self.textaimg_sda_a(
                prompt=__snake_case      ,      height=__snake_case      ,      width=__snake_case      ,      num_inference_steps=__snake_case      ,      guidance_scale=__snake_case      ,      negative_prompt=__snake_case      ,      num_images_per_prompt=__snake_case      ,      eta=__snake_case      ,      generator=__snake_case      ,      latents=__snake_case      ,      output_type=__snake_case      ,      return_dict=__snake_case      ,      callback=__snake_case      ,      callback_steps=__snake_case      ,      **__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]]  )






