



'''simple docstring'''






import os
import unittest

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    BertTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english

@require_tokenizers
class 							a__( __lowerCAmelCase		,			unittest.TestCase     ):
    lowercase__			=   BertTokenizer
    lowercase__			=   BertTokenizerFast
    lowercase__			=   True
    lowercase__			=   True
    lowercase__			=   filter_non_english







    def       lowercase_	(				self			:  Any     ):
      super().setUp()

      a						: str					       =					[
          '[UNK]',
          '[CLS]',
          '[SEP]',
          '[PAD]',
          '[MASK]',
          'want',
          '##want',
          '##ed',
          'wa',
          'un',
          'runn',
          '##ing',
          ',',
          'low',
          'lowest',
      ]
      a						: int					       =					os.path.join(self.tmpdirname						,      VOCAB_FILES_NAMES['vocab_file']     )
      with open(self.vocab_file						,      'w'						,      encoding='utf-8'     ) as vocab_writer:
        vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]     )     )







    def       lowercase_	(				self			:  Optional[int]						,      __snake_case			:  Dict     ):
      a						: Dict					       =					'UNwant\u00E9d,running'
      a						: Dict					       =					'unwanted, running'
      return input_text, output_text







    def       lowercase_	(				self			:  Any     ):
      a						: int					       =					self.tokenizer_class(self.vocab_file     )

      a						: int					       =					tokenizer.tokenize('UNwant\u00E9d,running'     )
      self.assertListEqual(lowerCAmelCase_						,      ['un', '##want', '##ed', ',', 'runn', '##ing']     )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase_     )						,      [9, 6, 7, 12, 10, 11]     )







    def       lowercase_	(				self			:  List[str]     ):
      if not self.test_rust_tokenizer:
        return

      a						: Any					       =					self.get_tokenizer()
      a						: Dict					       =					self.get_rust_tokenizer()

      a						: List[Any]					       =					'UNwant\u00E9d,running'

      a						: List[str]					       =					tokenizer.tokenize(lowerCAmelCase_     )
      a						: int					       =					rust_tokenizer.tokenize(lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

      a						: List[str]					       =					tokenizer.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
      a						: Optional[int]					       =					rust_tokenizer.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

      a						: List[Any]					       =					self.get_rust_tokenizer()
      a						: Dict					       =					tokenizer.encode(lowerCAmelCase_     )
      a						: Optional[Any]					       =					rust_tokenizer.encode(lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

      # With lower casing
      a						: List[str]					       =					self.get_tokenizer(do_lower_case=lowerCAmelCase_     )
      a						: str					       =					self.get_rust_tokenizer(do_lower_case=lowerCAmelCase_     )

      a						: Optional[int]					       =					'UNwant\u00E9d,running'

      a						: Dict					       =					tokenizer.tokenize(lowerCAmelCase_     )
      a						: List[str]					       =					rust_tokenizer.tokenize(lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

      a						: List[Any]					       =					tokenizer.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
      a						: Optional[Any]					       =					rust_tokenizer.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

      a						: Tuple					       =					self.get_rust_tokenizer()
      a						: Optional[int]					       =					tokenizer.encode(lowerCAmelCase_     )
      a						: Tuple					       =					rust_tokenizer.encode(lowerCAmelCase_     )
      self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )







    def       lowercase_	(				self			:  int     ):
      a						: Dict					       =					BasicTokenizer()

      self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'     )						,      ['ah', '\u535A', '\u63A8', 'zz']     )







    def       lowercase_	(				self			:  str     ):
      a						: Dict					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     )						,      ['hello', '!', 'how', 'are', 'you', '?']     )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,      ['hello']     )







    def       lowercase_	(				self			:  Optional[int]     ):
      a						: Dict					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_						,      strip_accents=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,      ['hällo', '!', 'how', 'are', 'you', '?']     )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,      ['h\u00E9llo']     )







    def       lowercase_	(				self			:  str     ):
      a						: List[Any]					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_						,      strip_accents=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,      ['hallo', '!', 'how', 'are', 'you', '?']     )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,      ['hello']     )







    def       lowercase_	(				self			:  Union[str, Any]     ):
      a						: Optional[Any]					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,      ['hallo', '!', 'how', 'are', 'you', '?']     )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     )						,      ['hello']     )







    def       lowercase_	(				self			:  Optional[int]     ):
      a						: Any					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     )						,      ['HeLLo', '!', 'how', 'Are', 'yoU', '?']     )







    def       lowercase_	(				self			:  str     ):
      a						: List[Any]					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_						,      strip_accents=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,      ['HäLLo', '!', 'how', 'Are', 'yoU', '?']     )







    def       lowercase_	(				self			:  int     ):
      a						: str					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_						,      strip_accents=lowerCAmelCase_     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     )						,      ['HaLLo', '!', 'how', 'Are', 'yoU', '?']     )







    def       lowercase_	(				self			:  Dict     ):
      a						: Tuple					       =					BasicTokenizer(do_lower_case=lowerCAmelCase_						,      never_split=['[UNK]']     )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'     )						,      ['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']     )







    def       lowercase_	(				self			:  Tuple     ):
      a						: Dict					       =					BasicTokenizer()
      a						: Optional[int]					       =					'a\n\'ll !!to?\'d of, can\'t.'
      a						: List[str]					       =					['a', '\'', 'll', '!', '!', 'to', '?', '\'', 'd', 'of', ',', 'can', '\'', 't', '.']
      self.assertListEqual(tokenizer.tokenize(lowerCAmelCase_     )						,      lowerCAmelCase_     )







    def       lowercase_	(				self			:  List[Any]     ):
      a						: List[str]					       =					['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

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

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

      self.assertListEqual(tokenizer.tokenize('unwanted running'     )						,      ['un', '##want', '##ed', 'runn', '##ing']     )

      self.assertListEqual(tokenizer.tokenize('unwantedX running'     )						,      ['[UNK]', 'runn', '##ing']     )







    def       lowercase_	(				self			:  str     ):
      self.assertTrue(_is_whitespace(' '     )     )
      self.assertTrue(_is_whitespace('\t'     )     )
      self.assertTrue(_is_whitespace('\r'     )     )
      self.assertTrue(_is_whitespace('\n'     )     )
      self.assertTrue(_is_whitespace('\u00A0'     )     )

      self.assertFalse(_is_whitespace('A'     )     )
      self.assertFalse(_is_whitespace('-'     )     )







    def       lowercase_	(				self			:  Tuple     ):
      self.assertTrue(_is_control('\u0005'     )     )

      self.assertFalse(_is_control('A'     )     )
      self.assertFalse(_is_control(' '     )     )
      self.assertFalse(_is_control('\t'     )     )
      self.assertFalse(_is_control('\r'     )     )







    def       lowercase_	(				self			:  List[Any]     ):
      self.assertTrue(_is_punctuation('-'     )     )
      self.assertTrue(_is_punctuation('$'     )     )
      self.assertTrue(_is_punctuation('`'     )     )
      self.assertTrue(_is_punctuation('.'     )     )

      self.assertFalse(_is_punctuation('A'     )     )
      self.assertFalse(_is_punctuation(' '     )     )







    def       lowercase_	(				self			:  Tuple     ):
      a						: Union[str, Any]					       =					self.get_tokenizer()
      a						: int					       =					self.get_rust_tokenizer()

      # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
      self.assertListEqual([tokenizer.tokenize(lowerCAmelCase_     ) for t in ['Test', '\xad', 'test']]						,      [['[UNK]'], [], ['[UNK]']]     )

      self.assertListEqual(
          [rust_tokenizer.tokenize(lowerCAmelCase_     ) for t in ['Test', '\xad', 'test']]						,      [['[UNK]'], [], ['[UNK]']]     )







    @slow
    def       lowercase_	(				self			:  Dict     ):
      a						: int					       =					self.tokenizer_class.from_pretrained('bert-base-uncased'     )

      a						: Optional[int]					       =					tokenizer.encode('sequence builders'						,      add_special_tokens=lowerCAmelCase_     )
      a						: int					       =					tokenizer.encode('multi-sequence build'						,      add_special_tokens=lowerCAmelCase_     )

      a						: Optional[int]					       =					tokenizer.build_inputs_with_special_tokens(lowerCAmelCase_     )
      a						: Tuple					       =					tokenizer.build_inputs_with_special_tokens(lowerCAmelCase_						,      lowerCAmelCase_     )

      assert encoded_sentence == [1_01] + text + [1_02]
      assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]







    def       lowercase_	(				self			:  Dict     ):
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
        with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""     ):
          a						: str					       =					self.rust_tokenizer_class.from_pretrained(lowerCAmelCase_						,      **lowerCAmelCase_     )

          a						: Optional[int]					       =					F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
          a						: str					       =					tokenizer_r.encode_plus(
              lowerCAmelCase_						,      return_attention_mask=lowerCAmelCase_						,      return_token_type_ids=lowerCAmelCase_						,      return_offsets_mapping=lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_						,      )

          a						: Optional[Any]					       =					tokenizer_r.do_lower_case if hasattr(lowerCAmelCase_						,      'do_lower_case'     ) else False
          a						: List[Any]					       =					(
              [
                  ((0, 0), tokenizer_r.cls_token),
                  ((0, 1), 'A'),
                  ((1, 2), ','),
                  ((3, 5), 'na'),
                  ((5, 6), '##ï'),
                  ((6, 8), '##ve'),
                  ((9, 15), tokenizer_r.mask_token),
                  ((16, 21), 'Allen'),
                  ((21, 23), '##NL'),
                  ((23, 24), '##P'),
                  ((25, 33), 'sentence'),
                  ((33, 34), '.'),
                  ((0, 0), tokenizer_r.sep_token),
              ]
              if not do_lower_case
              else [
                  ((0, 0), tokenizer_r.cls_token),
                  ((0, 1), 'a'),
                  ((1, 2), ','),
                  ((3, 8), 'naive'),
                  ((9, 15), tokenizer_r.mask_token),
                  ((16, 21), 'allen'),
                  ((21, 23), '##nl'),
                  ((23, 24), '##p'),
                  ((25, 33), 'sentence'),
                  ((33, 34), '.'),
                  ((0, 0), tokenizer_r.sep_token),
              ]
          )

          self.assertEqual(
              [e[1] for e in expected_results]						,      tokenizer_r.convert_ids_to_tokens(tokens['input_ids']     )     )
          self.assertEqual([e[0] for e in expected_results]						,      tokens['offset_mapping']     )







    def       lowercase_	(				self			:  Any     ):
      a						: str					       =					['的', '人', '有']
      a						: Tuple					       =					''.join(lowerCAmelCase_     )
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
        with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""     ):
          a						: Any					       =					True
          a						: List[Any]					       =					self.tokenizer_class.from_pretrained(lowerCAmelCase_						,      **lowerCAmelCase_     )
          a						: Optional[int]					       =					self.rust_tokenizer_class.from_pretrained(lowerCAmelCase_						,      **lowerCAmelCase_     )

          a						: str					       =					tokenizer_p.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
          a						: Any					       =					tokenizer_r.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )

          a						: List[str]					       =					tokenizer_r.convert_ids_to_tokens(lowerCAmelCase_     )
          a						: Optional[int]					       =					tokenizer_p.convert_ids_to_tokens(lowerCAmelCase_     )

          # it is expected that each Chinese character is not preceded by "##"
          self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )
          self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )

          a						: List[Any]					       =					False
          a						: int					       =					self.rust_tokenizer_class.from_pretrained(lowerCAmelCase_						,      **lowerCAmelCase_     )
          a						: Union[str, Any]					       =					self.tokenizer_class.from_pretrained(lowerCAmelCase_						,      **lowerCAmelCase_     )

          a						: Any					       =					tokenizer_r.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )
          a						: Optional[int]					       =					tokenizer_p.encode(lowerCAmelCase_						,      add_special_tokens=lowerCAmelCase_     )

          a						: Any					       =					tokenizer_r.convert_ids_to_tokens(lowerCAmelCase_     )
          a						: Any					       =					tokenizer_p.convert_ids_to_tokens(lowerCAmelCase_     )

          # it is expected that only the first Chinese character is not preceded by "##".
          a						: Dict					       =					[
              F"""##{token}""" if idx != 0 else token for idx, token in enumerate(lowerCAmelCase_     )
          ]
          self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )
          self.assertListEqual(lowerCAmelCase_						,      lowerCAmelCase_     )





