



'''simple docstring'''






import json
import os
import re
import unittest

from transformers import CodeGenTokenizer, CodeGenTokenizerFast
from transformers.models.codegen.tokenization_codegen import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class 							a__( lowerCamelCase__		,			unittest.TestCase     ):
    lowercase__			=   CodeGenTokenizer
    lowercase__			=   CodeGenTokenizerFast
    lowercase__			=   True
    lowercase__			=   {"""add_prefix_space""": True}
    lowercase__			=   False







    def       lowercase_	(				self			:  Optional[int]     ):
      super().setUp()

      # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
      a						: Optional[Any]					       =					[
          'l',
          'o',
          'w',
          'e',
          'r',
          's',
          't',
          'i',
          'd',
          'n',
          '\u0120',
          '\u0120l',
          '\u0120n',
          '\u0120lo',
          '\u0120low',
          'er',
          '\u0120lowest',
          '\u0120newer',
          '\u0120wider',
          '<unk>',
          '<|endoftext|>',
      ]
      a						: Any					       =					dict(zip(__snake_case						,      range(len(__snake_case     )     )     )     )
      a						: int					       =					['#version: 0.2', '\u0120 l', '\u0120l o', '\u0120lo w', 'e r', '']
      a						: Tuple					       =					{'unk_token': '<unk>'}

      a						: Any					       =					os.path.join(self.tmpdirname						,      VOCAB_FILES_NAMES['vocab_file']     )
      a						: List[Any]					       =					os.path.join(self.tmpdirname						,      VOCAB_FILES_NAMES['merges_file']     )
      with open(self.vocab_file						,      'w'						,      encoding='utf-8'     ) as fp:
        fp.write(json.dumps(__snake_case     ) + '\n'     )
      with open(self.merges_file						,      'w'						,      encoding='utf-8'     ) as fp:
        fp.write('\n'.join(__snake_case     )     )







    def       lowercase_	(				self			:  str						,      **__snake_case			:  str     ):
      kwargs.update(self.special_tokens_map     )
      return CodeGenTokenizer.from_pretrained(self.tmpdirname						,      **__snake_case     )







    def       lowercase_	(				self			:  List[Any]						,      **__snake_case			:  str     ):
      kwargs.update(self.special_tokens_map     )
      return CodeGenTokenizerFast.from_pretrained(self.tmpdirname						,      **__snake_case     )







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  List[str]     ):
      a						: Any					       =					'lower newer'
      a						: Any					       =					'lower newer'
      return input_text, output_text







    def       lowercase_	(				self			:  Tuple     ):
      a						: Optional[int]					       =					CodeGenTokenizer(self.vocab_file						,      self.merges_file						,      **self.special_tokens_map     )
      a						: str					       =					'lower newer'
      a						: Optional[int]					       =					['\u0120low', 'er', '\u0120', 'n', 'e', 'w', 'er']
      a						: str					       =					tokenizer.tokenize(__snake_case						,      add_prefix_space=__snake_case     )
      self.assertListEqual(__snake_case						,      __snake_case     )

      a						: Optional[int]					       =					tokens + [tokenizer.unk_token]
      a						: Union[str, Any]					       =					[14, 15, 10, 9, 3, 2, 15, 19]
      self.assertListEqual(tokenizer.convert_tokens_to_ids(__snake_case     )						,      __snake_case     )







    def       lowercase_	(				self			:  Dict     ):
      if not self.test_rust_tokenizer:
        return

      a						: int					       =					self.get_tokenizer()
      a						: Optional[int]					       =					self.get_rust_tokenizer(add_prefix_space=__snake_case     )

      a						: List[Any]					       =					'lower newer'

      # Testing tokenization
      a						: List[Any]					       =					tokenizer.tokenize(__snake_case						,      add_prefix_space=__snake_case     )
      a						: Union[str, Any]					       =					rust_tokenizer.tokenize(__snake_case     )
      self.assertListEqual(__snake_case						,      __snake_case     )

      # Testing conversion to ids without special tokens
      a						: List[str]					       =					tokenizer.encode(__snake_case						,      add_special_tokens=__snake_case						,      add_prefix_space=__snake_case     )
      a						: Dict					       =					rust_tokenizer.encode(__snake_case						,      add_special_tokens=__snake_case     )
      self.assertListEqual(__snake_case						,      __snake_case     )

      # Testing conversion to ids with special tokens
      a						: Optional[Any]					       =					self.get_rust_tokenizer(add_prefix_space=__snake_case     )
      a						: str					       =					tokenizer.encode(__snake_case						,      add_prefix_space=__snake_case     )
      a						: int					       =					rust_tokenizer.encode(__snake_case     )
      self.assertListEqual(__snake_case						,      __snake_case     )

      # Testing the unknown token
      a						: Optional[int]					       =					tokens + [rust_tokenizer.unk_token]
      a						: int					       =					[14, 15, 10, 9, 3, 2, 15, 19]
      self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(__snake_case     )						,      __snake_case     )







    def       lowercase_	(				self			:  int						,      *__snake_case			:  Dict						,      **__snake_case			:  List[str]     ):
      # It's very difficult to mix/test pretokenization with byte-level
      # And get both CodeGen and Roberta to work at the same time (mostly an issue of adding a space before the string)
      pass







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  Union[str, Any]=15     ):
      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(__snake_case						,      **__snake_case     )

          # Simple input
          a						: int					       =					'This is a simple input'
          a						: Dict					       =					['This is a simple input 1', 'This is a simple input 2']
          a						: Optional[Any]					       =					('This is a simple input', 'This is a pair')
          a						: List[Any]					       =					[
              ('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(__snake_case						,      tokenizer_r.encode						,      __snake_case						,      max_length=__snake_case						,      padding='max_length'     )

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

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

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

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

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







    def       lowercase_	(				self			:  int     ):
      a						: List[Any]					       =					CodeGenTokenizer.from_pretrained(self.tmpdirname						,      pad_token='<pad>'     )

      # Simple input
      a						: Dict					       =					'This is a simple input'
      a						: Optional[Any]					       =					['This is a simple input looooooooong', 'This is a simple input']
      a						: Dict					       =					('This is a simple input', 'This is a pair')
      a						: Optional[Any]					       =					[
          ('This is a simple input loooooong', 'This is a simple input'),
          ('This is a simple pair loooooong', 'This is a simple pair'),
      ]

      a						: Union[str, Any]					       =					tokenizer.pad_token_id

      a						: Dict					       =					tokenizer(__snake_case						,      padding='max_length'						,      max_length=30						,      return_tensors='np'     )
      a						: int					       =					tokenizer(__snake_case						,      padding=__snake_case						,      truncate=__snake_case						,      return_tensors='np'     )
      a						: Dict					       =					tokenizer(*__snake_case						,      padding='max_length'						,      max_length=60						,      return_tensors='np'     )
      a						: List[Any]					       =					tokenizer(__snake_case						,      padding=__snake_case						,      truncate=__snake_case						,      return_tensors='np'     )

      # s
      # test single string max_length padding
      self.assertEqual(out_s['input_ids'].shape[-1]						,      30     )
      self.assertTrue(pad_token_id in out_s['input_ids']     )
      self.assertTrue(0 in out_s['attention_mask']     )

      # s2
      # test automatic padding
      self.assertEqual(out_sa['input_ids'].shape[-1]						,      33     )
      # long slice doesn't have padding
      self.assertFalse(pad_token_id in out_sa['input_ids'][0]     )
      self.assertFalse(0 in out_sa['attention_mask'][0]     )
      # short slice does have padding
      self.assertTrue(pad_token_id in out_sa['input_ids'][1]     )
      self.assertTrue(0 in out_sa['attention_mask'][1]     )

      # p
      # test single pair max_length padding
      self.assertEqual(out_p['input_ids'].shape[-1]						,      60     )
      self.assertTrue(pad_token_id in out_p['input_ids']     )
      self.assertTrue(0 in out_p['attention_mask']     )

      # p2
      # test automatic padding pair
      self.assertEqual(out_pa['input_ids'].shape[-1]						,      52     )
      # long slice pair doesn't have padding
      self.assertFalse(pad_token_id in out_pa['input_ids'][0]     )
      self.assertFalse(0 in out_pa['attention_mask'][0]     )
      # short slice pair does have padding
      self.assertTrue(pad_token_id in out_pa['input_ids'][1]     )
      self.assertTrue(0 in out_pa['attention_mask'][1]     )







    def       lowercase_	(				self			:  int     ):
      a						: int					       =					'$$$'
      a						: List[str]					       =					CodeGenTokenizer.from_pretrained(self.tmpdirname						,      bos_token=__snake_case						,      add_bos_token=__snake_case     )

      a						: Optional[int]					       =					'This is a simple input'
      a						: Optional[Any]					       =					['This is a simple input 1', 'This is a simple input 2']

      a						: Tuple					       =					tokenizer.bos_token_id

      a						: int					       =					tokenizer(__snake_case     )
      a						: Any					       =					tokenizer(__snake_case     )

      self.assertEqual(out_s.input_ids[0]						,      __snake_case     )
      self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids     )     )

      a						: Optional[Any]					       =					tokenizer.decode(out_s.input_ids     )
      a						: str					       =					tokenizer.batch_decode(out_sa.input_ids     )

      self.assertEqual(decode_s.split()[0]						,      __snake_case     )
      self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa     )     )







    @slow
    def       lowercase_	(				self			:  Union[str, Any]     ):
      a						: Optional[Any]					       =					CodeGenTokenizer.from_pretrained('Salesforce/codegen-350M-mono'     )

      a						: str					       =					'\nif len_a > len_b:\n    result = a\nelse:\n    result = b\n\n\n\n#'
      a						: Optional[int]					       =					'\nif len_a > len_b:      result = a\nelse:      result = b'

      a						: Dict					       =					tokenizer.encode(__snake_case     )
      a						: Optional[int]					       =					['^#', re.escape('<|endoftext|>'     ), '^\'\'\'', '^"""', '\n\n\n']
      a						: Any					       =					tokenizer.decode(__snake_case						,      truncate_before_pattern=__snake_case     )
      self.assertEqual(__snake_case						,      __snake_case     )







    def       lowercase_	(				self			:  List[str]     ):
      pass




'''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     )     )