



"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import numpy as np
      import tensorflow as tf

      from transformers import (
          TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          FlaubertConfig,
          TFFlaubertForMultipleChoice,
          TFFlaubertForQuestionAnsweringSimple,
          TFFlaubertForSequenceClassification,
          TFFlaubertForTokenClassification,
          TFFlaubertModel,
          TFFlaubertWithLMHeadModel,
      )



class       SCREAMING_SNAKE_CASE__  :

   def __init__(   self      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	parent
    UpperCAmelCase	:					Optional[Any]	=	13
    UpperCAmelCase	:					Union[str, Any]	=	7
    UpperCAmelCase	:					Tuple	=	True
    UpperCAmelCase	:					List[str]	=	True
    UpperCAmelCase	:					str	=	True
    UpperCAmelCase	:					Tuple	=	True
    UpperCAmelCase	:					Dict	=	True
    UpperCAmelCase	:					Union[str, Any]	=	False
    UpperCAmelCase	:					Tuple	=	False
    UpperCAmelCase	:					int	=	False
    UpperCAmelCase	:					Any	=	2
    UpperCAmelCase	:					Tuple	=	99
    UpperCAmelCase	:					Any	=	0
    UpperCAmelCase	:					Dict	=	32
    UpperCAmelCase	:					Dict	=	2
    UpperCAmelCase	:					List[str]	=	4
    UpperCAmelCase	:					str	=	0.1
    UpperCAmelCase	:					List[Any]	=	0.1
    UpperCAmelCase	:					str	=	512
    UpperCAmelCase	:					str	=	16
    UpperCAmelCase	:					Optional[Any]	=	2
    UpperCAmelCase	:					Union[str, Any]	=	0.02
    UpperCAmelCase	:					Optional[int]	=	3
    UpperCAmelCase	:					Tuple	=	4
    UpperCAmelCase	:					Union[str, Any]	=	"""last"""
    UpperCAmelCase	:					Optional[Any]	=	True
    UpperCAmelCase	:					Union[str, Any]	=	None
    UpperCAmelCase	:					int	=	0

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Tuple:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	ids_tensor([self.batch_size, self.seq_length]      ,     self.vocab_size						)
    UpperCAmelCase	:					Dict	=	random_attention_mask([self.batch_size, self.seq_length]      ,     dtype=tf.floataa						)

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

    UpperCAmelCase	:					Any	=	None
    if self.use_token_type_ids:
     UpperCAmelCase	:					Dict	=	ids_tensor([self.batch_size, self.seq_length]      ,     self.n_langs						)

    UpperCAmelCase	:					Union[str, Any]	=	None
    UpperCAmelCase	:					Dict	=	None
    UpperCAmelCase	:					List[str]	=	None
    if self.use_labels:
     UpperCAmelCase	:					str	=	ids_tensor([self.batch_size]      ,     self.type_sequence_label_size						)
     UpperCAmelCase	:					Any	=	ids_tensor([self.batch_size, self.seq_length]      ,     self.num_labels						)
     UpperCAmelCase	:					int	=	ids_tensor([self.batch_size]      ,     2      ,     dtype=tf.floataa						)
     UpperCAmelCase	:					int	=	ids_tensor([self.batch_size]      ,     self.num_choices						)

    UpperCAmelCase	:					str	=	FlaubertConfig(
        vocab_size=self.vocab_size      ,     n_special=self.n_special      ,     emb_dim=self.hidden_size      ,     n_layers=self.num_hidden_layers      ,     n_heads=self.num_attention_heads      ,     dropout=self.hidden_dropout_prob      ,     attention_dropout=self.attention_probs_dropout_prob      ,     gelu_activation=self.gelu_activation      ,     sinusoidal_embeddings=self.sinusoidal_embeddings      ,     asm=self.asm      ,     causal=self.causal      ,     n_langs=self.n_langs      ,     max_position_embeddings=self.max_position_embeddings      ,     initializer_range=self.initializer_range      ,     summary_type=self.summary_type      ,     use_proj=self.use_proj      ,     bos_token_id=self.bos_token_id      ,     )

    return (
        config,
        input_ids,
        token_type_ids,
        input_lengths,
        sequence_labels,
        token_labels,
        is_impossible_labels,
        choice_labels,
        input_mask,
    )

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	TFFlaubertModel(config=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					List[Any]	=	{"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
    UpperCAmelCase	:					Optional[Any]	=	model(_SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	:					Dict	=	[input_ids, input_mask]
    UpperCAmelCase	:					Dict	=	model(_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, self.seq_length, self.hidden_size)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	TFFlaubertWithLMHeadModel(_SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	:					Dict	=	{"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
    UpperCAmelCase	:					str	=	model(_SCREAMING_SNAKE_CASE						)

    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.seq_length, self.vocab_size)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	TFFlaubertForQuestionAnsweringSimple(_SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	:					Tuple	=	{"""input_ids""": input_ids, """lengths""": input_lengths}

    UpperCAmelCase	:					int	=	model(_SCREAMING_SNAKE_CASE						)

    self.parent.assertEqual(result.start_logits.shape      ,     (self.batch_size, self.seq_length)						)
    self.parent.assertEqual(result.end_logits.shape      ,     (self.batch_size, self.seq_length)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      Tuple:





    '''simple docstring'''




    UpperCAmelCase	:					List[str]	=	TFFlaubertForSequenceClassification(_SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	:					Optional[Any]	=	{"""input_ids""": input_ids, """lengths""": input_lengths}

    UpperCAmelCase	:					int	=	model(_SCREAMING_SNAKE_CASE						)

    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.type_sequence_label_size)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	self.num_labels
    UpperCAmelCase	:					List[str]	=	TFFlaubertForTokenClassification(config=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					List[str]	=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
    UpperCAmelCase	:					Union[str, Any]	=	model(_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.seq_length, self.num_labels)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     )  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	self.num_choices
    UpperCAmelCase	:					Union[str, Any]	=	TFFlaubertForMultipleChoice(config=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					Tuple	=	tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE      ,     1						)      ,     (1, self.num_choices, 1)						)
    UpperCAmelCase	:					Optional[Any]	=	tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE      ,     1						)      ,     (1, self.num_choices, 1)						)
    UpperCAmelCase	:					List[str]	=	tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE      ,     1						)      ,     (1, self.num_choices, 1)						)
    UpperCAmelCase	:					Optional[Any]	=	{
        """input_ids""": multiple_choice_inputs_ids,
        """attention_mask""": multiple_choice_input_mask,
        """token_type_ids""": multiple_choice_token_type_ids,
    }
    UpperCAmelCase	:					int	=	model(_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.num_choices)						)




   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					Any	=	self.prepare_config_and_inputs()
    (
        (
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		(
        UpperCAmelCase
    )	,		
    )	:					Union[str, Any]	=	config_and_inputs
    UpperCAmelCase	:					str	=	{
        """input_ids""": input_ids,
        """token_type_ids""": token_type_ids,
        """langs""": token_type_ids,
        """lengths""": input_lengths,
    }
    return config, inputs_dict



@require_tf
class       SCREAMING_SNAKE_CASE__  (					UpperCAmelCase__      ,			UpperCAmelCase__      ,			unittest.TestCase ):
   __lowerCAmelCase  :   Union[str, Any]						=						(
       (
           TFFlaubertModel,
           TFFlaubertWithLMHeadModel,
           TFFlaubertForSequenceClassification,
           TFFlaubertForQuestionAnsweringSimple,
           TFFlaubertForTokenClassification,
           TFFlaubertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   __lowerCAmelCase  :   Union[str, Any]						=						(
       (TFFlaubertWithLMHeadModel,) if is_tf_available() else ()
   )  # TODO (PVP): Check other models whether language generation is also applicable
   __lowerCAmelCase  :   str						=						(
       {
           'feature-extraction': TFFlaubertModel,
           'fill-mask': TFFlaubertWithLMHeadModel,
           'question-answering': TFFlaubertForQuestionAnsweringSimple,
           'text-classification': TFFlaubertForSequenceClassification,
           'token-classification': TFFlaubertForTokenClassification,
           'zero-shot': TFFlaubertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   __lowerCAmelCase  :   int						=						False
   __lowerCAmelCase  :   List[Any]						=						False

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)  ->      str:





    '''simple docstring'''




    if (
        pipeline_test_casse_name == "QAPipelineTests"
        and tokenizer_name is not None
        and not tokenizer_name.endswith("""Fast"""						)
    ):
     # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
     # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
     # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
     return True

    return False

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	TFFlaubertModelTester(self						)
    UpperCAmelCase	:					Any	=	ConfigTester(self      ,     config_class=_SCREAMING_SNAKE_CASE      ,     emb_dim=37						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    self.config_tester.run_common_tests()

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					List[str]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_model(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_lm_head(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[Any]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_qa(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					int	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_sequence_classif(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					Tuple	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_for_token_classification(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Dict:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_flaubert_for_multiple_choice(*_SCREAMING_SNAKE_CASE						)




   @slow
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[Any]:





    '''simple docstring'''




    for model_name in TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase	:					Union[str, Any]	=	TFFlaubertModel.from_pretrained(_SCREAMING_SNAKE_CASE						)
     self.assertIsNotNone(_SCREAMING_SNAKE_CASE						)



@require_tf
@require_sentencepiece
@require_tokenizers
class       SCREAMING_SNAKE_CASE__  (					unittest.TestCase ):

   @slow
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Dict:





    '''simple docstring'''




    UpperCAmelCase	:					Optional[int]	=	TFFlaubertModel.from_pretrained("""jplu/tf-flaubert-small-cased"""						)

    UpperCAmelCase	:					List[Any]	=	tf.convert_to_tensor(
        [[0, 158, 735, 2592, 1424, 6727, 82, 1]]      ,     dtype=tf.intaa      ,     )  # "J'aime flaubert !"

    UpperCAmelCase	:					List[Any]	=	model(_SCREAMING_SNAKE_CASE						)[0]
    UpperCAmelCase	:					Tuple	=	tf.TensorShape((1, 8, 512)						)
    self.assertEqual(output.shape      ,     _SCREAMING_SNAKE_CASE						)
    # compare the actual values for a slice.
    UpperCAmelCase	:					int	=	tf.convert_to_tensor(
        [
            [
                [-1.876_8773, -1.56_6555, 0.2707_2418],
                [-1.692_0038, -0.587_3505, 1.932_9599],
                [-2.956_3985, -1.699_3835, 1.797_2052],
            ]
        ]      ,     dtype=tf.floataa      ,     )

    self.assertTrue(np.allclose(output[:, :3, :3].numpy()      ,     expected_slice.numpy()      ,     atol=1E-4						)						)





'''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  SCREAMING_SNAKE_CASE :






    """simple docstring"""





    def __init__(  self      :					Any  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					Any=2  ,						UpperCamelCase__      :					Union[str, Any]=8  ,						UpperCamelCase__      :					List[Any]=True  ,						UpperCamelCase__      :					Any=True  ,						UpperCamelCase__      :					str=True  ,						UpperCamelCase__      :					Dict=True  ,						UpperCamelCase__      :					List[Any]=9_9  ,						UpperCamelCase__      :					List[Any]=1_6  ,						UpperCamelCase__      :					List[str]=5  ,						UpperCamelCase__      :					Dict=2  ,						UpperCamelCase__      :					Optional[int]=3_6  ,						UpperCamelCase__      :					str="gelu"  ,						UpperCamelCase__      :					Dict=0.0  ,						UpperCamelCase__      :					Dict=0.0  ,						UpperCamelCase__      :					Optional[int]=5_1_2  ,						UpperCamelCase__      :					Dict=1_6  ,						UpperCamelCase__      :					List[str]=2  ,						UpperCamelCase__      :					Any=0.0_2  ,						UpperCamelCase__      :					str=3  ,						UpperCamelCase__      :					Tuple=4  ,						UpperCamelCase__      :					Union[str, Any]=None  ,						):


       """simple docstring"""







       UpperCamelCase					=  parent
       UpperCamelCase					=  batch_size
       UpperCamelCase					=  seq_length
       UpperCamelCase					=  is_training
       UpperCamelCase					=  use_input_mask
       UpperCamelCase					=  use_token_type_ids
       UpperCamelCase					=  use_labels
       UpperCamelCase					=  vocab_size
       UpperCamelCase					=  hidden_size
       UpperCamelCase					=  num_hidden_layers
       UpperCamelCase					=  num_attention_heads
       UpperCamelCase					=  intermediate_size
       UpperCamelCase					=  hidden_act
       UpperCamelCase					=  hidden_dropout_prob
       UpperCamelCase					=  attention_probs_dropout_prob
       UpperCamelCase					=  max_position_embeddings
       UpperCamelCase					=  type_vocab_size
       UpperCamelCase					=  type_sequence_label_size
       UpperCamelCase					=  initializer_range
       UpperCamelCase					=  num_labels
       UpperCamelCase					=  num_choices
       UpperCamelCase					=  scope






    def  A       (  self      :					int ):


       """simple docstring"""







       UpperCamelCase					=  ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size )

       UpperCamelCase					=  None
       if self.use_input_mask:
          UpperCamelCase					=  random_attention_mask([self.batch_size, self.seq_length] )

       UpperCamelCase					=  None
       if self.use_token_type_ids:
          UpperCamelCase					=  ids_tensor([self.batch_size, self.seq_length]  ,						self.type_vocab_size )

       UpperCamelCase					=  None
       UpperCamelCase					=  None
       UpperCamelCase					=  None
       if self.use_labels:
          UpperCamelCase					=  ids_tensor([self.batch_size]  ,						self.type_sequence_label_size )
          UpperCamelCase					=  ids_tensor([self.batch_size, self.seq_length]  ,						self.num_labels )
          UpperCamelCase					=  ids_tensor([self.batch_size]  ,						self.num_choices )

       UpperCamelCase					=  self.get_config()

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






    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







       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=UpperCamelCase__  ,						initializer_range=self.initializer_range  ,						)






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  self.get_config()
       UpperCamelCase					=  3_0_0
       return config






    def  A       (  self      :					Tuple ):


       """simple docstring"""







       (
           (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      
       )					=  self.prepare_config_and_inputs()

       UpperCamelCase					=  True
       UpperCamelCase					=  floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
       UpperCamelCase					=  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  A       (  self      :					Tuple  ,						UpperCamelCase__      :					Tuple  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					List[str]  ,						UpperCamelCase__      :					Dict ):


       """simple docstring"""







       UpperCamelCase					=  MraModel(config=UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__ )
       UpperCamelCase					=  model(UpperCamelCase__  ,						token_type_ids=UpperCamelCase__ )
       UpperCamelCase					=  model(UpperCamelCase__ )
       self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size) )






    def  A       (  self      :					List[str]  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					str  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					Optional[Any]  ,						):


       """simple docstring"""







       UpperCamelCase					=  True
       UpperCamelCase					=  MraModel(UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(
           UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						encoder_hidden_states=UpperCamelCase__  ,						encoder_attention_mask=UpperCamelCase__  ,						)
       UpperCamelCase					=  model(
           UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						encoder_hidden_states=UpperCamelCase__  ,						)
       UpperCamelCase					=  model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__ )
       self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size) )






    def  A       (  self      :					int  ,						UpperCamelCase__      :					Optional[int]  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					List[str]  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  MraForMaskedLM(config=UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						labels=UpperCamelCase__ )
       self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size) )






    def  A       (  self      :					Any  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					List[str]  ,						UpperCamelCase__      :					Tuple  ,						UpperCamelCase__      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  MraForQuestionAnswering(config=UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(
           UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						start_positions=UpperCamelCase__  ,						end_positions=UpperCamelCase__  ,						)
       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  A       (  self      :					Optional[int]  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					Tuple  ,						UpperCamelCase__      :					Optional[int]  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					Optional[Any]  ,						UpperCamelCase__      :					Tuple ):


       """simple docstring"""







       UpperCamelCase					=  self.num_labels
       UpperCamelCase					=  MraForSequenceClassification(UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						labels=UpperCamelCase__ )
       self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels) )






    def  A       (  self      :					Any  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					str  ,						UpperCamelCase__      :					List[Any]  ,						UpperCamelCase__      :					Optional[int]  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  self.num_labels
       UpperCamelCase					=  MraForTokenClassification(config=UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  model(UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						labels=UpperCamelCase__ )
       self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.num_labels) )






    def  A       (  self      :					int  ,						UpperCamelCase__      :					Optional[Any]  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					Optional[int]  ,						UpperCamelCase__      :					Tuple  ,						UpperCamelCase__      :					Dict  ,						UpperCamelCase__      :					str  ,						UpperCamelCase__      :					Dict ):


       """simple docstring"""







       UpperCamelCase					=  self.num_choices
       UpperCamelCase					=  MraForMultipleChoice(config=UpperCamelCase__ )
       model.to(UpperCamelCase__ )
       model.eval()
       UpperCamelCase					=  input_ids.unsqueeze(1 ).expand(-1  ,						self.num_choices  ,						-1 ).contiguous()
       UpperCamelCase					=  token_type_ids.unsqueeze(1 ).expand(-1  ,						self.num_choices  ,						-1 ).contiguous()
       UpperCamelCase					=  input_mask.unsqueeze(1 ).expand(-1  ,						self.num_choices  ,						-1 ).contiguous()
       UpperCamelCase					=  model(
           UpperCamelCase__  ,						attention_mask=UpperCamelCase__  ,						token_type_ids=UpperCamelCase__  ,						labels=UpperCamelCase__  ,						)
       self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_choices) )






    def  A       (  self      :					int ):


       """simple docstring"""







       UpperCamelCase					=  self.prepare_config_and_inputs()
       (
           (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      (
           UpperCamelCase
       )				,      
       )					=  config_and_inputs
       UpperCamelCase					=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
       return config, inputs_dict

@require_torch
class  SCREAMING_SNAKE_CASE (  _a   ,						unittest.TestCase		):






    """simple docstring"""





    _SCREAMING_SNAKE_CASE	  =  (
        (
            MraModel,
            MraForMaskedLM,
            MraForMultipleChoice,
            MraForQuestionAnswering,
            MraForSequenceClassification,
            MraForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    _SCREAMING_SNAKE_CASE	  =  False
    _SCREAMING_SNAKE_CASE	  =  False
    _SCREAMING_SNAKE_CASE	  =  False
    _SCREAMING_SNAKE_CASE	  =  False

    _SCREAMING_SNAKE_CASE	  =  ()






    def  A       (  self      :					str ):


       """simple docstring"""







       UpperCamelCase					=  MraModelTester(self )
       UpperCamelCase					=  ConfigTester(self  ,						config_class=UpperCamelCase__  ,						hidden_size=3_7 )






    def  A       (  self      :					str ):


       """simple docstring"""







       self.config_tester.run_common_tests()






    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__ )






    def  A       (  self      :					str ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
          UpperCamelCase					=  type
          self.model_tester.create_and_check_model(*UpperCamelCase__ )






    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__ )






    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__ )






    def  A       (  self      :					Tuple ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__ )






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__ )






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__ )






    @slow
    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          UpperCamelCase					=  MraModel.from_pretrained(UpperCamelCase__ )
          self.assertIsNotNone(UpperCamelCase__ )






    @unittest.skip(reason='MRA does not output attentions' )
    def  A       (  self      :					List[str] ):


       """simple docstring"""







       return

@require_torch
class  SCREAMING_SNAKE_CASE (  unittest.TestCase		):






    """simple docstring"""





    @slow
    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







       UpperCamelCase					=  MraModel.from_pretrained('uw-madison/mra-base-512-4' )
       UpperCamelCase					=  torch.arange(2_5_6 ).unsqueeze(0 )

       with torch.no_grad():
          UpperCamelCase					=  model(UpperCamelCase__ )[0]

       UpperCamelCase					=  torch.Size((1, 2_5_6, 7_6_8) )
       self.assertEqual(output.shape  ,						UpperCamelCase__ )

       UpperCamelCase					=  torch.tensor(
           [[[-0.0_1_4_0, 0.0_8_3_0, -0.0_3_8_1], [0.1_5_4_6, 0.1_4_0_2, 0.0_2_2_0], [0.1_1_6_2, 0.0_8_5_1, 0.0_1_6_5]]] )

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






    @slow
    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       UpperCamelCase					=  MraForMaskedLM.from_pretrained('uw-madison/mra-base-512-4' )
       UpperCamelCase					=  torch.arange(2_5_6 ).unsqueeze(0 )

       with torch.no_grad():
          UpperCamelCase					=  model(UpperCamelCase__ )[0]

       UpperCamelCase					=  5_0_2_6_5

       UpperCamelCase					=  torch.Size((1, 2_5_6, vocab_size) )
       self.assertEqual(output.shape  ,						UpperCamelCase__ )

       UpperCamelCase					=  torch.tensor(
           [[[9.2_5_9_5, -3.6_0_3_8, 1_1.8_8_1_9], [9.3_8_6_9, -3.2_6_9_3, 1_1.0_9_5_6], [1_1.8_5_2_4, -3.4_9_3_8, 1_3.1_2_1_0]]] )

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






    @slow
    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       UpperCamelCase					=  MraForMaskedLM.from_pretrained('uw-madison/mra-base-4096-8-d3' )
       UpperCamelCase					=  torch.arange(4_0_9_6 ).unsqueeze(0 )

       with torch.no_grad():
          UpperCamelCase					=  model(UpperCamelCase__ )[0]

       UpperCamelCase					=  5_0_2_6_5

       UpperCamelCase					=  torch.Size((1, 4_0_9_6, vocab_size) )
       self.assertEqual(output.shape  ,						UpperCamelCase__ )

       UpperCamelCase					=  torch.tensor(
           [[[5.4_7_8_9, -2.3_5_6_4, 7.5_0_6_4], [7.9_0_6_7, -1.3_3_6_9, 9.9_6_6_8], [9.0_7_1_2, -1.8_1_0_6, 7.0_3_8_0]]] )

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