'''simple docstring'''






import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
     import torch

     from transformers import (
         MraForMaskedLM,
         MraForMultipleChoice,
         MraForQuestionAnswering,
         MraForSequenceClassification,
         MraForTokenClassification,
         MraModel,
     )
     from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST

class 							a__:







    def __init__(				self			:  Union[str, Any]						,      __snake_case			:  Optional[int]						,      __snake_case			:  Optional[int]=2						,      __snake_case			:  Union[str, Any]=8						,      __snake_case			:  List[str]=True						,      __snake_case			:  Dict=True						,      __snake_case			:  Optional[Any]=True						,      __snake_case			:  List[str]=True						,      __snake_case			:  Tuple=99						,      __snake_case			:  int=16						,      __snake_case			:  Optional[int]=5						,      __snake_case			:  int=2						,      __snake_case			:  Tuple=36						,      __snake_case			:  Optional[Any]="gelu"						,      __snake_case			:  str=0.0						,      __snake_case			:  Optional[int]=0.0						,      __snake_case			:  Tuple=5_12						,      __snake_case			:  str=16						,      __snake_case			:  str=2						,      __snake_case			:  int=0.02						,      __snake_case			:  Optional[int]=3						,      __snake_case			:  List[Any]=4						,      __snake_case			:  Any=None						,      ):
      a						: int					       =					parent
      a						: Any					       =					batch_size
      a						: Optional[int]					       =					seq_length
      a						: List[str]					       =					is_training
      a						: Dict					       =					use_input_mask
      a						: Union[str, Any]					       =					use_token_type_ids
      a						: Tuple					       =					use_labels
      a						: Dict					       =					vocab_size
      a						: Optional[int]					       =					hidden_size
      a						: List[Any]					       =					num_hidden_layers
      a						: Optional[Any]					       =					num_attention_heads
      a						: str					       =					intermediate_size
      a						: Dict					       =					hidden_act
      a						: str					       =					hidden_dropout_prob
      a						: Tuple					       =					attention_probs_dropout_prob
      a						: Optional[Any]					       =					max_position_embeddings
      a						: Tuple					       =					type_vocab_size
      a						: int					       =					type_sequence_label_size
      a						: List[Any]					       =					initializer_range
      a						: List[str]					       =					num_labels
      a						: List[str]					       =					num_choices
      a						: Optional[Any]					       =					scope







    def       lowercase_	(				self			:  Union[str, Any]     ):
      a						: List[Any]					       =					ids_tensor([self.batch_size, self.seq_length]						,      self.vocab_size     )

      a						: Optional[Any]					       =					None
      if self.use_input_mask:
        a						: List[Any]					       =					random_attention_mask([self.batch_size, self.seq_length]     )

      a						: Tuple					       =					None
      if self.use_token_type_ids:
        a						: Optional[Any]					       =					ids_tensor([self.batch_size, self.seq_length]						,      self.type_vocab_size     )

      a						: str					       =					None
      a						: int					       =					None
      a						: Any					       =					None
      if self.use_labels:
        a						: int					       =					ids_tensor([self.batch_size]						,      self.type_sequence_label_size     )
        a						: Union[str, Any]					       =					ids_tensor([self.batch_size, self.seq_length]						,      self.num_labels     )
        a						: List[str]					       =					ids_tensor([self.batch_size]						,      self.num_choices     )

      a						: Dict					       =					self.get_config()

      return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







    def       lowercase_	(				self			:  Union[str, Any]     ):
      return MraConfig(
          vocab_size=self.vocab_size						,      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						,      max_position_embeddings=self.max_position_embeddings						,      type_vocab_size=self.type_vocab_size						,      is_decoder=__snake_case						,      initializer_range=self.initializer_range						,      )







    def       lowercase_	(				self			:  List[str]     ):
      a						: List[Any]					       =					self.get_config()
      a						: Optional[Any]					       =					3_00
      return config







    def       lowercase_	(				self			:  Union[str, Any]     ):
      (
          (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     
      )						: Optional[Any]					       =					self.prepare_config_and_inputs()

      a						: Union[str, Any]					       =					True
      a						: Tuple					       =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
      a						: Dict					       =					ids_tensor([self.batch_size, self.seq_length]						,      vocab_size=2     )

      return (
          config,
          input_ids,
          token_type_ids,
          input_mask,
          sequence_labels,
          token_labels,
          choice_labels,
          encoder_hidden_states,
          encoder_attention_mask,
      )







    def       lowercase_	(				self			:  int						,      __snake_case			:  int						,      __snake_case			:  List[Any]						,      __snake_case			:  Union[str, Any]						,      __snake_case			:  List[Any]						,      __snake_case			:  Union[str, Any]						,      __snake_case			:  Dict						,      __snake_case			:  Any     ):
      a						: Dict					       =					MraModel(config=__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: str					       =					model(__snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case     )
      a						: List[str]					       =					model(__snake_case						,      token_type_ids=__snake_case     )
      a						: Union[str, Any]					       =					model(__snake_case     )
      self.parent.assertEqual(result.last_hidden_state.shape						,      (self.batch_size, self.seq_length, self.hidden_size)     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Tuple						,      __snake_case			:  List[str]						,      __snake_case			:  str						,      __snake_case			:  Optional[Any]						,      __snake_case			:  Union[str, Any]						,      __snake_case			:  Any						,      __snake_case			:  Optional[Any]						,      __snake_case			:  Optional[int]						,      __snake_case			:  List[Any]						,      ):
      a						: Optional[Any]					       =					True
      a						: Optional[int]					       =					MraModel(__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: List[Any]					       =					model(
          __snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      encoder_hidden_states=__snake_case						,      encoder_attention_mask=__snake_case						,      )
      a						: Any					       =					model(
          __snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      encoder_hidden_states=__snake_case						,      )
      a						: Optional[int]					       =					model(__snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case     )
      self.parent.assertEqual(result.last_hidden_state.shape						,      (self.batch_size, self.seq_length, self.hidden_size)     )







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  int						,      __snake_case			:  List[Any]						,      __snake_case			:  Optional[int]						,      __snake_case			:  Optional[Any]						,      __snake_case			:  List[Any]						,      __snake_case			:  Dict						,      __snake_case			:  Optional[Any]     ):
      a						: Union[str, Any]					       =					MraForMaskedLM(config=__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: List[str]					       =					model(__snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      labels=__snake_case     )
      self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.seq_length, self.vocab_size)     )







    def       lowercase_	(				self			:  Tuple						,      __snake_case			:  Union[str, Any]						,      __snake_case			:  str						,      __snake_case			:  Tuple						,      __snake_case			:  str						,      __snake_case			:  Tuple						,      __snake_case			:  Optional[int]						,      __snake_case			:  int     ):
      a						: Optional[int]					       =					MraForQuestionAnswering(config=__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: Optional[int]					       =					model(
          __snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      start_positions=__snake_case						,      end_positions=__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       lowercase_	(				self			:  Dict						,      __snake_case			:  Tuple						,      __snake_case			:  List[Any]						,      __snake_case			:  List[Any]						,      __snake_case			:  Optional[Any]						,      __snake_case			:  Any						,      __snake_case			:  List[str]						,      __snake_case			:  str     ):
      a						: Tuple					       =					self.num_labels
      a						: Dict					       =					MraForSequenceClassification(__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: Any					       =					model(__snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      labels=__snake_case     )
      self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.num_labels)     )







    def       lowercase_	(				self			:  str						,      __snake_case			:  Dict						,      __snake_case			:  Optional[Any]						,      __snake_case			:  int						,      __snake_case			:  List[Any]						,      __snake_case			:  Any						,      __snake_case			:  List[Any]						,      __snake_case			:  int     ):
      a						: Tuple					       =					self.num_labels
      a						: Tuple					       =					MraForTokenClassification(config=__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: List[Any]					       =					model(__snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      labels=__snake_case     )
      self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.seq_length, self.num_labels)     )







    def       lowercase_	(				self			:  Any						,      __snake_case			:  Any						,      __snake_case			:  str						,      __snake_case			:  Dict						,      __snake_case			:  List[Any]						,      __snake_case			:  Any						,      __snake_case			:  Any						,      __snake_case			:  str     ):
      a						: Optional[int]					       =					self.num_choices
      a						: int					       =					MraForMultipleChoice(config=__snake_case     )
      model.to(__snake_case     )
      model.eval()
      a						: Tuple					       =					input_ids.unsqueeze(1     ).expand(-1						,      self.num_choices						,      -1     ).contiguous()
      a						: Optional[int]					       =					token_type_ids.unsqueeze(1     ).expand(-1						,      self.num_choices						,      -1     ).contiguous()
      a						: Optional[Any]					       =					input_mask.unsqueeze(1     ).expand(-1						,      self.num_choices						,      -1     ).contiguous()
      a						: int					       =					model(
          __snake_case						,      attention_mask=__snake_case						,      token_type_ids=__snake_case						,      labels=__snake_case						,      )
      self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.num_choices)     )







    def       lowercase_	(				self			:  Optional[Any]     ):
      a						: Union[str, Any]					       =					self.prepare_config_and_inputs()
      (
          (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     (
          a
      )       ,     
      )						: Union[str, Any]					       =					config_and_inputs
      a						: List[str]					       =					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict

@require_torch
class 							a__( lowerCamelCase__		,			unittest.TestCase     ):
    lowercase__			=   (
        (
            MraModel,
            MraForMaskedLM,
            MraForMultipleChoice,
            MraForQuestionAnswering,
            MraForSequenceClassification,
            MraForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    lowercase__			=   False
    lowercase__			=   False
    lowercase__			=   False
    lowercase__			=   False

    lowercase__			=   ()







    def       lowercase_	(				self			:  Any     ):
      a						: Tuple					       =					MraModelTester(self     )
      a						: str					       =					ConfigTester(self						,      config_class=__snake_case						,      hidden_size=37     )







    def       lowercase_	(				self			:  List[str]     ):
      self.config_tester.run_common_tests()







    def       lowercase_	(				self			:  List[str]     ):
      a						: List[Any]					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__snake_case     )







    def       lowercase_	(				self			:  Any     ):
      a						: Union[str, Any]					       =					self.model_tester.prepare_config_and_inputs()
      for type in ["absolute", "relative_key", "relative_key_query"]:
        a						: Dict					       =					type
        self.model_tester.create_and_check_model(*__snake_case     )







    def       lowercase_	(				self			:  List[Any]     ):
      a						: Dict					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__snake_case     )







    def       lowercase_	(				self			:  Optional[Any]     ):
      a						: List[str]					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*__snake_case     )







    def       lowercase_	(				self			:  List[Any]     ):
      a						: int					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__snake_case     )







    def       lowercase_	(				self			:  Tuple     ):
      a						: Tuple					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__snake_case     )







    def       lowercase_	(				self			:  Optional[Any]     ):
      a						: Dict					       =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__snake_case     )







    @slow
    def       lowercase_	(				self			:  int     ):
      for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						: Dict					       =					MraModel.from_pretrained(__snake_case     )
        self.assertIsNotNone(__snake_case     )







    @unittest.skip(reason='MRA does not output attentions'     )
    def       lowercase_	(				self			:  Union[str, Any]     ):
      return

