


"""simple docstring"""







import inspect
import unittest

from transformers import YolosConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch
     from torch import nn

     from transformers import YolosForObjectDetection, YolosModel
     from transformers.models.yolos.modeling_yolos import YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
     from PIL import Image

     from transformers import AutoImageProcessor


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self		,     snake_case__		,     snake_case__=13		,     snake_case__=[30, 30]		,     snake_case__=2		,     snake_case__=3		,     snake_case__=True		,     snake_case__=True		,     snake_case__=32		,     snake_case__=5		,     snake_case__=4		,     snake_case__=37		,     snake_case__="gelu"		,     snake_case__=0.1		,     snake_case__=0.1		,     snake_case__=10		,     snake_case__=0.02		,     snake_case__=3		,     snake_case__=None		,     snake_case__=8		,     snake_case__=10		,     ):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							parent
         lowerCAmelCase     :     List[str]								=							batch_size
         lowerCAmelCase     :     Any								=							image_size
         lowerCAmelCase     :     Dict								=							patch_size
         lowerCAmelCase     :     Union[str, Any]								=							num_channels
         lowerCAmelCase     :     List[str]								=							is_training
         lowerCAmelCase     :     Union[str, Any]								=							use_labels
         lowerCAmelCase     :     List[str]								=							hidden_size
         lowerCAmelCase     :     Tuple								=							num_hidden_layers
         lowerCAmelCase     :     Tuple								=							num_attention_heads
         lowerCAmelCase     :     Optional[int]								=							intermediate_size
         lowerCAmelCase     :     Tuple								=							hidden_act
         lowerCAmelCase     :     Dict								=							hidden_dropout_prob
         lowerCAmelCase     :     Optional[int]								=							attention_probs_dropout_prob
         lowerCAmelCase     :     List[str]								=							type_sequence_label_size
         lowerCAmelCase     :     Optional[Any]								=							initializer_range
         lowerCAmelCase     :     List[str]								=							num_labels
         lowerCAmelCase     :     Optional[int]								=							scope
         lowerCAmelCase     :     Tuple								=							n_targets
         lowerCAmelCase     :     Dict								=							num_detection_tokens
         # we set the expected sequence length (which is used in several tests)
         # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token) + num_detection_tokens
         lowerCAmelCase     :     Optional[int]								=							(image_size[1] // patch_size) * (image_size[0] // patch_size)
         lowerCAmelCase     :     int								=							num_patches + 1 + self.num_detection_tokens

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]]						)

         lowerCAmelCase     :     Tuple								=							None
         if self.use_labels:
           # labels is a list of Dict (each Dict being the labels for a given example in the batch)
           lowerCAmelCase     :     Dict								=							[]
           for i in range(self.batch_size						):
             lowerCAmelCase     :     Optional[int]								=							{}
             lowerCAmelCase     :     Optional[Any]								=							torch.randint(
                 high=self.num_labels		,     size=(self.n_targets,)		,     device=snake_case__						)
             lowerCAmelCase     :     Any								=							torch.rand(self.n_targets		,     4		,     device=snake_case__						)
             labels.append(snake_case__						)

         lowerCAmelCase     :     Union[str, Any]								=							self.get_config()

         return config, pixel_values, labels

       def        lowercase__							(						self						):






         """simple docstring"""





         return YolosConfig(
             image_size=self.image_size		,     patch_size=self.patch_size		,     num_channels=self.num_channels		,     hidden_size=self.hidden_size		,     num_hidden_layers=self.num_hidden_layers		,     num_attention_heads=self.num_attention_heads		,     intermediate_size=self.intermediate_size		,     hidden_act=self.hidden_act		,     hidden_dropout_prob=self.hidden_dropout_prob		,     attention_probs_dropout_prob=self.attention_probs_dropout_prob		,     is_decoder=snake_case__		,     initializer_range=self.initializer_range		,     num_detection_tokens=self.num_detection_tokens		,     num_labels=self.num_labels		,     )

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     str								=							YolosModel(config=snake_case__						)
         model.to(snake_case__						)
         model.eval()
         lowerCAmelCase     :     Optional[int]								=							model(snake_case__						)
         self.parent.assertEqual(
             result.last_hidden_state.shape		,     (self.batch_size, self.expected_seq_len, self.hidden_size)						)

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							YolosForObjectDetection(snake_case__						)
         model.to(snake_case__						)
         model.eval()

         lowerCAmelCase     :     List[Any]								=							model(pixel_values=snake_case__						)
         lowerCAmelCase     :     Dict								=							model(snake_case__						)

         self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_detection_tokens, self.num_labels + 1)						)
         self.parent.assertEqual(result.pred_boxes.shape		,     (self.batch_size, self.num_detection_tokens, 4)						)

         lowerCAmelCase     :     Optional[int]								=							model(pixel_values=snake_case__		,     labels=snake_case__						)

         self.parent.assertEqual(result.loss.shape		,     ()						)
         self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_detection_tokens, self.num_labels + 1)						)
         self.parent.assertEqual(result.pred_boxes.shape		,     (self.batch_size, self.num_detection_tokens, 4)						)







       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							self.prepare_config_and_inputs()
         lowerCAmelCase						,  lowerCAmelCase						,  lowerCAmelCase     :     List[Any]								=							config_and_inputs
         lowerCAmelCase     :     Union[str, Any]								=							{"pixel_values": pixel_values}
         return config, inputs_dict


