

import collections
import inspect
import unittest

from transformers import SwinvaConfig
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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
 from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor
class        _lowercase					:







     def __init__(      self ,						UpperCamelCase_ ,						UpperCamelCase_=13 ,						UpperCamelCase_=32 ,						UpperCamelCase_=2 ,						UpperCamelCase_=3 ,						UpperCamelCase_=16 ,						UpperCamelCase_=[1, 2, 1] ,						UpperCamelCase_=[2, 2, 4] ,						UpperCamelCase_=2 ,						UpperCamelCase_=2.0 ,						UpperCamelCase_=True ,						UpperCamelCase_=0.0 ,						UpperCamelCase_=0.0 ,						UpperCamelCase_=0.1 ,						UpperCamelCase_="gelu" ,						UpperCamelCase_=False ,						UpperCamelCase_=True ,						UpperCamelCase_=0.0_2 ,						UpperCamelCase_=1E-5 ,						UpperCamelCase_=True ,						UpperCamelCase_=None ,						UpperCamelCase_=True ,						UpperCamelCase_=10 ,						UpperCamelCase_=8 ,						):
      __magic_name__     =      parent
      __magic_name__     =      batch_size
      __magic_name__     =      image_size
      __magic_name__     =      patch_size
      __magic_name__     =      num_channels
      __magic_name__     =      embed_dim
      __magic_name__     =      depths
      __magic_name__     =      num_heads
      __magic_name__     =      window_size
      __magic_name__     =      mlp_ratio
      __magic_name__     =      qkv_bias
      __magic_name__     =      hidden_dropout_prob
      __magic_name__     =      attention_probs_dropout_prob
      __magic_name__     =      drop_path_rate
      __magic_name__     =      hidden_act
      __magic_name__     =      use_absolute_embeddings
      __magic_name__     =      patch_norm
      __magic_name__     =      layer_norm_eps
      __magic_name__     =      initializer_range
      __magic_name__     =      is_training
      __magic_name__     =      scope
      __magic_name__     =      use_labels
      __magic_name__     =      type_sequence_label_size
      __magic_name__     =      encoder_stride







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

      __magic_name__     =      None
      if self.use_labels:
       __magic_name__     =      ids_tensor([self.batch_size] ,						self.type_sequence_label_size       )

      __magic_name__     =      self.get_config()

      return config, pixel_values, labels







     def 	lowerCAmelCase__    (      self       ):
      return SwinvaConfig(
          image_size=self.image_size ,						patch_size=self.patch_size ,						num_channels=self.num_channels ,						embed_dim=self.embed_dim ,						depths=self.depths ,						num_heads=self.num_heads ,						window_size=self.window_size ,						mlp_ratio=self.mlp_ratio ,						qkv_bias=self.qkv_bias ,						hidden_dropout_prob=self.hidden_dropout_prob ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob ,						drop_path_rate=self.drop_path_rate ,						hidden_act=self.hidden_act ,						use_absolute_embeddings=self.use_absolute_embeddings ,						path_norm=self.patch_norm ,						layer_norm_eps=self.layer_norm_eps ,						initializer_range=self.initializer_range ,						encoder_stride=self.encoder_stride ,						)







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      SwinvaModel(config=lowercase__       )
      model.to(lowercase__       )
      model.eval()
      __magic_name__     =      model(lowercase__       )

      __magic_name__     =      ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths       ) - 1))
      __magic_name__     =      int(config.embed_dim * 2 ** (len(config.depths       ) - 1)       )

      self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, expected_seq_len, expected_dim)       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      SwinvaForMaskedImageModeling(config=lowercase__       )
      model.to(lowercase__       )
      model.eval()
      __magic_name__     =      model(lowercase__       )
      self.parent.assertEqual(
          result.logits.shape ,						(self.batch_size, self.num_channels, self.image_size, self.image_size)       )

      # test greyscale images
      __magic_name__     =      1
      __magic_name__     =      SwinvaForMaskedImageModeling(lowercase__       )
      model.to(lowercase__       )
      model.eval()

      __magic_name__     =      floats_tensor([self.batch_size, 1, self.image_size, self.image_size]       )
      __magic_name__     =      model(lowercase__       )
      self.parent.assertEqual(result.logits.shape ,						(self.batch_size, 1, self.image_size, self.image_size)       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      self.type_sequence_label_size
      __magic_name__     =      SwinvaForImageClassification(lowercase__       )
      model.to(lowercase__       )
      model.eval()
      __magic_name__     =      model(lowercase__ ,						labels=lowercase__       )
      self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size)       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.prepare_config_and_inputs()
      __magic_name__     =      config_and_inputs
      __magic_name__     =      {"pixel_values": pixel_values}
      return config, inputs_dict