@require_torch
class 							a__( unittest.TestCase     ):







    @slow
    def       lowercase_	(				self			:  Union[str, Any]     ):
      a						: Union[str, Any]					       =					MraModel.from_pretrained('uw-madison/mra-base-512-4'     )
      a						: List[str]					       =					torch.arange(2_56     ).unsqueeze(0     )

      with torch.no_grad():
        a						: Optional[int]					       =					model(__snake_case     )[0]

      a						: Any					       =					torch.Size((1, 2_56, 7_68)     )
      self.assertEqual(output.shape						,      __snake_case     )

      a						: str					       =					torch.tensor(
          [[[-0.0140, 0.0830, -0.0381], [0.1546, 0.1402, 0.0220], [0.1162, 0.0851, 0.0165]]]     )

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







    @slow
    def       lowercase_	(				self			:  Optional[int]     ):
      a						: Dict					       =					MraForMaskedLM.from_pretrained('uw-madison/mra-base-512-4'     )
      a						: Optional[int]					       =					torch.arange(2_56     ).unsqueeze(0     )

      with torch.no_grad():
        a						: Dict					       =					model(__snake_case     )[0]

      a						: Union[str, Any]					       =					5_02_65

      a						: Dict					       =					torch.Size((1, 2_56, vocab_size)     )
      self.assertEqual(output.shape						,      __snake_case     )

      a						: Dict					       =					torch.tensor(
          [[[9.2595, -3.6038, 11.8819], [9.3869, -3.2693, 11.0956], [11.8524, -3.4938, 13.1210]]]     )

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







    @slow
    def       lowercase_	(				self			:  Any     ):
      a						: Dict					       =					MraForMaskedLM.from_pretrained('uw-madison/mra-base-4096-8-d3'     )
      a						: Optional[int]					       =					torch.arange(40_96     ).unsqueeze(0     )

      with torch.no_grad():
        a						: Tuple					       =					model(__snake_case     )[0]

      a						: List[Any]					       =					5_02_65

      a						: str					       =					torch.Size((1, 40_96, vocab_size)     )
      self.assertEqual(output.shape						,      __snake_case     )

      a						: int					       =					torch.tensor(
          [[[5.4789, -2.3564, 7.5064], [7.9067, -1.3369, 9.9668], [9.0712, -1.8106, 7.0380]]]     )

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