@require_torch
class       SCREAMING_SNAKE_CASE__				(		lowercase   ,    lowercase   ,    unittest.TestCase				):
       """simple docstring"""


       a  :				Optional[int]   =(YolosModel, YolosForObjectDetection) if is_torch_available() else ()
       a  :				Dict   =(
           {"feature-extraction": YolosModel, "object-detection": YolosForObjectDetection} if is_torch_available() else {}
       )

       a  :				Dict   =False
       a  :				Optional[Any]   =False
       a  :				str   =False
       a  :				List[str]   =False

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__=False						):






         """simple docstring"""





         lowerCAmelCase     :     List[Any]								=							super()._prepare_for_class(snake_case__		,     snake_case__		,     return_labels=snake_case__						)

         if return_labels:
           if model_class.__name__ == "YolosForObjectDetection":
             lowerCAmelCase     :     Optional[int]								=							[]
             for i in range(self.model_tester.batch_size						):
               lowerCAmelCase     :     Union[str, Any]								=							{}
               lowerCAmelCase     :     List[Any]								=							torch.ones(
                   size=(self.model_tester.n_targets,)		,     device=snake_case__		,     dtype=torch.long						)
               lowerCAmelCase     :     List[str]								=							torch.ones(
                   self.model_tester.n_targets		,     4		,     device=snake_case__		,     dtype=torch.float						)
               labels.append(snake_case__						)
             lowerCAmelCase     :     Optional[int]								=							labels

         return inputs_dict

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							YolosModelTester(self						)
         lowerCAmelCase     :     Optional[int]								=							ConfigTester(self		,     config_class=snake_case__		,     has_text_modality=snake_case__		,     hidden_size=37						)

       def        lowercase__							(						self						):






         """simple docstring"""





         self.config_tester.run_common_tests()

       def        lowercase__							(						self						):






         """simple docstring"""





         pass

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase						,  lowerCAmelCase     :     Tuple								=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase     :     int								=							model_class(snake_case__						)
           self.assertIsInstance(model.get_input_embeddings()		,     (nn.Module)						)
           lowerCAmelCase     :     Dict								=							model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(snake_case__		,     nn.Linear						)						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase						,  lowerCAmelCase     :     int								=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase     :     List[Any]								=							model_class(snake_case__						)
           lowerCAmelCase     :     str								=							inspect.signature(model.forward						)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           lowerCAmelCase     :     Tuple								=							[*signature.parameters.keys()]

           lowerCAmelCase     :     int								=							["pixel_values"]
           self.assertListEqual(arg_names[:1]		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase						,  lowerCAmelCase     :     str								=							self.model_tester.prepare_config_and_inputs_for_common()
         lowerCAmelCase     :     Union[str, Any]								=							True

         # in YOLOS, the seq_len is different
         lowerCAmelCase     :     str								=							self.model_tester.expected_seq_len
         for model_class in self.all_model_classes:
           lowerCAmelCase     :     int								=							True
           lowerCAmelCase     :     List[str]								=							False
           lowerCAmelCase     :     Optional[Any]								=							True
           lowerCAmelCase     :     List[str]								=							model_class(snake_case__						)
           model.to(snake_case__						)
           model.eval()
           with torch.no_grad():
             lowerCAmelCase     :     Union[str, Any]								=							model(**self._prepare_for_class(snake_case__		,     snake_case__						)						)
           lowerCAmelCase     :     List[str]								=							outputs.attentions
           self.assertEqual(len(snake_case__						)		,     self.model_tester.num_hidden_layers						)

           # check that output_attentions also work using config
           del inputs_dict["output_attentions"]
           lowerCAmelCase     :     int								=							True
           lowerCAmelCase     :     Optional[int]								=							model_class(snake_case__						)
           model.to(snake_case__						)
           model.eval()
           with torch.no_grad():
             lowerCAmelCase     :     Union[str, Any]								=							model(**self._prepare_for_class(snake_case__		,     snake_case__						)						)
           lowerCAmelCase     :     Optional[Any]								=							outputs.attentions
           self.assertEqual(len(snake_case__						)		,     self.model_tester.num_hidden_layers						)

           self.assertListEqual(
               list(attentions[0].shape[-3:]						)		,     [self.model_tester.num_attention_heads, seq_len, seq_len]		,     )
           lowerCAmelCase     :     Tuple								=							len(snake_case__						)

           # Check attention is always last and order is fine
           lowerCAmelCase     :     Union[str, Any]								=							True
           lowerCAmelCase     :     List[Any]								=							True
           lowerCAmelCase     :     Union[str, Any]								=							model_class(snake_case__						)
           model.to(snake_case__						)
           model.eval()
           with torch.no_grad():
             lowerCAmelCase     :     Union[str, Any]								=							model(**self._prepare_for_class(snake_case__		,     snake_case__						)						)

           lowerCAmelCase     :     Optional[int]								=							1
           self.assertEqual(out_len + added_hidden_states		,     len(snake_case__						)						)

           lowerCAmelCase     :     Any								=							outputs.attentions

           self.assertEqual(len(snake_case__						)		,     self.model_tester.num_hidden_layers						)
           self.assertListEqual(
               list(self_attentions[0].shape[-3:]						)		,     [self.model_tester.num_attention_heads, seq_len, seq_len]		,     )

       def        lowercase__							(						self						):






         """simple docstring"""





         def check_hidden_states_output(snake_case__		,     snake_case__		,     snake_case__						):
           lowerCAmelCase     :     List[str]								=							model_class(snake_case__						)
           model.to(snake_case__						)
           model.eval()

           with torch.no_grad():
             lowerCAmelCase     :     Optional[int]								=							model(**self._prepare_for_class(snake_case__		,     snake_case__						)						)

           lowerCAmelCase     :     Tuple								=							outputs.hidden_states

           lowerCAmelCase     :     Dict								=							getattr(
               self.model_tester		,     "expected_num_hidden_layers"		,     self.model_tester.num_hidden_layers + 1						)
           self.assertEqual(len(snake_case__						)		,     snake_case__						)

           # YOLOS has a different seq_length
           lowerCAmelCase     :     List[str]								=							self.model_tester.expected_seq_len

           self.assertListEqual(
               list(hidden_states[0].shape[-2:]						)		,     [seq_length, self.model_tester.hidden_size]		,     )

         lowerCAmelCase						,  lowerCAmelCase     :     Optional[int]								=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase     :     str								=							True
           check_hidden_states_output(snake_case__		,     snake_case__		,     snake_case__						)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           lowerCAmelCase     :     str								=							True

           check_hidden_states_output(snake_case__		,     snake_case__		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Optional[int]								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_object_detection(*snake_case__						)







       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         for model_name in YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowerCAmelCase     :     str								=							YolosModel.from_pretrained(snake_case__						)
           self.assertIsNotNone(snake_case__						)

def 					a__			(				):


  '''simple docstring'''







  lowerCAmelCase     :     List[Any]								=							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
  return image





@require_torch
@require_vision
class       SCREAMING_SNAKE_CASE__				(		unittest.TestCase				):
       """simple docstring"""


       @cached_property
       def        lowercase__							(						self						):






         """simple docstring"""





         return AutoImageProcessor.from_pretrained("hustvl/yolos-small"						) if is_vision_available() else None







       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[str]								=							YolosForObjectDetection.from_pretrained("hustvl/yolos-small"						).to(snake_case__						)

         lowerCAmelCase     :     Dict								=							self.default_image_processor
         lowerCAmelCase     :     Any								=							prepare_img()
         lowerCAmelCase     :     Optional[Any]								=							image_processor(images=snake_case__		,     return_tensors="pt"						).to(snake_case__						)

         # forward pass
         with torch.no_grad():
           lowerCAmelCase     :     Dict								=							model(inputs.pixel_values						)

         # verify outputs
         lowerCAmelCase     :     Dict								=							torch.Size((1, 100, 92)						)
         self.assertEqual(outputs.logits.shape		,     snake_case__						)

         lowerCAmelCase     :     Optional[int]								=							torch.tensor(
             [[-24.0248, -10.3024, -14.8290], [-42.0392, -16.8200, -27.4334], [-27.2743, -11.8154, -18.7148]]		,     device=snake_case__		,     )
         lowerCAmelCase     :     Dict								=							torch.tensor(
             [[0.2559, 0.5455, 0.4706], [0.2989, 0.7279, 0.1875], [0.7732, 0.4017, 0.4462]]		,     device=snake_case__						)
         self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]		,     snake_case__		,     atol=1e-4						)						)
         self.assertTrue(torch.allclose(outputs.pred_boxes[0, :3, :3]		,     snake_case__		,     atol=1e-4						)						)

         # verify postprocessing
         lowerCAmelCase     :     List[str]								=							image_processor.post_process_object_detection(
             snake_case__		,     threshold=0.3		,     target_sizes=[image.size[::-1]]						)[0]
         lowerCAmelCase     :     Optional[Any]								=							torch.tensor([0.9994, 0.9790, 0.9964, 0.9972, 0.9861]						).to(snake_case__						)
         lowerCAmelCase     :     Dict								=							[75, 75, 17, 63, 17]
         lowerCAmelCase     :     str								=							torch.tensor([335.0609, 79.3848, 375.4216, 187.2495]						).to(snake_case__						)

         self.assertEqual(len(results["scores"]						)		,     5						)
         self.assertTrue(torch.allclose(results["scores"]		,     snake_case__		,     atol=1e-4						)						)
         self.assertSequenceEqual(results["labels"].tolist()		,     snake_case__						)
         self.assertTrue(torch.allclose(results["boxes"][0, :]		,     snake_case__						)						)









