





import os
import pickle
import unittest

from transformers import AutoTokenizer
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.models.bert_japanese.tokenization_bert_japanese import (
    VOCAB_FILES_NAMES,
    BertJapaneseTokenizer,
    CharacterTokenizer,
    JumanppTokenizer,
    MecabTokenizer,
    SudachiTokenizer,
    WordpieceTokenizer,
)
from transformers.testing_utils import custom_tokenizers, require_jumanpp, require_sudachi

from ...test_tokenization_common import TokenizerTesterMixin







@custom_tokenizers
class   __lowerCAmelCase			(					_UpperCamelCase		,unittest.TestCase  ):
   _UpperCamelCase :						List[str]     		=				BertJapaneseTokenizer
   _UpperCamelCase :						int     		=				False
   _UpperCamelCase :						Any     		=				True





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      super().setUp()

      a__	:						List[Any]      		=  [
          "[UNK]",
          "[CLS]",
          "[SEP]",
          "こんにちは",
          "こん",
          "にちは",
          "ばんは",
          "##こん",
          "##にちは",
          "##ばんは",
          "世界",
          "##世界",
          "、",
          "##、",
          "。",
          "##。",
      ]

      a__	:						Any      		=  os.path.join(self.tmpdirname					,			VOCAB_FILES_NAMES["vocab_file"]      )
      with open(self.vocab_file					,			"w"					,			encoding="utf-8"      ) as vocab_writer:
         vocab_writer.write("".join([x + "\n" for x in vocab_tokens]      )      )





   def 	_snake_case ( self					,			snake_case      )				->  Dict:
      """simple docstring"""





      a__	:						str      		=  "こんにちは、世界。 \nこんばんは、世界。"
      a__	:						Union[str, Any]      		=  "こんにちは 、 世界 。 こんばんは 、 世界 。"
      return input_text, output_text





   def 	_snake_case ( self					,			snake_case      )				->  Tuple:
      """simple docstring"""





      a__		,     a__	:						List[Any]      		=  self.get_input_output_texts(snake_case      )
      a__	:						int      		=  tokenizer.encode(snake_case					,			add_special_tokens=snake_case      )
      a__	:						List[Any]      		=  tokenizer.decode(snake_case					,			clean_up_tokenization_spaces=snake_case      )
      return text, ids





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						str      		=  self.tokenizer_class(self.vocab_file      )

      a__	:						Union[str, Any]      		=  tokenizer.tokenize("こんにちは、世界。\nこんばんは、世界。"      )
      self.assertListEqual(snake_case					,			["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]      )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case      )					,			[3, 12, 10, 14, 4, 9, 12, 10, 14]      )





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						Tuple      		=  self.tokenizer_class(self.vocab_file					,			word_tokenizer_type="mecab"      )
      self.assertIsNotNone(snake_case      )

      a__	:						Any      		=  "こんにちは、世界。\nこんばんは、世界。"
      a__	:						List[str]      		=  tokenizer.tokenize(snake_case      )
      self.assertListEqual(snake_case					,			["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]      )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case      )					,			[3, 12, 10, 14, 4, 9, 12, 10, 14]      )

      a__	:						Union[str, Any]      		=  os.path.join(self.tmpdirname					,			"tokenizer.bin"      )
      with open(snake_case					,			"wb"      ) as handle:
         pickle.dump(snake_case					,			snake_case      )

      with open(snake_case					,			"rb"      ) as handle:
         a__	:						Dict      		=  pickle.load(snake_case      )

      a__	:						Optional[Any]      		=  tokenizer_new.tokenize(snake_case      )

      self.assertListEqual(snake_case					,			snake_case      )





   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						Any      		=  MecabTokenizer(mecab_dic="ipadic"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップルストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,			)





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      try:
         a__	:						str      		=  MecabTokenizer(mecab_dic="unidic_lite"      )
      except ModuleNotFoundError:
         return

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,			)





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      try:
         a__	:						Optional[Any]      		=  MecabTokenizer(mecab_dic="unidic"      )
      except ModuleNotFoundError:
         return

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,			)





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  MecabTokenizer(do_lower_case=snake_case					,			mecab_dic="ipadic"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップルストア", "で", "iphone", "8", "が", "発売", "さ", "れ", "た", "。"]					,			)





   def 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      try:
         a__	:						Any      		=  MecabTokenizer(
             do_lower_case=snake_case					,			normalize_text=snake_case					,			mecab_option="-d /usr/local/lib/mecab/dic/jumandic"      )
      except RuntimeError:
         # if dict doesn't exist in the system, previous code raises this error.
         return

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れた", "\u3000", "。"]					,			)





   def 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      a__	:						List[str]      		=  MecabTokenizer(normalize_text=snake_case					,			mecab_dic="ipadic"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れ", "た", "　", "。"]					,			)





   @require_sudachi
   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						Any      		=  self.tokenizer_class(self.vocab_file					,			word_tokenizer_type="sudachi"      )
      self.assertIsNotNone(snake_case      )

      a__	:						int      		=  "こんにちは、世界。\nこんばんは、世界。"
      a__	:						List[Any]      		=  tokenizer.tokenize(snake_case      )
      self.assertListEqual(snake_case					,			["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]      )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case      )					,			[3, 12, 10, 14, 4, 9, 12, 10, 14]      )

      a__	:						int      		=  os.path.join(self.tmpdirname					,			"tokenizer.bin"      )
      with open(snake_case					,			"wb"      ) as handle:
         pickle.dump(snake_case					,			snake_case      )

      with open(snake_case					,			"rb"      ) as handle:
         a__	:						str      		=  pickle.load(snake_case      )

      a__	:						Tuple      		=  tokenizer_new.tokenize(snake_case      )

      self.assertListEqual(snake_case					,			snake_case      )





   @require_sudachi
   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						Optional[Any]      		=  SudachiTokenizer(sudachi_dict_type="core"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			[" ", "\t", "アップル", "ストア", "で", "iPhone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]					,			)





   @require_sudachi
   def 	_snake_case ( self      )				->  str:
      """simple docstring"""





      a__	:						Any      		=  SudachiTokenizer(sudachi_dict_type="core"					,			sudachi_split_mode="A"      )

      self.assertListEqual(tokenizer.tokenize("外国人参政権"      )					,			["外国", "人", "参政", "権"]      )





   @require_sudachi
   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						Optional[int]      		=  SudachiTokenizer(sudachi_dict_type="core"					,			sudachi_split_mode="B"      )

      self.assertListEqual(tokenizer.tokenize("外国人参政権"      )					,			["外国人", "参政権"]      )





   @require_sudachi
   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      a__	:						Optional[int]      		=  SudachiTokenizer(sudachi_dict_type="core"					,			sudachi_split_mode="C"      )

      self.assertListEqual(tokenizer.tokenize("外国人参政権"      )					,			["外国人参政権"]      )





   @require_sudachi
   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						List[str]      		=  SudachiTokenizer(do_lower_case=snake_case					,			sudachi_dict_type="core"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			[" ", "\t", "アップル", "ストア", "で", "iphone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]					,			)





   @require_sudachi
   def 	_snake_case ( self      )				->  Optional[int]:
      """simple docstring"""





      a__	:						Optional[int]      		=  SudachiTokenizer(normalize_text=snake_case					,			sudachi_dict_type="core"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			[" ", "\t", "ｱｯﾌﾟﾙ", "ストア", "で", "iPhone", "８", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", "\u3000", "。", " ", " "]					,			)





   @require_sudachi
   def 	_snake_case ( self      )				->  Optional[int]:
      """simple docstring"""





      a__	:						str      		=  SudachiTokenizer(trim_whitespace=snake_case					,			sudachi_dict_type="core"      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,			)





   @require_jumanpp
   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  self.tokenizer_class(self.vocab_file					,			word_tokenizer_type="jumanpp"      )
      self.assertIsNotNone(snake_case      )

      a__	:						Dict      		=  "こんにちは、世界。\nこんばんは、世界。"
      a__	:						Optional[Any]      		=  tokenizer.tokenize(snake_case      )
      self.assertListEqual(snake_case					,			["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]      )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case      )					,			[3, 12, 10, 14, 4, 9, 12, 10, 14]      )

      a__	:						Tuple      		=  os.path.join(self.tmpdirname					,			"tokenizer.bin"      )
      with open(snake_case					,			"wb"      ) as handle:
         pickle.dump(snake_case					,			snake_case      )

      with open(snake_case					,			"rb"      ) as handle:
         a__	:						Any      		=  pickle.load(snake_case      )

      a__	:						Tuple      		=  tokenizer_new.tokenize(snake_case      )

      self.assertListEqual(snake_case					,			snake_case      )





   @require_jumanpp
   def 	_snake_case ( self      )				->  str:
      """simple docstring"""





      a__	:						str      		=  JumanppTokenizer()

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iPhone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,			)





   @require_jumanpp
   def 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      a__	:						Optional[Any]      		=  JumanppTokenizer(do_lower_case=snake_case      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iphone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,			)





   @require_jumanpp
   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						List[Any]      		=  JumanppTokenizer(normalize_text=snake_case      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["ｱ", "ｯ", "ﾌ", "ﾟ", "ﾙ", "ストア", "で", "iPhone", "８", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,			)





   @require_jumanpp
   def 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      a__	:						str      		=  JumanppTokenizer(trim_whitespace=snake_case      )

      self.assertListEqual(
          tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "      )					,			["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れた", "。"]					,			)





   @require_jumanpp
   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						List[Any]      		=  JumanppTokenizer()

      self.assertListEqual(
          tokenizer.tokenize("ありがとうございますm(_ _)ｍ見つけるのが大変です。"      )					,			["ありがとう", "ございます", "m(_ _)m", "見つける", "の", "が", "大変です", "。"]					,			)





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      a__	:						str      		=  ["[UNK]", "[CLS]", "[SEP]", "こんにちは", "こん", "にちは", "ばんは", "##こん", "##にちは", "##ばんは"]

      a__	:						Dict      		=  {}
      for i, token in enumerate(snake_case      ):
         a__	:						Any      		=  i
      a__	:						Dict      		=  WordpieceTokenizer(vocab=snake_case					,			unk_token="[UNK]"      )

      self.assertListEqual(tokenizer.tokenize(""      )					,			[]      )

      self.assertListEqual(tokenizer.tokenize("こんにちは"      )					,			["こんにちは"]      )

      self.assertListEqual(tokenizer.tokenize("こんばんは"      )					,			["こん", "##ばんは"]      )

      self.assertListEqual(tokenizer.tokenize("こんばんは こんばんにちは こんにちは"      )					,			["こん", "##ばんは", "[UNK]", "こんにちは"]      )





   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						List[str]      		=  BertJapaneseTokenizer.from_pretrained("nlp-waseda/roberta-base-japanese-with-auto-jumanpp"      )
      a__	:						int      		=  tokenizer.subword_tokenizer

      a__	:						List[str]      		=  subword_tokenizer.tokenize("国境 の 長い トンネル を 抜ける と 雪国 であった 。"      )
      self.assertListEqual(snake_case					,			["▁国境", "▁の", "▁長い", "▁トンネル", "▁を", "▁抜ける", "▁と", "▁雪", "国", "▁であった", "▁。"]      )

      a__	:						Optional[int]      		=  subword_tokenizer.tokenize("こんばんは こんばん にち は こんにちは"      )
      self.assertListEqual(snake_case					,			["▁こん", "ばん", "は", "▁こん", "ばん", "▁に", "ち", "▁は", "▁こんにちは"]      )





   def 	_snake_case ( self      )				->  Union[str, Any]:
      """simple docstring"""





      a__	:						Optional[Any]      		=  self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese"      )

      a__	:						Union[str, Any]      		=  tokenizer.encode("ありがとう。"					,			add_special_tokens=snake_case      )
      a__	:						List[str]      		=  tokenizer.encode("どういたしまして。"					,			add_special_tokens=snake_case      )

      a__	:						Optional[Any]      		=  tokenizer.build_inputs_with_special_tokens(snake_case      )
      a__	:						Tuple      		=  tokenizer.build_inputs_with_special_tokens(snake_case					,			snake_case      )

      # 2 is for "[CLS]", 3 is for "[SEP]"
      assert encoded_sentence == [2] + text + [3]
      assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class   __lowerCAmelCase			(					_UpperCamelCase		,unittest.TestCase  ):
   _UpperCamelCase :						int     		=				BertJapaneseTokenizer
   _UpperCamelCase :						Optional[int]     		=				False





   def 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      super().setUp()

      a__	:						Union[str, Any]      		=  ["[UNK]", "[CLS]", "[SEP]", "こ", "ん", "に", "ち", "は", "ば", "世", "界", "、", "。"]

      a__	:						Dict      		=  os.path.join(self.tmpdirname					,			VOCAB_FILES_NAMES["vocab_file"]      )
      with open(self.vocab_file					,			"w"					,			encoding="utf-8"      ) as vocab_writer:
         vocab_writer.write("".join([x + "\n" for x in vocab_tokens]      )      )





   def 	_snake_case ( self					,			**snake_case      )				->  Union[str, Any]:
      """simple docstring"""





      return BertJapaneseTokenizer.from_pretrained(self.tmpdirname					,			subword_tokenizer_type="character"					,			**snake_case      )





   def 	_snake_case ( self					,			snake_case      )				->  Dict:
      """simple docstring"""





      a__	:						Dict      		=  "こんにちは、世界。 \nこんばんは、世界。"
      a__	:						List[Any]      		=  "こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。"
      return input_text, output_text





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  List[str]:
      """simple docstring"""





      pass  # TODO add if relevant





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  self.tokenizer_class(self.vocab_file					,			subword_tokenizer_type="character"      )

      a__	:						Any      		=  tokenizer.tokenize("こんにちは、世界。 \nこんばんは、世界。"      )
      self.assertListEqual(
          snake_case					,			["こ", "ん", "に", "ち", "は", "、", "世", "界", "。", "こ", "ん", "ば", "ん", "は", "、", "世", "界", "。"]      )
      self.assertListEqual(
          tokenizer.convert_tokens_to_ids(snake_case      )					,			[3, 4, 5, 6, 7, 11, 9, 10, 12, 3, 4, 8, 4, 7, 11, 9, 10, 12]      )





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						str      		=  ["[UNK]", "[CLS]", "[SEP]", "こ", "ん", "に", "ち", "は", "ば", "世", "界", "、", "。"]

      a__	:						Any      		=  {}
      for i, token in enumerate(snake_case      ):
         a__	:						Tuple      		=  i
      a__	:						Union[str, Any]      		=  CharacterTokenizer(vocab=snake_case					,			unk_token="[UNK]"      )

      self.assertListEqual(tokenizer.tokenize(""      )					,			[]      )

      self.assertListEqual(tokenizer.tokenize("こんにちは"      )					,			["こ", "ん", "に", "ち", "は"]      )

      self.assertListEqual(tokenizer.tokenize("こんにちほ"      )					,			["こ", "ん", "に", "ち", "[UNK]"]      )





   def 	_snake_case ( self      )				->  Optional[int]:
      """simple docstring"""





      a__	:						Optional[Any]      		=  self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese-char"      )

      a__	:						List[str]      		=  tokenizer.encode("ありがとう。"					,			add_special_tokens=snake_case      )
      a__	:						List[str]      		=  tokenizer.encode("どういたしまして。"					,			add_special_tokens=snake_case      )

      a__	:						Dict      		=  tokenizer.build_inputs_with_special_tokens(snake_case      )
      a__	:						Optional[Any]      		=  tokenizer.build_inputs_with_special_tokens(snake_case					,			snake_case      )

      # 2 is for "[CLS]", 3 is for "[SEP]"
      assert encoded_sentence == [2] + text + [3]
      assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class   __lowerCAmelCase			(					unittest.TestCase  ):





   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      a__	:						Dict      		=  "cl-tohoku/bert-base-japanese"
      a__	:						Optional[int]      		=  AutoTokenizer.from_pretrained(snake_case      )
      self.assertIsInstance(snake_case					,			snake_case      )







class   __lowerCAmelCase			(					unittest.TestCase  ):





   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      a__	:						List[str]      		=  "cl-tohoku/bert-base-japanese"
      with self.assertLogs("transformers"					,			level="WARNING"      ) as cm:
         BertTokenizer.from_pretrained(snake_case      )
         self.assertTrue(
             cm.records[0].message.startswith(
                 "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                 " is called from."      )      )
      a__	:						Optional[int]      		=  "bert-base-cased"
      with self.assertLogs("transformers"					,			level="WARNING"      ) as cm:
         BertJapaneseTokenizer.from_pretrained(snake_case      )
         self.assertTrue(
             cm.records[0].message.startswith(
                 "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                 " is called from."      )      )








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


SCREAMING_SNAKE_CASE__       :			Dict			      =						"""CompVis/stable-diffusion-v1-1"""
SCREAMING_SNAKE_CASE__       :			Dict			      =						"""CompVis/stable-diffusion-v1-2"""
SCREAMING_SNAKE_CASE__       :			Tuple			      =						"""CompVis/stable-diffusion-v1-3"""
SCREAMING_SNAKE_CASE__       :			str			      =						"""CompVis/stable-diffusion-v1-4"""







class   __lowerCAmelCase			(					_UpperCamelCase  ):





   def __init__( self					,			snake_case					,			snake_case					,			snake_case					,			snake_case					,			snake_case					,			snake_case					,			snake_case					,			snake_case = True					,			)				->  Any:
      """simple docstring"""





      super()._init_()

      a__	:						Union[str, Any]      		=  StableDiffusionPipeline.from_pretrained(snake_case      )
      a__	:						Optional[Any]      		=  StableDiffusionPipeline.from_pretrained(snake_case      )
      a__	:						Optional[Any]      		=  StableDiffusionPipeline.from_pretrained(snake_case      )
      a__	:						int      		=  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 	_snake_case ( self      )				->  Dict[str, Any]:
      """simple docstring"""





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





   def 	_snake_case ( self					,			snake_case = "auto"      )				->  Optional[Any]:
      """simple docstring"""





      if slice_size == "auto":
         # half the attention head size is usually a good trade-off between
         # speed and memory
         a__	:						List[Any]      		=  self.unet.config.attention_head_dim // 2
      self.unet.set_attention_slice(snake_case      )





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      self.enable_attention_slicing(snake_case      )





   @torch.no_grad()
   def 	_snake_case ( self					,			snake_case					,			snake_case = 512					,			snake_case = 512					,			snake_case = 50					,			snake_case = 7.5					,			snake_case = None					,			snake_case = 1					,			snake_case = 0.0					,			snake_case = None					,			snake_case = None					,			snake_case = "pil"					,			snake_case = True					,			snake_case = None					,			snake_case = 1					,			**snake_case					,			)				->  Optional[int]:
      """simple docstring"""





      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 	_snake_case ( self					,			snake_case					,			snake_case = 512					,			snake_case = 512					,			snake_case = 50					,			snake_case = 7.5					,			snake_case = None					,			snake_case = 1					,			snake_case = 0.0					,			snake_case = None					,			snake_case = None					,			snake_case = "pil"					,			snake_case = True					,			snake_case = None					,			snake_case = 1					,			**snake_case					,			)				->  Dict:
      """simple docstring"""





      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 	_snake_case ( self					,			snake_case					,			snake_case = 512					,			snake_case = 512					,			snake_case = 50					,			snake_case = 7.5					,			snake_case = None					,			snake_case = 1					,			snake_case = 0.0					,			snake_case = None					,			snake_case = None					,			snake_case = "pil"					,			snake_case = True					,			snake_case = None					,			snake_case = 1					,			**snake_case					,			)				->  Union[str, Any]:
      """simple docstring"""





      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 	_snake_case ( self					,			snake_case					,			snake_case = 512					,			snake_case = 512					,			snake_case = 50					,			snake_case = 7.5					,			snake_case = None					,			snake_case = 1					,			snake_case = 0.0					,			snake_case = None					,			snake_case = None					,			snake_case = "pil"					,			snake_case = True					,			snake_case = None					,			snake_case = 1					,			**snake_case					,			)				->  Dict:
      """simple docstring"""





      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 	_snake_case ( self					,			snake_case					,			snake_case = 512					,			snake_case = 512					,			snake_case = 50					,			snake_case = 7.5					,			snake_case = None					,			snake_case = 1					,			snake_case = 0.0					,			snake_case = None					,			snake_case = None					,			snake_case = "pil"					,			snake_case = True					,			snake_case = None					,			snake_case = 1					,			**snake_case					,			)				->  Dict:
      """simple docstring"""





      a__	:						Any      		=  "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
      a__	:						Any      		=  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
      a__	:						List[Any]      		=  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
      a__	:						Optional[Any]      		=  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
      a__	:						Dict      		=  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]]      )

