

'''simple docstring'''

import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


A_       						=							get_tests_dir("fixtures/spiece.model")





@require_sentencepiece
@require_tokenizers
class 							_snake_case (       _a	,  unittest.TestCase						):
   _A       :     str       =					DebertaVaTokenizer
   _A       :     List[str]       =					DebertaVaTokenizerFast
   _A       :     Dict       =					True
   _A       :     Union[str, Any]       =					True
   def     __UpperCamelCase						( self			:      Optional[int]							):
     super().setUp()

     # We have a SentencePiece fixture for testing
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,unk_token="<unk>"							)
     tokenizer.save_pretrained(self.tmpdirname							)
   def     __UpperCamelCase						( self			:      int     ,SCREAMING_SNAKE_CASE__			:      Optional[int]							):
     SCREAMING_SNAKE_CASE:Dict						      =					"this is a test"
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					"this is a test"
     return input_text, output_text
   def     __UpperCamelCase						( self			:      Optional[int]							):
     SCREAMING_SNAKE_CASE:str						      =					"<pad>"
     SCREAMING_SNAKE_CASE:List[Any]						      =					0

     self.assertEqual(self.get_tokenizer()._convert_token_to_id(SCREAMING_SNAKE_CASE__							)     ,SCREAMING_SNAKE_CASE__							)
     self.assertEqual(self.get_tokenizer()._convert_id_to_token(SCREAMING_SNAKE_CASE__							)     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Dict							):
     SCREAMING_SNAKE_CASE:Tuple						      =					list(self.get_tokenizer().get_vocab().keys()							)
     self.assertEqual(vocab_keys[0]     ,"<pad>"							)
     self.assertEqual(vocab_keys[1]     ,"<unk>"							)
     self.assertEqual(vocab_keys[-1]     ,"[PAD]"							)
     self.assertEqual(len(SCREAMING_SNAKE_CASE__							)     ,30_001							)
   def     __UpperCamelCase						( self			:      int							):
     self.assertEqual(self.get_tokenizer().vocab_size     ,30_000							)
   def     __UpperCamelCase						( self			:      Any							):
     # fmt: off
     SCREAMING_SNAKE_CASE:int						      =					" \tHeLLo!how  \n Are yoU?  "
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					["▁hello", "!", "how", "▁are", "▁you", "?"]
     # fmt: on

     SCREAMING_SNAKE_CASE:Optional[int]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:List[Any]						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Dict						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   @unittest.skip("There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."							)
   def     __UpperCamelCase						( self			:      List[str]							):
     pass
   @unittest.skip("There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."							)
   def     __UpperCamelCase						( self			:      str							):
     pass
   def     __UpperCamelCase						( self			:      str							):
     # fmt: off
     SCREAMING_SNAKE_CASE:Tuple						      =					"I was born in 92000, and this is falsé."
     SCREAMING_SNAKE_CASE:List[str]						      =					["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     SCREAMING_SNAKE_CASE:Dict						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:str						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Dict						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Optional[Any]							):
     # fmt: off
     SCREAMING_SNAKE_CASE:int						      =					"I was born in 92000, and this is falsé."
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					["▁i", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     SCREAMING_SNAKE_CASE:List[Any]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Dict						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Any						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      List[str]							):
     # fmt: off
     SCREAMING_SNAKE_CASE:Tuple						      =					"I was born in 92000, and this is falsé."
     SCREAMING_SNAKE_CASE:List[str]						      =					["▁i", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
     # fmt: on

     SCREAMING_SNAKE_CASE:int						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Tuple						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Optional[Any]							):
     # fmt: off
     SCREAMING_SNAKE_CASE:List[Any]						      =					"I was born in 92000, and this is falsé."
     SCREAMING_SNAKE_CASE:str						      =					["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     SCREAMING_SNAKE_CASE:Optional[Any]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:List[str]						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      List[str]							):
     # fmt: off
     SCREAMING_SNAKE_CASE:List[str]						      =					" \tHeLLo!how  \n Are yoU?  "
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					["▁", "<unk>", "e", "<unk>", "o", "!", "how", "▁", "<unk>", "re", "▁yo", "<unk>", "?"]
     # fmt: on

     SCREAMING_SNAKE_CASE:List[str]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:List[Any]						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,do_lower_case=SCREAMING_SNAKE_CASE__     ,split_by_punct=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Tuple						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)

     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      int							):
     SCREAMING_SNAKE_CASE:List[str]						      =					self.get_tokenizer()
     SCREAMING_SNAKE_CASE:List[Any]						      =					self.get_rust_tokenizer()

     SCREAMING_SNAKE_CASE:Dict						      =					"I was born in 92000, and this is falsé."

     SCREAMING_SNAKE_CASE:Optional[Any]						      =					tokenizer.convert_ids_to_tokens(tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]						      =					tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:str						      =					self.get_rust_tokenizer()
     SCREAMING_SNAKE_CASE:str						      =					tokenizer.encode(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[Any]						      =					rust_tokenizer.encode(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Tuple							):
     SCREAMING_SNAKE_CASE:Tuple						      =					"This is a test"
     SCREAMING_SNAKE_CASE:List[Any]						      =					[13, 1, 4_398, 25, 21, 1_289]
     SCREAMING_SNAKE_CASE:Optional[int]						      =					["▁", "T", "his", "▁is", "▁a", "▁test"]
     SCREAMING_SNAKE_CASE:Dict						      =					["▁", "<unk>", "his", "▁is", "▁a", "▁test"]

     SCREAMING_SNAKE_CASE:List[Any]						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__     ,keep_accents=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					DebertaVaTokenizerFast(SCREAMING_SNAKE_CASE__     ,keep_accents=SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Any						      =					tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]						      =					tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Any						      =					tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]						      =					rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]						      =					rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					rust_tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     # fmt: off
     SCREAMING_SNAKE_CASE:Tuple						      =					"I was born in 92000, and this is falsé."
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					[13, 1, 23, 386, 19, 561, 3_050, 15, 17, 48, 25, 8_256, 18, 1, 9]
     SCREAMING_SNAKE_CASE:Tuple						      =					["▁", "I", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "é", ".", ]
     SCREAMING_SNAKE_CASE:List[Any]						      =					["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
     # fmt: on

     SCREAMING_SNAKE_CASE:int						      =					tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[Any]						      =					rust_tokenizer.encode(SCREAMING_SNAKE_CASE__     ,add_special_tokens=SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Any						      =					rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]						      =					rust_tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__							)
     self.assertListEqual(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Tuple							):
     SCREAMING_SNAKE_CASE:Tuple						      =					DebertaVaTokenizer(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Any						      =					tokenizer.encode("sequence builders"							)
     SCREAMING_SNAKE_CASE:List[str]						      =					tokenizer.encode("multi-sequence build"							)

     SCREAMING_SNAKE_CASE:Any						      =					tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Tuple						      =					tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)

     self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]     ,SCREAMING_SNAKE_CASE__							)
     self.assertEqual(
         [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]     ,SCREAMING_SNAKE_CASE__     ,)







   @slow
   def     __UpperCamelCase						( self			:      Optional[int]							):
     # fmt: off
     SCREAMING_SNAKE_CASE:Any						      =					{"input_ids": [[1, 39_867, 36, 19_390, 486, 27, 35_052, 81_436, 18, 60_685, 1_225, 7, 35_052, 81_436, 18, 9_367, 16_899, 18, 15_937, 53, 594, 773, 18, 16_287, 30_465, 36, 15_937, 6, 41_139, 38, 36_979, 60_763, 191, 6, 34_132, 99, 6, 50_538, 390, 43_230, 6, 34_132, 2_779, 20_850, 14, 699, 1_072, 1_194, 36, 382, 10_901, 53, 7, 699, 1_072, 2_084, 36, 20_422, 630, 53, 19, 105, 3_049, 1_896, 1_053, 16_899, 1_506, 11, 37_978, 4_243, 7, 1_237, 31_869, 200, 16_566, 654, 6, 35_052, 81_436, 7, 55_630, 13_593, 4, 2], [1, 26, 15_011, 13, 667, 8, 1_053, 18, 23_611, 1_237, 72_356, 12_820, 34, 104_134, 1_209, 35, 13_313, 6_627, 21, 202, 347, 7, 164, 2_399, 11, 46, 4_485, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 5, 1_232, 2_864, 15_785, 14_951, 105, 5, 8_581, 1_250, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "token_type_ids": [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
     # fmt: on

     self.tokenizer_integration_test_util(
         expected_encoding=SCREAMING_SNAKE_CASE__     ,model_name="microsoft/deberta-v2-xlarge"     ,revision="ad6e42c1532ddf3a15c39246b63f5559d558b670"     ,)









'''simple docstring'''

import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        FlaubertForMultipleChoice,
        FlaubertForQuestionAnswering,
        FlaubertForQuestionAnsweringSimple,
        FlaubertForSequenceClassification,
        FlaubertForTokenClassification,
        FlaubertModel,
        FlaubertWithLMHeadModel,
    )
    from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST





class 							_snake_case (       _a						):
   def __init__( self			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Tuple=13     ,SCREAMING_SNAKE_CASE__			:      Optional[int]=7     ,SCREAMING_SNAKE_CASE__			:      List[Any]=True     ,SCREAMING_SNAKE_CASE__			:      List[Any]=True     ,SCREAMING_SNAKE_CASE__			:      str=True     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]=True     ,SCREAMING_SNAKE_CASE__			:      Any=True     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=False     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]=False     ,SCREAMING_SNAKE_CASE__			:      int=False     ,SCREAMING_SNAKE_CASE__			:      int=2     ,SCREAMING_SNAKE_CASE__			:      Any=99     ,SCREAMING_SNAKE_CASE__			:      Optional[int]=0     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=32     ,SCREAMING_SNAKE_CASE__			:      List[str]=5     ,SCREAMING_SNAKE_CASE__			:      Tuple=4     ,SCREAMING_SNAKE_CASE__			:      Tuple=0.1     ,SCREAMING_SNAKE_CASE__			:      str=0.1     ,SCREAMING_SNAKE_CASE__			:      Dict=512     ,SCREAMING_SNAKE_CASE__			:      Optional[int]=12     ,SCREAMING_SNAKE_CASE__			:      List[Any]=2     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=0.02     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]=3     ,SCREAMING_SNAKE_CASE__			:      Dict=4     ,SCREAMING_SNAKE_CASE__			:      Dict="last"     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=None     ,SCREAMING_SNAKE_CASE__			:      List[Any]=None     ,):
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					parent
     SCREAMING_SNAKE_CASE:Dict						      =					batch_size
     SCREAMING_SNAKE_CASE:int						      =					seq_length
     SCREAMING_SNAKE_CASE:Any						      =					is_training
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					use_input_lengths
     SCREAMING_SNAKE_CASE:List[Any]						      =					use_token_type_ids
     SCREAMING_SNAKE_CASE:Dict						      =					use_labels
     SCREAMING_SNAKE_CASE:Dict						      =					gelu_activation
     SCREAMING_SNAKE_CASE:Dict						      =					sinusoidal_embeddings
     SCREAMING_SNAKE_CASE:List[str]						      =					causal
     SCREAMING_SNAKE_CASE:List[Any]						      =					asm
     SCREAMING_SNAKE_CASE:List[str]						      =					n_langs
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					vocab_size
     SCREAMING_SNAKE_CASE:Optional[int]						      =					n_special
     SCREAMING_SNAKE_CASE:str						      =					hidden_size
     SCREAMING_SNAKE_CASE:Dict						      =					num_hidden_layers
     SCREAMING_SNAKE_CASE:Dict						      =					num_attention_heads
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					hidden_dropout_prob
     SCREAMING_SNAKE_CASE:Tuple						      =					attention_probs_dropout_prob
     SCREAMING_SNAKE_CASE:Tuple						      =					max_position_embeddings
     SCREAMING_SNAKE_CASE:List[str]						      =					type_vocab_size
     SCREAMING_SNAKE_CASE:int						      =					type_sequence_label_size
     SCREAMING_SNAKE_CASE:Any						      =					initializer_range
     SCREAMING_SNAKE_CASE:str						      =					num_labels
     SCREAMING_SNAKE_CASE:Dict						      =					num_choices
     SCREAMING_SNAKE_CASE:Any						      =					summary_type
     SCREAMING_SNAKE_CASE:int						      =					use_proj
     SCREAMING_SNAKE_CASE:int						      =					scope
   def     __UpperCamelCase						( self			:      Optional[int]							):
     SCREAMING_SNAKE_CASE:int						      =					ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size							)
     SCREAMING_SNAKE_CASE:str						      =					random_attention_mask([self.batch_size, self.seq_length]							)

     SCREAMING_SNAKE_CASE:Tuple						      =					None
     if self.use_input_lengths:
       SCREAMING_SNAKE_CASE:List[Any]						      =					(
           ids_tensor([self.batch_size]     ,vocab_size=2							) + self.seq_length - 2
       )  # small variation of seq_length

     SCREAMING_SNAKE_CASE:Any						      =					None
     if self.use_token_type_ids:
       SCREAMING_SNAKE_CASE:Optional[int]						      =					ids_tensor([self.batch_size, self.seq_length]     ,self.n_langs							)

     SCREAMING_SNAKE_CASE:Dict						      =					None
     SCREAMING_SNAKE_CASE:List[Any]						      =					None
     SCREAMING_SNAKE_CASE:List[Any]						      =					None
     if self.use_labels:
       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					ids_tensor([self.batch_size]     ,self.type_sequence_label_size							)
       SCREAMING_SNAKE_CASE:str						      =					ids_tensor([self.batch_size, self.seq_length]     ,self.num_labels							)
       SCREAMING_SNAKE_CASE:int						      =					ids_tensor([self.batch_size]     ,2							).float()
       SCREAMING_SNAKE_CASE:Optional[Any]						      =					ids_tensor([self.batch_size]     ,self.num_choices							)

     SCREAMING_SNAKE_CASE:List[Any]						      =					self.get_config()

     return (
         config,
         input_ids,
         token_type_ids,
         input_lengths,
         sequence_labels,
         token_labels,
         is_impossible_labels,
         choice_labels,
         input_mask,
     )
   def     __UpperCamelCase						( self			:      Optional[int]							):
     return FlaubertConfig(
         vocab_size=self.vocab_size     ,n_special=self.n_special     ,emb_dim=self.hidden_size     ,n_layers=self.num_hidden_layers     ,n_heads=self.num_attention_heads     ,dropout=self.hidden_dropout_prob     ,attention_dropout=self.attention_probs_dropout_prob     ,gelu_activation=self.gelu_activation     ,sinusoidal_embeddings=self.sinusoidal_embeddings     ,asm=self.asm     ,causal=self.causal     ,n_langs=self.n_langs     ,max_position_embeddings=self.max_position_embeddings     ,initializer_range=self.initializer_range     ,summary_type=self.summary_type     ,use_proj=self.use_proj     ,)
   def     __UpperCamelCase						( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Dict     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,):
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					FlaubertModel(config=SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()
     SCREAMING_SNAKE_CASE:Any						      =					model(SCREAMING_SNAKE_CASE__     ,lengths=SCREAMING_SNAKE_CASE__     ,langs=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Any						      =					model(SCREAMING_SNAKE_CASE__     ,langs=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[int]						      =					model(SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.last_hidden_state.shape     ,(self.batch_size, self.seq_length, self.hidden_size)							)
   def     __UpperCamelCase						( self			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      str     ,):
     SCREAMING_SNAKE_CASE:Optional[int]						      =					FlaubertWithLMHeadModel(SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()

     SCREAMING_SNAKE_CASE:Optional[int]						      =					model(SCREAMING_SNAKE_CASE__     ,token_type_ids=SCREAMING_SNAKE_CASE__     ,labels=SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.loss.shape     ,()							)
     self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.seq_length, self.vocab_size)							)
   def     __UpperCamelCase						( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,):
     SCREAMING_SNAKE_CASE:Optional[int]						      =					FlaubertForQuestionAnsweringSimple(SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()

     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					model(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Dict						      =					model(SCREAMING_SNAKE_CASE__     ,start_positions=SCREAMING_SNAKE_CASE__     ,end_positions=SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.start_logits.shape     ,(self.batch_size, self.seq_length)							)
     self.parent.assertEqual(result.end_logits.shape     ,(self.batch_size, self.seq_length)							)
   def     __UpperCamelCase						( self			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,):
     SCREAMING_SNAKE_CASE:str						      =					FlaubertForQuestionAnswering(SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()

     SCREAMING_SNAKE_CASE:List[Any]						      =					model(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[Any]						      =					model(
         SCREAMING_SNAKE_CASE__     ,start_positions=SCREAMING_SNAKE_CASE__     ,end_positions=SCREAMING_SNAKE_CASE__     ,cls_index=SCREAMING_SNAKE_CASE__     ,is_impossible=SCREAMING_SNAKE_CASE__     ,p_mask=SCREAMING_SNAKE_CASE__     ,)

     SCREAMING_SNAKE_CASE:str						      =					model(
         SCREAMING_SNAKE_CASE__     ,start_positions=SCREAMING_SNAKE_CASE__     ,end_positions=SCREAMING_SNAKE_CASE__     ,cls_index=SCREAMING_SNAKE_CASE__     ,is_impossible=SCREAMING_SNAKE_CASE__     ,)

     ((SCREAMING_SNAKE_CASE)      ,    ):List[Any]						      =					result_with_labels.to_tuple()

     SCREAMING_SNAKE_CASE:Optional[int]						      =					model(SCREAMING_SNAKE_CASE__     ,start_positions=SCREAMING_SNAKE_CASE__     ,end_positions=SCREAMING_SNAKE_CASE__							)

     ((SCREAMING_SNAKE_CASE)      ,    ):List[Any]						      =					result_with_labels.to_tuple()

     self.parent.assertEqual(result_with_labels.loss.shape     ,()							)
     self.parent.assertEqual(result.start_top_log_probs.shape     ,(self.batch_size, model.config.start_n_top)							)
     self.parent.assertEqual(result.start_top_index.shape     ,(self.batch_size, model.config.start_n_top)							)
     self.parent.assertEqual(
         result.end_top_log_probs.shape     ,(self.batch_size, model.config.start_n_top * model.config.end_n_top)							)
     self.parent.assertEqual(
         result.end_top_index.shape     ,(self.batch_size, model.config.start_n_top * model.config.end_n_top)							)
     self.parent.assertEqual(result.cls_logits.shape     ,(self.batch_size,)							)
   def     __UpperCamelCase						( self			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      Dict     ,):
     SCREAMING_SNAKE_CASE:List[Any]						      =					FlaubertForSequenceClassification(SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()

     SCREAMING_SNAKE_CASE:Tuple						      =					model(SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					model(SCREAMING_SNAKE_CASE__     ,labels=SCREAMING_SNAKE_CASE__							)

     self.parent.assertEqual(result.loss.shape     ,()							)
     self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.type_sequence_label_size)							)
   def     __UpperCamelCase						( self			:      int     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Any     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,):
     SCREAMING_SNAKE_CASE:List[str]						      =					self.num_labels
     SCREAMING_SNAKE_CASE:Optional[int]						      =					FlaubertForTokenClassification(SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()

     SCREAMING_SNAKE_CASE:Optional[Any]						      =					model(SCREAMING_SNAKE_CASE__     ,attention_mask=SCREAMING_SNAKE_CASE__     ,labels=SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.seq_length, self.num_labels)							)
   def     __UpperCamelCase						( self			:      Any     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      List[Any]     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      List[str]     ,):
     SCREAMING_SNAKE_CASE:List[str]						      =					self.num_choices
     SCREAMING_SNAKE_CASE:Any						      =					FlaubertForMultipleChoice(config=SCREAMING_SNAKE_CASE__							)
     model.to(SCREAMING_SNAKE_CASE__							)
     model.eval()
     SCREAMING_SNAKE_CASE:str						      =					input_ids.unsqueeze(1							).expand(-1     ,self.num_choices     ,-1							).contiguous()
     SCREAMING_SNAKE_CASE:Dict						      =					token_type_ids.unsqueeze(1							).expand(-1     ,self.num_choices     ,-1							).contiguous()
     SCREAMING_SNAKE_CASE:List[Any]						      =					input_mask.unsqueeze(1							).expand(-1     ,self.num_choices     ,-1							).contiguous()
     SCREAMING_SNAKE_CASE:int						      =					model(
         SCREAMING_SNAKE_CASE__     ,attention_mask=SCREAMING_SNAKE_CASE__     ,token_type_ids=SCREAMING_SNAKE_CASE__     ,labels=SCREAMING_SNAKE_CASE__     ,)
     self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.num_choices)							)







   def     __UpperCamelCase						( self			:      Any							):
     SCREAMING_SNAKE_CASE:str						      =					self.prepare_config_and_inputs()
     (
         (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    (
         SCREAMING_SNAKE_CASE
     )      ,    
     ):Tuple						      =					config_and_inputs
     SCREAMING_SNAKE_CASE:Tuple						      =					{
         "input_ids": input_ids,
         "token_type_ids": token_type_ids,
         "lengths": input_lengths,
         "attention_mask": input_mask,
     }
     return config, inputs_dict





@require_torch
class 							_snake_case (       _a	,  _a	,  unittest.TestCase						):
   _A       :     int       =					(
       (
           FlaubertModel,
           FlaubertWithLMHeadModel,
           FlaubertForQuestionAnswering,
           FlaubertForQuestionAnsweringSimple,
           FlaubertForSequenceClassification,
           FlaubertForTokenClassification,
           FlaubertForMultipleChoice,
       )
       if is_torch_available()
       else ()
   )
   _A       :     Optional[Any]       =					(
       {
           '''feature-extraction''': FlaubertModel,
           '''fill-mask''': FlaubertWithLMHeadModel,
           '''question-answering''': FlaubertForQuestionAnsweringSimple,
           '''text-classification''': FlaubertForSequenceClassification,
           '''token-classification''': FlaubertForTokenClassification,
           '''zero-shot''': FlaubertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   def     __UpperCamelCase						( self			:      str     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Tuple     ,SCREAMING_SNAKE_CASE__			:      str     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]							):
     if (
         pipeline_test_casse_name == "QAPipelineTests"
         and tokenizer_name is not None
         and not tokenizer_name.endswith("Fast"							)
     ):
       # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
       # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
       # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
       return True

     return False
   def     __UpperCamelCase						( self			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      Optional[int]     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]     ,SCREAMING_SNAKE_CASE__			:      int=False							):
     SCREAMING_SNAKE_CASE:Any						      =					super()._prepare_for_class(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__     ,return_labels=SCREAMING_SNAKE_CASE__							)

     if return_labels:
       if model_class.__name__ == "FlaubertForQuestionAnswering":
         SCREAMING_SNAKE_CASE:Dict						      =					torch.zeros(
             self.model_tester.batch_size     ,dtype=torch.long     ,device=SCREAMING_SNAKE_CASE__							)
         SCREAMING_SNAKE_CASE:int						      =					torch.zeros(
             self.model_tester.batch_size     ,dtype=torch.long     ,device=SCREAMING_SNAKE_CASE__							)

     return inputs_dict
   def     __UpperCamelCase						( self			:      Optional[int]							):
     SCREAMING_SNAKE_CASE:int						      =					FlaubertModelTester(self							)
     SCREAMING_SNAKE_CASE:Dict						      =					ConfigTester(self     ,config_class=SCREAMING_SNAKE_CASE__     ,emb_dim=37							)
   def     __UpperCamelCase						( self			:      Any							):
     self.config_tester.run_common_tests()
   def     __UpperCamelCase						( self			:      Any							):
     SCREAMING_SNAKE_CASE:Any						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_model(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Optional[int]							):
     SCREAMING_SNAKE_CASE:Dict						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_lm_head(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      str							):
     SCREAMING_SNAKE_CASE:str						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_simple_qa(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Any							):
     SCREAMING_SNAKE_CASE:Dict						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_qa(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      Optional[Any]							):
     SCREAMING_SNAKE_CASE:Dict						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_sequence_classif(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      List[Any]							):
     SCREAMING_SNAKE_CASE:Optional[Any]						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_token_classif(*SCREAMING_SNAKE_CASE__							)
   def     __UpperCamelCase						( self			:      int							):
     SCREAMING_SNAKE_CASE:List[Any]						      =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_flaubert_multiple_choice(*SCREAMING_SNAKE_CASE__							)
   @slow
   def     __UpperCamelCase						( self			:      List[str]							):
     for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       SCREAMING_SNAKE_CASE:Tuple						      =					FlaubertModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
       self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)







   @slow
   @require_torch_gpu
   def     __UpperCamelCase						( self			:      str							):
     SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:int						      =					self.model_tester.prepare_config_and_inputs_for_common()
     for model_class in self.all_model_classes:
       # FlauBertForMultipleChoice behaves incorrectly in JIT environments.
       if model_class == FlaubertForMultipleChoice:
         return

       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					True
       SCREAMING_SNAKE_CASE:Optional[int]						      =					model_class(config=SCREAMING_SNAKE_CASE__							)

       SCREAMING_SNAKE_CASE:Any						      =					self._prepare_for_class(SCREAMING_SNAKE_CASE__     ,SCREAMING_SNAKE_CASE__							)
       SCREAMING_SNAKE_CASE:Any						      =					torch.jit.trace(
           SCREAMING_SNAKE_CASE__     ,(inputs_dict["input_ids"].to("cpu"							), inputs_dict["attention_mask"].to("cpu"							))							)

       with tempfile.TemporaryDirectory() as tmp:
         torch.jit.save(SCREAMING_SNAKE_CASE__     ,os.path.join(SCREAMING_SNAKE_CASE__     ,"traced_model.pt"							)							)
         SCREAMING_SNAKE_CASE:Optional[Any]						      =					torch.jit.load(os.path.join(SCREAMING_SNAKE_CASE__     ,"traced_model.pt"							)     ,map_location=SCREAMING_SNAKE_CASE__							)
         loaded(inputs_dict["input_ids"].to(SCREAMING_SNAKE_CASE__							)     ,inputs_dict["attention_mask"].to(SCREAMING_SNAKE_CASE__							)							)





@require_torch
class 							_snake_case (       unittest.TestCase						):
   @slow
   def     __UpperCamelCase						( self			:      List[str]							):
     SCREAMING_SNAKE_CASE:Optional[int]						      =					FlaubertModel.from_pretrained("flaubert/flaubert_base_cased"							)
     SCREAMING_SNAKE_CASE:Optional[int]						      =					torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]							)
     with torch.no_grad():
       SCREAMING_SNAKE_CASE:Union[str, Any]						      =					model(SCREAMING_SNAKE_CASE__							)[0]
     SCREAMING_SNAKE_CASE:Union[str, Any]						      =					torch.Size((1, 11, 768)							)
     self.assertEqual(output.shape     ,SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:int						      =					torch.tensor(
         [[[-2.6_251, -1.4_298, -0.0_227], [-2.8_510, -1.6_387, 0.2_258], [-2.8_114, -1.1_832, -0.3_066]]]							)

     self.assertTrue(torch.allclose(output[:, :3, :3]     ,SCREAMING_SNAKE_CASE__     ,atol=1e-4							)							)