"""simple docstring"""







import unittest

from transformers import BigBirdTokenizer, BigBirdTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase__      				=   '''▁'''

lowerCAmelCase__      				=   get_tests_dir('''fixtures/test_sentencepiece.model''')


@require_sentencepiece
@require_tokenizers
class       SCREAMING_SNAKE_CASE__				(		lowercase   ,    unittest.TestCase				):
       """simple docstring"""


       a  :				str   =BigBirdTokenizer
       a  :				Union[str, Any]   =BigBirdTokenizerFast
       a  :				Tuple   =True
       a  :				Any   =True

       def        lowercase__							(						self						):






         """simple docstring"""





         super().setUp()

         lowerCAmelCase     :     str								=							self.tokenizer_class(snake_case__		,     keep_accents=snake_case__						)
         tokenizer.save_pretrained(self.tmpdirname						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     str								=							"<s>"
         lowerCAmelCase     :     Optional[int]								=							1

         self.assertEqual(self.get_tokenizer()._convert_token_to_id(snake_case__						)		,     snake_case__						)
         self.assertEqual(self.get_tokenizer()._convert_id_to_token(snake_case__						)		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Dict								=							list(self.get_tokenizer().get_vocab().keys()						)

         self.assertEqual(vocab_keys[0]		,     "<unk>"						)
         self.assertEqual(vocab_keys[1]		,     "<s>"						)
         self.assertEqual(vocab_keys[-1]		,     "[MASK]"						)
         self.assertEqual(len(snake_case__						)		,     1_004						)

       def        lowercase__							(						self						):






         """simple docstring"""





         self.assertEqual(self.get_tokenizer().vocab_size		,     1_000						)

       def        lowercase__							(						self						):






         """simple docstring"""





         if not self.test_rust_tokenizer:
           return

         lowerCAmelCase     :     Tuple								=							self.get_tokenizer()
         lowerCAmelCase     :     Optional[int]								=							self.get_rust_tokenizer()

         lowerCAmelCase     :     Tuple								=							"I was born in 92000, and this is falsé."

         lowerCAmelCase     :     Optional[int]								=							tokenizer.tokenize(snake_case__						)
         lowerCAmelCase     :     int								=							rust_tokenizer.tokenize(snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

         lowerCAmelCase     :     Tuple								=							tokenizer.encode(snake_case__		,     add_special_tokens=snake_case__						)
         lowerCAmelCase     :     int								=							rust_tokenizer.encode(snake_case__		,     add_special_tokens=snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

         lowerCAmelCase     :     List[Any]								=							self.get_rust_tokenizer()
         lowerCAmelCase     :     Tuple								=							tokenizer.encode(snake_case__						)
         lowerCAmelCase     :     List[Any]								=							rust_tokenizer.encode(snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							BigBirdTokenizer(snake_case__		,     keep_accents=snake_case__						)

         lowerCAmelCase     :     Union[str, Any]								=							tokenizer.tokenize("This is a test"						)
         self.assertListEqual(snake_case__		,     ["▁This", "▁is", "▁a", "▁t", "est"]						)

         self.assertListEqual(
             tokenizer.convert_tokens_to_ids(snake_case__						)		,     [285, 46, 10, 170, 382]		,     )

         lowerCAmelCase     :     Any								=							tokenizer.tokenize("I was born in 92000, and this is falsé."						)
         self.assertListEqual(
             snake_case__		,     [
                 SPIECE_UNDERLINE + "I",
                 SPIECE_UNDERLINE + "was",
                 SPIECE_UNDERLINE + "b",
                 "or",
                 "n",
                 SPIECE_UNDERLINE + "in",
                 SPIECE_UNDERLINE + "",
                 "9",
                 "2",
                 "0",
                 "0",
                 "0",
                 ",",
                 SPIECE_UNDERLINE + "and",
                 SPIECE_UNDERLINE + "this",
                 SPIECE_UNDERLINE + "is",
                 SPIECE_UNDERLINE + "f",
                 "al",
                 "s",
                 "é",
                 ".",
             ]		,     )
         lowerCAmelCase     :     str								=							tokenizer.convert_tokens_to_ids(snake_case__						)
         self.assertListEqual(
             snake_case__		,     [8, 21, 84, 55, 24, 19, 7, 0, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 0, 4]		,     )

         lowerCAmelCase     :     List[str]								=							tokenizer.convert_ids_to_tokens(snake_case__						)
         self.assertListEqual(
             snake_case__		,     [
                 SPIECE_UNDERLINE + "I",
                 SPIECE_UNDERLINE + "was",
                 SPIECE_UNDERLINE + "b",
                 "or",
                 "n",
                 SPIECE_UNDERLINE + "in",
                 SPIECE_UNDERLINE + "",
                 "<unk>",
                 "2",
                 "0",
                 "0",
                 "0",
                 ",",
                 SPIECE_UNDERLINE + "and",
                 SPIECE_UNDERLINE + "this",
                 SPIECE_UNDERLINE + "is",
                 SPIECE_UNDERLINE + "f",
                 "al",
                 "s",
                 "<unk>",
                 ".",
             ]		,     )

       @cached_property
       def        lowercase__							(						self						):






         """simple docstring"""





         return BigBirdTokenizer.from_pretrained("google/bigbird-roberta-base"						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[Any]								=							"Hello World!"
         lowerCAmelCase     :     Any								=							[65, 18_536, 2_260, 101, 66]

         self.assertListEqual(snake_case__		,     self.big_tokenizer.encode(snake_case__						)						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							(
             "This is a very long text with a lot of weird characters, such as: . , ~ ? ( ) \" [ ] ! : - . Also we will"
             " add words that should not exsist and be tokenized to <unk>, such as saoneuhaoesuth"
         )
         # fmt: off
         lowerCAmelCase     :     List[str]								=							[65, 871, 419, 358, 946, 991, 2_521, 452, 358, 1_357, 387, 7_751, 3_536, 112, 985, 456, 126, 865, 938, 5_400, 5_734, 458, 1_368, 467, 786, 2_462, 5_246, 1_159, 633, 865, 4_519, 457, 582, 852, 2_557, 427, 916, 508, 405, 34_324, 497, 391, 408, 11_342, 1_244, 385, 100, 938, 985, 456, 574, 362, 12_597, 3_200, 3_129, 1_172, 66]  # noqa: E231
         # fmt: on
         self.assertListEqual(snake_case__		,     self.big_tokenizer.encode(snake_case__						)						)

       @require_torch
       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         import torch

         from transformers import BigBirdConfig, BigBirdModel

         # Build sequence
         lowerCAmelCase     :     Dict								=							list(self.big_tokenizer.get_vocab().keys()						)[:10]
         lowerCAmelCase     :     int								=							" ".join(snake_case__						)
         lowerCAmelCase     :     Dict								=							self.big_tokenizer.encode_plus(snake_case__		,     return_tensors="pt"		,     return_token_type_ids=snake_case__						)
         lowerCAmelCase     :     Any								=							self.big_tokenizer.batch_encode_plus(
             [sequence + " " + sequence]		,     return_tensors="pt"		,     return_token_type_ids=snake_case__						)

         lowerCAmelCase     :     str								=							BigBirdConfig(attention_type="original_full"						)
         lowerCAmelCase     :     Any								=							BigBirdModel(snake_case__						)

         assert model.get_input_embeddings().weight.shape[0] >= self.big_tokenizer.vocab_size

         with torch.no_grad():
           model(**snake_case__						)
           model(**snake_case__						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[str]								=							BigBirdTokenizer.from_pretrained("google/bigbird-roberta-base"						)
         lowerCAmelCase     :     Union[str, Any]								=							tokenizer.decode(tokenizer("Paris is the [MASK]."						).input_ids						)

         self.assertTrue(decoded_text == "[CLS] Paris is the[MASK].[SEP]"						)







       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							{"input_ids": [[65, 39_286, 458, 36_335, 2_001, 456, 13_073, 13_266, 455, 113, 7_746, 1_741, 11_157, 391, 13_073, 13_266, 455, 113, 3_967, 35_412, 113, 4_936, 109, 3_870, 2_377, 113, 30_084, 45_720, 458, 134, 17_496, 112, 503, 11_672, 113, 118, 112, 5_665, 13_347, 38_687, 112, 1_496, 31_389, 112, 3_268, 47_264, 134, 962, 112, 16_377, 8_035, 23_130, 430, 12_169, 15_518, 28_592, 458, 146, 41_697, 109, 391, 12_169, 15_518, 16_689, 458, 146, 41_358, 109, 452, 726, 4_034, 111, 763, 35_412, 5_082, 388, 1_903, 111, 9_051, 391, 2_870, 48_918, 1_900, 1_123, 550, 998, 112, 9_586, 15_985, 455, 391, 410, 22_955, 37_636, 114, 66], [65, 448, 17_496, 419, 3_663, 385, 763, 113, 27_533, 2_870, 3_283, 13_043, 1_639, 24_713, 523, 656, 24_013, 18_550, 2_521, 517, 27_014, 21_244, 420, 1_212, 1_465, 391, 927, 4_833, 388, 578, 11_786, 114, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [65, 484, 2_169, 7_687, 21_932, 18_146, 726, 363, 17_032, 3_391, 114, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
         # fmt: on

         self.tokenizer_integration_test_util(
             expected_encoding=snake_case__		,     model_name="google/bigbird-roberta-base"		,     revision="215c99f1600e06f83acce68422f2035b2b5c3510"		,     )





