


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  SCREAMING_SNAKE_CASE__  (				lowercase__						,    unittest.TestCase			):
      snake_case__				:     int        =						BertJapaneseTokenizer
      snake_case__				:     Optional[int]        =						False
      snake_case__				:     Union[str, Any]        =						True
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			List[str]:
             super().setUp()

             a_					:		Optional[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        SCREAMING_SNAKE_CASE							(       self				:       str     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     )		->			Optional[int]:
             a_					:		Optional[int]							=  'こんにちは、世界。 \nこんばんは、世界。'
             a_					:		Optional[Any]							=  'こんにちは 、 世界 。 こんばんは 、 世界 。'
             return input_text, output_text
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       List[str]     )		->			int:
             a_							,		a_					:		int							=  self.get_input_output_texts(SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  tokenizer.encode(SCREAMING_SNAKE_CASE__     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )
             a_					:		Tuple							=  tokenizer.decode(SCREAMING_SNAKE_CASE__     ,							clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE__     )
             return text, ids
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			Dict:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Tuple:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Optional[Any]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Any:
             a_					:		Union[str, Any]							=  self.tokenizer_class(self.vocab_file     )

             a_					:		str							=  tokenizer.tokenize('こんにちは、世界。\nこんばんは、世界。'     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			List[str]:
             a_					:		str							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='mecab'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		str							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		List[Any]							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		Optional[int]							=  os.path.join(self.tmpdirname     ,							'tokenizer.bin'     )
             with open(SCREAMING_SNAKE_CASE__     ,							'wb'     ) as handle:
                    pickle.dump(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

             with open(SCREAMING_SNAKE_CASE__     ,							'rb'     ) as handle:
                    a_					:		Union[str, Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		List[Any]							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Union[str, Any]:
             a_					:		List[str]							=  MecabTokenizer(mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップルストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			List[Any]:
             try:
                    a_					:		List[str]							=  MecabTokenizer(mecab_dic='unidic_lite'     )
             except ModuleNotFoundError:
                    return

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Optional[int]:
             try:
                    a_					:		Union[str, Any]							=  MecabTokenizer(mecab_dic='unidic'     )
             except ModuleNotFoundError:
                    return

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Any:
             a_					:		Optional[Any]							=  MecabTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__     ,							mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップルストア', 'で', 'iphone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			Union[str, Any]:
             try:
                    a_					:		Any							=  MecabTokenizer(
                        do_lower_case=SCREAMING_SNAKE_CASE__     ,							normalize_text=SCREAMING_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        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Any:
             a_					:		int							=  MecabTokenizer(normalize_text=SCREAMING_SNAKE_CASE__     ,							mecab_dic='ipadic'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['ｱｯﾌﾟﾙストア', 'で', 'iPhone', '８', 'が', '発売', 'さ', 'れ', 'た', '　', '。']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			str:
             a_					:		List[str]							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='sudachi'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		List[str]							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		Dict							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		int							=  os.path.join(self.tmpdirname     ,							'tokenizer.bin'     )
             with open(SCREAMING_SNAKE_CASE__     ,							'wb'     ) as handle:
                    pickle.dump(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

             with open(SCREAMING_SNAKE_CASE__     ,							'rb'     ) as handle:
                    a_					:		Union[str, Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[Any]							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			List[str]:
             a_					:		List[str]							=  SudachiTokenizer(sudachi_dict_type='core'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							[' ', '\t', 'アップル', 'ストア', 'で', 'iPhone', '8', ' ', 'が', ' ', ' ', '\n ', '発売', 'さ', 'れ', 'た', ' ', '。', ' ', ' ']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Union[str, Any]:
             a_					:		List[Any]							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='A'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国', '人', '参政', '権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Tuple:
             a_					:		Tuple							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='B'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国人', '参政権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			List[str]:
             a_					:		Union[str, Any]							=  SudachiTokenizer(sudachi_dict_type='core'     ,							sudachi_split_mode='C'     )

             self.assertListEqual(tokenizer.tokenize('外国人参政権'     )     ,							['外国人参政権']     )
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			Union[str, Any]:
             a_					:		Dict							=  SudachiTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__     ,							sudachi_dict_type='core'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							[' ', '\t', 'アップル', 'ストア', 'で', 'iphone', '8', ' ', 'が', ' ', ' ', '\n ', '発売', 'さ', 'れ', 'た', ' ', '。', ' ', ' ']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Optional[Any]:
             a_					:		Any							=  SudachiTokenizer(normalize_text=SCREAMING_SNAKE_CASE__     ,							sudachi_dict_type='core'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							[' ', '\t', 'ｱｯﾌﾟﾙ', 'ストア', 'で', 'iPhone', '８', ' ', 'が', ' ', ' ', '\n ', '発売', 'さ', 'れ', 'た', '\u3000', '。', ' ', ' ']     ,							)
      @require_sudachi
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			List[str]:
             a_					:		int							=  SudachiTokenizer(trim_whitespace=SCREAMING_SNAKE_CASE__     ,							sudachi_dict_type='core'     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れ', 'た', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Optional[Any]:
             a_					:		Tuple							=  self.tokenizer_class(self.vocab_file     ,							word_tokenizer_type='jumanpp'     )
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )

             a_					:		Any							=  'こんにちは、世界。\nこんばんは、世界。'
             a_					:		List[Any]							=  tokenizer.tokenize(SCREAMING_SNAKE_CASE__     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['こんにちは', '、', '世界', '。', 'こん', '##ばんは', '、', '世界', '。']     )
             self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]     )

             a_					:		Optional[int]							=  os.path.join(self.tmpdirname     ,							'tokenizer.bin'     )
             with open(SCREAMING_SNAKE_CASE__     ,							'wb'     ) as handle:
                    pickle.dump(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

             with open(SCREAMING_SNAKE_CASE__     ,							'rb'     ) as handle:
                    a_					:		Optional[Any]							=  pickle.load(SCREAMING_SNAKE_CASE__     )

             a_					:		Tuple							=  tokenizer_new.tokenize(SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Optional[int]:
             a_					:		Optional[Any]							=  JumanppTokenizer()

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', '\u3000', 'が', '\u3000', '\u3000', '\u3000', '発売', 'さ', 'れた', '\u3000', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Optional[Any]:
             a_					:		Union[str, Any]							=  JumanppTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iphone', '8', '\u3000', 'が', '\u3000', '\u3000', '\u3000', '発売', 'さ', 'れた', '\u3000', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			List[Any]:
             a_					:		Optional[int]							=  JumanppTokenizer(normalize_text=SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['ｱ', 'ｯ', 'ﾌ', 'ﾟ', 'ﾙ', 'ストア', 'で', 'iPhone', '８', '\u3000', 'が', '\u3000', '\u3000', '\u3000', '発売', 'さ', 'れた', '\u3000', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			int:
             a_					:		Dict							=  JumanppTokenizer(trim_whitespace=SCREAMING_SNAKE_CASE__     )

             self.assertListEqual(
                 tokenizer.tokenize(' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '     )     ,							['アップル', 'ストア', 'で', 'iPhone', '8', 'が', '発売', 'さ', 'れた', '。']     ,							)
      @require_jumanpp
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			List[str]:
             a_					:		str							=  JumanppTokenizer()

             self.assertListEqual(
                 tokenizer.tokenize('ありがとうございますm(_ _)ｍ見つけるのが大変です。'     )     ,							['ありがとう', 'ございます', 'm(_ _)m', '見つける', 'の', 'が', '大変です', '。']     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			Any:
             a_					:		Tuple							=  ['[UNK]', '[CLS]', '[SEP]', 'こんにちは', 'こん', 'にちは', 'ばんは', '##こん', '##にちは', '##ばんは']

             a_					:		List[Any]							=  {}
             for i, token in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		List[str]							=  i
             a_					:		Dict							=  WordpieceTokenizer(vocab=SCREAMING_SNAKE_CASE__     ,							unk_token='[UNK]'     )

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

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

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

             self.assertListEqual(tokenizer.tokenize('こんばんは こんばんにちは こんにちは'     )     ,							['こん', '##ばんは', '[UNK]', 'こんにちは']     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			List[str]:
             a_					:		List[str]							=  BertJapaneseTokenizer.from_pretrained('nlp-waseda/roberta-base-japanese-with-auto-jumanpp'     )
             a_					:		List[str]							=  tokenizer.subword_tokenizer

             a_					:		Optional[int]							=  subword_tokenizer.tokenize('国境 の 長い トンネル を 抜ける と 雪国 であった 。'     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['▁国境', '▁の', '▁長い', '▁トンネル', '▁を', '▁抜ける', '▁と', '▁雪', '国', '▁であった', '▁。']     )

             a_					:		Optional[int]							=  subword_tokenizer.tokenize('こんばんは こんばん にち は こんにちは'     )
             self.assertListEqual(SCREAMING_SNAKE_CASE__     ,							['▁こん', 'ばん', 'は', '▁こん', 'ばん', '▁に', 'ち', '▁は', '▁こんにちは']     )

      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Tuple:
             a_					:		Optional[Any]							=  self.tokenizer_class.from_pretrained('cl-tohoku/bert-base-japanese'     )

             a_					:		int							=  tokenizer.encode('ありがとう。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )
             a_					:		Dict							=  tokenizer.encode('どういたしまして。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )

             a_					:		int							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     ,							SCREAMING_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  SCREAMING_SNAKE_CASE__  (				lowercase__						,    unittest.TestCase			):
      snake_case__				:     Optional[int]        =						BertJapaneseTokenizer
      snake_case__				:     str        =						False
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Any:
             super().setUp()

             a_					:		int							=  ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

             a_					:		str							=  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        SCREAMING_SNAKE_CASE							(       self				:       str     ,							**SCREAMING_SNAKE_CASE__				:       Optional[int]     )		->			Tuple:
             return BertJapaneseTokenizer.from_pretrained(self.tmpdirname     ,							subword_tokenizer_type='character'     ,							**SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       List[str]     )		->			List[str]:
             a_					:		List[Any]							=  'こんにちは、世界。 \nこんばんは、世界。'
             a_					:		Optional[Any]							=  'こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'
             return input_text, output_text
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			List[str]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			List[str]:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Tuple:
             pass  # TODO add if relevant
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Dict:
             a_					:		Optional[int]							=  self.tokenizer_class(self.vocab_file     ,							subword_tokenizer_type='character'     )

             a_					:		Any							=  tokenizer.tokenize('こんにちは、世界。 \nこんばんは、世界。'     )
             self.assertListEqual(
                 SCREAMING_SNAKE_CASE__     ,							['こ', 'ん', 'に', 'ち', 'は', '、', '世', '界', '。', 'こ', 'ん', 'ば', 'ん', 'は', '、', '世', '界', '。']     )
             self.assertListEqual(
                 tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__     )     ,							[3, 4, 5, 6, 7, 1_1, 9, 1_0, 1_2, 3, 4, 8, 4, 7, 1_1, 9, 1_0, 1_2]     )
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		Dict							=  ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

             a_					:		Dict							=  {}
             for i, token in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		str							=  i
             a_					:		Optional[Any]							=  CharacterTokenizer(vocab=SCREAMING_SNAKE_CASE__     ,							unk_token='[UNK]'     )

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

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

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

      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		Union[str, Any]							=  self.tokenizer_class.from_pretrained('cl-tohoku/bert-base-japanese-char'     )

             a_					:		Optional[Any]							=  tokenizer.encode('ありがとう。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  tokenizer.encode('どういたしまして。'     ,							add_special_tokens=SCREAMING_SNAKE_CASE__     )

             a_					:		Union[str, Any]							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     )
             a_					:		Union[str, Any]							=  tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     ,							SCREAMING_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  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			List[str]:
             a_					:		int							=  'cl-tohoku/bert-base-japanese'
             a_					:		Optional[Any]							=  AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__     )
             self.assertIsInstance(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Optional[Any]:
             a_					:		List[str]							=  'cl-tohoku/bert-base-japanese'
             with self.assertLogs('transformers'     ,							level='WARNING'     ) as cm:
                    BertTokenizer.from_pretrained(SCREAMING_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_					:		Tuple							=  'bert-base-cased'
             with self.assertLogs('transformers'     ,							level='WARNING'     ) as cm:
                    BertJapaneseTokenizer.from_pretrained(SCREAMING_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.'     )     )







"""simple docstring"""
import gc
import math
import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, logging, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


__a      =				logging.get_logger(__name__)

enable_full_determinism()
class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			List[Any]						=     UNetaDModel
					_A		:			Union[str, Any]						=     """sample"""






					@property
					def    lowerCAmelCase_				(       self:							str						)   ->	Tuple:
											snake_case_ :List[str]						=			4
											snake_case_ :Tuple						=			3
											snake_case_ :Optional[Any]						=			(32, 32)

											snake_case_ :str						=			floats_tensor((batch_size, num_channels) + sizes						).to(snake_case						)
											snake_case_ :Union[str, Any]						=			torch.tensor([10]						).to(snake_case						)

											return {"sample": noise, "timestep": time_step}






					@property
					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Dict:
											return (3, 32, 32)






					@property
					def    lowerCAmelCase_				(       self:							Optional[int]						)   ->	Optional[int]:
											return (3, 32, 32)






					def    lowerCAmelCase_				(       self:							Optional[int]						)   ->	Dict:
											snake_case_ :Any						=			{
											    """block_out_channels""": (32, 64),
											    """down_block_types""": ("""DownBlock2D""", """AttnDownBlock2D"""),
											    """up_block_types""": ("""AttnUpBlock2D""", """UpBlock2D"""),
											    """attention_head_dim""": 3,
											    """out_channels""": 3,
											    """in_channels""": 3,
											    """layers_per_block""": 2,
											    """sample_size""": 32,
											}
											snake_case_ :Tuple						=			self.dummy_input
											return init_dict, inputs_dict

class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			List[str]						=     UNetaDModel
					_A		:			Union[str, Any]						=     """sample"""






					@property
					def    lowerCAmelCase_				(       self:							str						)   ->	str:
											snake_case_ :List[str]						=			4
											snake_case_ :Optional[int]						=			4
											snake_case_ :int						=			(32, 32)

											snake_case_ :Any						=			floats_tensor((batch_size, num_channels) + sizes						).to(snake_case						)
											snake_case_ :List[Any]						=			torch.tensor([10]						).to(snake_case						)

											return {"sample": noise, "timestep": time_step}






					@property
					def    lowerCAmelCase_				(       self:							Optional[int]						)   ->	Optional[int]:
											return (4, 32, 32)






					@property
					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	int:
											return (4, 32, 32)






					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	List[Any]:
											snake_case_ :Dict						=			{
											    """sample_size""": 32,
											    """in_channels""": 4,
											    """out_channels""": 4,
											    """layers_per_block""": 2,
											    """block_out_channels""": (32, 64),
											    """attention_head_dim""": 32,
											    """down_block_types""": ("""DownBlock2D""", """DownBlock2D"""),
											    """up_block_types""": ("""UpBlock2D""", """UpBlock2D"""),
											}
											snake_case_ :List[str]						=			self.dummy_input
											return init_dict, inputs_dict






					def    lowerCAmelCase_				(       self:							Optional[int]						)   ->	Optional[Any]:
											snake_case_,       snake_case_ :List[str]						=			UNetaDModel.from_pretrained("""fusing/unet-ldm-dummy-update"""						,     output_loading_info=snake_case						)

											self.assertIsNotNone(snake_case						)
											self.assertEqual(len(loading_info["""missing_keys"""]						)						,     0						)

											model.to(snake_case						)
											snake_case_ :List[str]						=			model(**self.dummy_input						).sample

											assert image is not None, "Make sure output is not None"






					@unittest.skipIf(torch_device != """cuda"""						,     """This test is supposed to run on GPU"""						)
					def    lowerCAmelCase_				(       self:							Tuple						)   ->	Dict:
											snake_case_,       snake_case_ :Union[str, Any]						=			UNetaDModel.from_pretrained("""fusing/unet-ldm-dummy-update"""						,     output_loading_info=snake_case						)
											model.to(snake_case						)
											snake_case_ :Union[str, Any]						=			model(**self.dummy_input						).sample

											assert image is not None, "Make sure output is not None"






					@unittest.skipIf(torch_device != """cuda"""						,     """This test is supposed to run on GPU"""						)
					def    lowerCAmelCase_				(       self:							str						)   ->	Any:
											# by defautl model loading will use accelerate as `low_cpu_mem_usage=True`
											snake_case_,       snake_case_ :List[str]						=			UNetaDModel.from_pretrained("""fusing/unet-ldm-dummy-update"""						,     output_loading_info=snake_case						)
											model_accelerate.to(snake_case						)
											model_accelerate.eval()

											snake_case_ :List[Any]						=			torch.randn(
											    1						,     model_accelerate.config.in_channels						,     model_accelerate.config.sample_size						,     model_accelerate.config.sample_size						,     generator=torch.manual_seed(0						)						,     )
											snake_case_ :int						=			noise.to(snake_case						)
											snake_case_ :str						=			torch.tensor([10] * noise.shape[0]						).to(snake_case						)

											snake_case_ :Optional[int]						=			model_accelerate(snake_case						,     snake_case						)["""sample"""]

											# two models don't need to stay in the device at the same time
											del model_accelerate
											torch.cuda.empty_cache()
											gc.collect()

											snake_case_,       snake_case_ :str						=			UNetaDModel.from_pretrained(
											    """fusing/unet-ldm-dummy-update"""						,     output_loading_info=snake_case						,     low_cpu_mem_usage=snake_case						)
											model_normal_load.to(snake_case						)
											model_normal_load.eval()
											snake_case_ :int						=			model_normal_load(snake_case						,     snake_case						)["""sample"""]

											assert torch_all_close(snake_case						,     snake_case						,     rtol=1E-3						)






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	Any:
											snake_case_ :Tuple						=			UNetaDModel.from_pretrained("""fusing/unet-ldm-dummy-update"""						)
											model.eval()
											model.to(snake_case						)

											snake_case_ :Optional[int]						=			torch.randn(
											    1						,     model.config.in_channels						,     model.config.sample_size						,     model.config.sample_size						,     generator=torch.manual_seed(0						)						,     )
											snake_case_ :int						=			noise.to(snake_case						)
											snake_case_ :List[Any]						=			torch.tensor([10] * noise.shape[0]						).to(snake_case						)

											with torch.no_grad():
																	snake_case_ :Union[str, Any]						=			model(snake_case						,     snake_case						).sample

											snake_case_ :Optional[int]						=			output[0, -1, -3:, -3:].flatten().cpu()
											# fmt: off
											snake_case_ :Dict						=			torch.tensor([-1_3.3_2_5_8, -2_0.1_1_0_0, -1_5.9_8_7_3, -1_7.6_6_1_7, -2_3.0_5_9_6, -1_7.9_4_1_9, -1_3.3_6_7_5, -1_6.1_8_8_9, -1_2.3_8_0_0]						)
											# fmt: on

											self.assertTrue(torch_all_close(snake_case						,     snake_case						,     rtol=1E-3						)						)

class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			List[Any]						=     UNetaDModel
					_A		:			List[Any]						=     """sample"""






					@property
					def    lowerCAmelCase_				(       self:							Union[str, Any]						,     snake_case:							int=(32, 32)						)   ->	Tuple:
											snake_case_ :Union[str, Any]						=			4
											snake_case_ :Any						=			3

											snake_case_ :int						=			floats_tensor((batch_size, num_channels) + sizes						).to(snake_case						)
											snake_case_ :Any						=			torch.tensor(batch_size * [10]						).to(dtype=torch.intaa						,     device=snake_case						)

											return {"sample": noise, "timestep": time_step}






					@property
					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Any:
											return (3, 32, 32)






					@property
					def    lowerCAmelCase_				(       self:							int						)   ->	Tuple:
											return (3, 32, 32)






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	Tuple:
											snake_case_ :List[Any]						=			{
											    """block_out_channels""": [32, 64, 64, 64],
											    """in_channels""": 3,
											    """layers_per_block""": 1,
											    """out_channels""": 3,
											    """time_embedding_type""": """fourier""",
											    """norm_eps""": 1E-6,
											    """mid_block_scale_factor""": math.sqrt(2.0						),
											    """norm_num_groups""": None,
											    """down_block_types""": [
											        """SkipDownBlock2D""",
											        """AttnSkipDownBlock2D""",
											        """SkipDownBlock2D""",
											        """SkipDownBlock2D""",
											    ],
											    """up_block_types""": [
											        """SkipUpBlock2D""",
											        """SkipUpBlock2D""",
											        """AttnSkipUpBlock2D""",
											        """SkipUpBlock2D""",
											    ],
											}
											snake_case_ :int						=			self.dummy_input
											return init_dict, inputs_dict






					@slow
					def    lowerCAmelCase_				(       self:							Optional[Any]						)   ->	List[Any]:
											snake_case_,       snake_case_ :List[Any]						=			UNetaDModel.from_pretrained("""google/ncsnpp-celebahq-256"""						,     output_loading_info=snake_case						)
											self.assertIsNotNone(snake_case						)
											self.assertEqual(len(loading_info["""missing_keys"""]						)						,     0						)

											model.to(snake_case						)
											snake_case_ :Any						=			self.dummy_input
											snake_case_ :int						=			floats_tensor((4, 3) + (256, 256)						).to(snake_case						)
											snake_case_ :int						=			noise
											snake_case_ :int						=			model(**snake_case						)

											assert image is not None, "Make sure output is not None"






					@slow
					def    lowerCAmelCase_				(       self:							str						)   ->	Dict:
											snake_case_ :Dict						=			UNetaDModel.from_pretrained("""google/ncsnpp-celebahq-256"""						)
											model.to(snake_case						)

											snake_case_ :List[str]						=			4
											snake_case_ :Optional[int]						=			3
											snake_case_ :List[str]						=			(256, 256)

											snake_case_ :Tuple						=			torch.ones((batch_size, num_channels) + sizes						).to(snake_case						)
											snake_case_ :str						=			torch.tensor(batch_size * [1E-4]						).to(snake_case						)

											with torch.no_grad():
																	snake_case_ :Dict						=			model(snake_case						,     snake_case						).sample

											snake_case_ :int						=			output[0, -3:, -3:, -1].flatten().cpu()
											# fmt: off
											snake_case_ :Optional[Any]						=			torch.tensor([-4_8_4_2.8_6_9_1, -6_4_9_9.6_6_3_1, -3_8_0_0.1_9_5_3, -7_9_7_8.2_6_8_6, -1_0_9_8_0.7_1_2_9, -2_0_0_2_8.8_5_3_5, 8_1_4_8.2_8_2_2, 2_3_4_2.2_9_0_5, 5_6_7.7_6_0_8]						)
											# fmt: on

											self.assertTrue(torch_all_close(snake_case						,     snake_case						,     rtol=1E-2						)						)






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	List[Any]:
											snake_case_ :Optional[Any]						=			UNetaDModel.from_pretrained("""fusing/ncsnpp-ffhq-ve-dummy-update"""						)
											model.to(snake_case						)

											snake_case_ :Optional[int]						=			4
											snake_case_ :Optional[Any]						=			3
											snake_case_ :Optional[Any]						=			(32, 32)

											snake_case_ :Dict						=			torch.ones((batch_size, num_channels) + sizes						).to(snake_case						)
											snake_case_ :Any						=			torch.tensor(batch_size * [1E-4]						).to(snake_case						)

											with torch.no_grad():
																	snake_case_ :str						=			model(snake_case						,     snake_case						).sample

											snake_case_ :int						=			output[0, -3:, -3:, -1].flatten().cpu()
											# fmt: off
											snake_case_ :int						=			torch.tensor([-0.0_3_2_5, -0.0_9_0_0, -0.0_8_6_9, -0.0_3_3_2, -0.0_7_2_5, -0.0_2_7_0, -0.0_1_0_1, 0.0_2_2_7, 0.0_2_5_6]						)
											# fmt: on

											self.assertTrue(torch_all_close(snake_case						,     snake_case						,     rtol=1E-2						)						)






					def    lowerCAmelCase_				(       self:							Dict						)   ->	Optional[Any]:
											# not required for this model
											pass