@require_torch
class        _lowercase					(     _UpperCAmelCase   , _UpperCAmelCase   , unittest.TestCase     ):
     _lowerCamelCase     =       (
         (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
     )
     _lowerCamelCase     =       (
         {'''feature-extraction''': SwinvaModel, '''image-classification''': SwinvaForImageClassification}
         if is_torch_available()
         else {}
     )

     _lowerCamelCase     =       False
     _lowerCamelCase     =       False
     _lowerCamelCase     =       False
     _lowerCamelCase     =       False







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      SwinvaModelTester(self       )
      __magic_name__     =      ConfigTester(self ,						config_class=lowercase__ ,						embed_dim=37       )







     def 	lowerCAmelCase__    (      self       ):
      self.config_tester.create_and_test_config_to_json_string()
      self.config_tester.create_and_test_config_to_json_file()
      self.config_tester.create_and_test_config_from_and_save_pretrained()
      self.config_tester.create_and_test_config_with_num_labels()
      self.config_tester.check_config_can_be_init_without_params()
      self.config_tester.check_config_arguments_init()







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowercase__       )







     @unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''       )
     def 	lowerCAmelCase__    (      self       ):
      pass







     @unittest.skip(reason='''Swinv2 does not use inputs_embeds'''       )
     def 	lowerCAmelCase__    (      self       ):
      pass







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()

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







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
       __magic_name__     =      model_class(lowercase__       )
       __magic_name__     =      inspect.signature(model.forward       )
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       __magic_name__     =      [*signature.parameters.keys()]

       __magic_name__     =      ["pixel_values"]
       self.assertListEqual(arg_names[:1] ,						lowercase__       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__     =      True

      for model_class in self.all_model_classes:
       __magic_name__     =      True
       __magic_name__     =      False
       __magic_name__     =      True
       __magic_name__     =      model_class(lowercase__       )
       model.to(lowercase__       )
       model.eval()
       with torch.no_grad():
        __magic_name__     =      model(**self._prepare_for_class(lowercase__ ,						lowercase__       )       )
       __magic_name__     =      outputs.attentions
       __magic_name__     =      len(self.model_tester.depths       )
       self.assertEqual(len(lowercase__       ) ,						lowercase__       )

       # check that output_attentions also work using config
       del inputs_dict["output_attentions"]
       __magic_name__     =      True
       __magic_name__     =      config.window_size**2
       __magic_name__     =      model_class(lowercase__       )
       model.to(lowercase__       )
       model.eval()
       with torch.no_grad():
        __magic_name__     =      model(**self._prepare_for_class(lowercase__ ,						lowercase__       )       )
       __magic_name__     =      outputs.attentions
       self.assertEqual(len(lowercase__       ) ,						lowercase__       )

       self.assertListEqual(
           list(attentions[0].shape[-3:]       ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)
       __magic_name__     =      len(lowercase__       )

       # Check attention is always last and order is fine
       __magic_name__     =      True
       __magic_name__     =      True
       __magic_name__     =      model_class(lowercase__       )
       model.to(lowercase__       )
       model.eval()
       with torch.no_grad():
        __magic_name__     =      model(**self._prepare_for_class(lowercase__ ,						lowercase__       )       )

       if hasattr(self.model_tester ,						'''num_hidden_states_types'''       ):
        __magic_name__     =      self.model_tester.num_hidden_states_types
       else:
        # also another +1 for reshaped_hidden_states
        __magic_name__     =      2
       self.assertEqual(out_len + added_hidden_states ,						len(lowercase__       )       )

       __magic_name__     =      outputs.attentions

       self.assertEqual(len(lowercase__       ) ,						lowercase__       )

       self.assertListEqual(
           list(self_attentions[0].shape[-3:]       ) ,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,						)







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      model_class(lowercase__       )
      model.to(lowercase__       )
      model.eval()

      with torch.no_grad():
       __magic_name__     =      model(**self._prepare_for_class(lowercase__ ,						lowercase__       )       )

      __magic_name__     =      outputs.hidden_states

      __magic_name__     =      getattr(
          self.model_tester ,						'''expected_num_hidden_layers''' ,						len(self.model_tester.depths       ) + 1       )
      self.assertEqual(len(lowercase__       ) ,						lowercase__       )

      # Swinv2 has a different seq_length
      __magic_name__     =      (
          config.patch_size
          if isinstance(config.patch_size ,						collections.abc.Iterable       )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__     =      (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

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

      __magic_name__     =      outputs.reshaped_hidden_states
      self.assertEqual(len(lowercase__       ) ,						lowercase__       )

      __magic_name__     =      reshaped_hidden_states[0].shape
      __magic_name__     =      (
          reshaped_hidden_states[0].view(lowercase__ ,						lowercase__ ,						height * width       ).permute(0 ,						2 ,						1       )
      )
      self.assertListEqual(
          list(reshaped_hidden_states.shape[-2:]       ) ,						[num_patches, self.model_tester.embed_dim] ,						)







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__     =      (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size ,						collections.abc.Iterable       )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )

      for model_class in self.all_model_classes:
       __magic_name__     =      True
       self.check_hidden_states_output(lowercase__ ,						lowercase__ ,						lowercase__ ,						lowercase__       )

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       __magic_name__     =      True

       self.check_hidden_states_output(lowercase__ ,						lowercase__ ,						lowercase__ ,						lowercase__       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__     =      3

      __magic_name__     =      (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size ,						collections.abc.Iterable       )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )
      __magic_name__     =      (
          config.patch_size
          if isinstance(config.patch_size ,						collections.abc.Iterable       )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__     =      image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
      __magic_name__     =      image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

      for model_class in self.all_model_classes:
       __magic_name__     =      True
       self.check_hidden_states_output(lowercase__ ,						lowercase__ ,						lowercase__ ,						(padded_height, padded_width)       )

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       __magic_name__     =      True
       self.check_hidden_states_output(lowercase__ ,						lowercase__ ,						lowercase__ ,						(padded_height, padded_width)       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_image_modeling(*lowercase__       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*lowercase__       )







     @slow
     def 	lowerCAmelCase__    (      self       ):






      for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __magic_name__     =      SwinvaModel.from_pretrained(lowercase__       )
       self.assertIsNotNone(lowercase__       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__     =      _config_zero_init(lowercase__       )
      for model_class in self.all_model_classes:
       __magic_name__     =      model_class(config=lowercase__       )
       for name, param in model.named_parameters():
        if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
         self.assertIn(
             ((param.data.mean() * 1E9).round() / 1E9).item() ,						[0.0, 1.0] ,						msg=f'''Parameter {name} of model {model_class} seems not properly initialized''' ,						)


@require_vision
@require_torch
class        _lowercase					(     unittest.TestCase     ):







     @cached_property
     def 	lowerCAmelCase__    (      self       ):
      return (
          AutoImageProcessor.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''       )
          if is_vision_available()
          else None
      )







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      SwinvaForImageClassification.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''       ).to(
          lowercase__       )
      __magic_name__     =      self.default_image_processor

      __magic_name__     =      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''       )
      __magic_name__     =      image_processor(images=lowercase__ ,						return_tensors='''pt'''       ).to(lowercase__       )

      # forward pass
      with torch.no_grad():
       __magic_name__     =      model(**lowercase__       )

      # verify the logits
      __magic_name__     =      torch.Size((1, 1000)       )
      self.assertEqual(outputs.logits.shape ,						lowercase__       )
      __magic_name__     =      torch.tensor([-0.3_9_4_7, -0.4_3_0_6, 0.0_0_2_6]       ).to(lowercase__       )
      self.assertTrue(torch.allclose(outputs.logits[0, :3] ,						lowercase__ ,						atol=1E-4       )       )




"""simple docstring"""






import unittest

from transformers import SPIECE_UNDERLINE, ReformerTokenizer, ReformerTokenizerFast
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										=		get_tests_dir("fixtures/test_sentencepiece.model")
@require_sentencepiece
@require_tokenizers
class        _lowercase					(     __UpperCAmelCase   , unittest.TestCase     ):
     _lowerCamelCase     =       ReformerTokenizer
     _lowerCamelCase     =       ReformerTokenizerFast
     _lowerCamelCase     =       True
     _lowerCamelCase     =       False
     _lowerCamelCase     =       True







     def 	lowerCAmelCase__    (      self       ):
      super().setUp()

      __magic_name__     =      ReformerTokenizer(UpperCamelCase_ ,						keep_accents=UpperCamelCase_       )
      tokenizer.save_pretrained(self.tmpdirname       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      '''<s>'''
      __magic_name__     =      1

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







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      list(self.get_tokenizer().get_vocab().keys()       )

      self.assertEqual(vocab_keys[0] ,						'''<unk>'''       )
      self.assertEqual(vocab_keys[1] ,						'''<s>'''       )
      self.assertEqual(vocab_keys[-1] ,						'''j'''       )
      self.assertEqual(len(UpperCamelCase_       ) ,						1000       )







     def 	lowerCAmelCase__    (      self       ):
      self.assertEqual(self.get_tokenizer().vocab_size ,						1000       )







     def 	lowerCAmelCase__    (      self       ):
      if not self.test_rust_tokenizer:
       return

      __magic_name__     =      self.get_tokenizer()
      __magic_name__     =      self.get_rust_tokenizer()

      __magic_name__     =      '''I was born in 92000, and this is falsé.'''

      __magic_name__     =      tokenizer.tokenize(UpperCamelCase_       )
      __magic_name__     =      rust_tokenizer.tokenize(UpperCamelCase_       )
      self.assertListEqual(UpperCamelCase_ ,						UpperCamelCase_       )

      __magic_name__     =      tokenizer.encode(UpperCamelCase_ ,						add_special_tokens=UpperCamelCase_       )
      __magic_name__     =      rust_tokenizer.encode(UpperCamelCase_ ,						add_special_tokens=UpperCamelCase_       )
      self.assertListEqual(UpperCamelCase_ ,						UpperCamelCase_       )

      __magic_name__     =      self.get_rust_tokenizer()
      __magic_name__     =      tokenizer.encode(UpperCamelCase_       )
      __magic_name__     =      rust_tokenizer.encode(UpperCamelCase_       )
      self.assertListEqual(UpperCamelCase_ ,						UpperCamelCase_       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_=15       ):
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
       with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''       ):
        __magic_name__     =      self.rust_tokenizer_class.from_pretrained(UpperCamelCase_ ,						**UpperCamelCase_       )

        # Simple input
        __magic_name__     =      '''This is a simple input'''
        __magic_name__     =      ['''This is a simple input 1''', '''This is a simple input 2''']
        __magic_name__     =      ('''This is a simple input''', '''This is a pair''')
        __magic_name__     =      [
            ('''This is a simple input 1''', '''This is a simple input 2'''),
            ('''This is a simple pair 1''', '''This is a simple pair 2'''),
        ]

        # Simple input tests
        self.assertRaises(UpperCamelCase_ ,						tokenizer_r.encode ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length'''       )

        # Simple input
        self.assertRaises(UpperCamelCase_ ,						tokenizer_r.encode_plus ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length'''       )

        # Simple input
        self.assertRaises(
            UpperCamelCase_ ,						tokenizer_r.batch_encode_plus ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length''' ,						)

        # Pair input
        self.assertRaises(UpperCamelCase_ ,						tokenizer_r.encode ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length'''       )

        # Pair input
        self.assertRaises(UpperCamelCase_ ,						tokenizer_r.encode_plus ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length'''       )

        # Pair input
        self.assertRaises(
            UpperCamelCase_ ,						tokenizer_r.batch_encode_plus ,						UpperCamelCase_ ,						max_length=UpperCamelCase_ ,						padding='''max_length''' ,						)







     def 	lowerCAmelCase__    (      self       ):
      pass







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      ReformerTokenizer(UpperCamelCase_ ,						keep_accents=UpperCamelCase_       )

      __magic_name__     =      tokenizer.tokenize('''This is a test'''       )
      self.assertListEqual(UpperCamelCase_ ,						['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']       )

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

      __magic_name__     =      tokenizer.tokenize('''I was born in 92000, and this is falsé.'''       )
      self.assertListEqual(
          UpperCamelCase_ ,						[
              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''',
              '''é''',
              '''.''',
          ] ,						)
      __magic_name__     =      tokenizer.convert_tokens_to_ids(UpperCamelCase_       )
      self.assertListEqual(
          UpperCamelCase_ ,						[8, 21, 84, 55, 24, 19, 7, 0, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 0, 4] ,						)

      __magic_name__     =      tokenizer.convert_ids_to_tokens(UpperCamelCase_       )
      self.assertListEqual(
          UpperCamelCase_ ,						[
              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 	lowerCAmelCase__    (      self       ):
      return ReformerTokenizer.from_pretrained('''google/reformer-crime-and-punishment'''       )







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      '''Hello World!'''
      __magic_name__     =      [126, 32, 262, 152, 38, 72, 287]

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







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      (
          '''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'''
      )
      __magic_name__     =      [
          108,
          265,
          24,
          111,
          4,
          258,
          156,
          35,
          28,
          275,
          3,
          259,
          297,
          260,
          84,
          4,
          35,
          110,
          44,
          8,
          259,
          91,
          268,
          21,
          11,
          209,
          274,
          109,
          266,
          277,
          117,
          86,
          93,
          315,
          258,
          278,
          258,
          277,
          258,
          0,
          258,
          288,
          258,
          319,
          258,
          0,
          258,
          0,
          258,
          0,
          258,
          0,
          258,
          287,
          258,
          315,
          258,
          289,
          258,
          278,
          99,
          269,
          266,
          262,
          8,
          259,
          241,
          4,
          217,
          230,
          268,
          266,
          55,
          168,
          106,
          75,
          193,
          266,
          223,
          27,
          49,
          26,
          282,
          25,
          264,
          299,
          19,
          26,
          0,
          258,
          277,
          117,
          86,
          93,
          176,
          183,
          270,
          11,
          262,
          42,
          61,
          265,
      ]

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







     @require_torch
     @slow
     def 	lowerCAmelCase__    (      self       ):
      import torch

      from transformers import ReformerConfig, ReformerModel

      # Build sequence
      __magic_name__     =      list(self.big_tokenizer.get_vocab().keys()       )[:10]
      __magic_name__     =      ''' '''.join(UpperCamelCase_       )
      __magic_name__     =      self.big_tokenizer.encode_plus(UpperCamelCase_ ,						return_tensors='''pt'''       )
      __magic_name__     =      self.big_tokenizer.batch_encode_plus([sequence, sequence] ,						return_tensors='''pt'''       )

      __magic_name__     =      ReformerConfig()
      # The input gets padded during training so adjust the axial position encodings from the pretrained model value of (512, 1024)
      __magic_name__     =      encoded_sequence['''input_ids'''].shape
      __magic_name__     =      ReformerModel(UpperCamelCase_       )

      # Reformer has config.vocab_size == tokenizer.vocab_size == len(tokenizer) - 1 = 320; len(tokenizer) is 321 (including a pad token with id 320)
      assert model.get_input_embeddings().weight.shape[0] >= self.big_tokenizer.vocab_size

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







     @slow
     def 	lowerCAmelCase__    (      self       ):
      # fmt: off
      __magic_name__     =      {'''input_ids''': [[108, 265, 24, 111, 4, 258, 156, 7, 51, 279, 58, 7, 76, 25, 69, 278], [140, 243, 264, 134, 17, 267, 77, 263, 22, 262, 297, 258, 304, 177, 279, 266, 14, 89, 13, 35, 261, 299, 272, 137, 275, 278]], '''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]]}  # noqa: E501
      # fmt: on

      # This tokenizer does not know some characters like ")".
      # That is the reason why we use very simple texts here.
      # Also see https://github.com/huggingface/transformers/pull/11737#issuecomment-850769064
      __magic_name__     =      [
          '''This is a very simple sentence.''',
          '''The quick brown fox jumps over the lazy dog.''',
      ]

      self.tokenizer_integration_test_util(
          expected_encoding=UpperCamelCase_ ,						model_name='''google/reformer-crime-and-punishment''' ,						revision='''0e6c3decb8211d49bf881013425dc8b0448b3f5a''' ,						padding=UpperCamelCase_ ,						sequences=UpperCamelCase_ ,						)

