





'''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       :    List[Any]	,			snake_case_       :    Optional[int]	,			snake_case_       :    Any=2	,			snake_case_       :    Optional[Any]=8	,			snake_case_       :    Union[str, Any]=True	,			snake_case_       :    Optional[Any]=True	,			snake_case_       :    Optional[Any]=True	,			snake_case_       :    int=True	,			snake_case_       :    int=9_9	,			snake_case_       :    Optional[Any]=1_6	,			snake_case_       :    Union[str, Any]=5	,			snake_case_       :    Optional[Any]=2	,			snake_case_       :    List[Any]=3_6	,			snake_case_       :    str="gelu"	,			snake_case_       :    Optional[int]=0.0	,			snake_case_       :    Dict=0.0	,			snake_case_       :    str=5_1_2	,			snake_case_       :    str=1_6	,			snake_case_       :    Tuple=2	,			snake_case_       :    Optional[int]=0.0_2	,			snake_case_       :    Dict=3	,			snake_case_       :    Union[str, Any]=4	,			snake_case_       :    List[Any]=None	,			):
      _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      lowercase	(					self       :    Union[str, Any]    ):
      _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      lowercase	(					self       :    str    ):
      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]    ):
      _UpperCAmelCase     							=   self.get_config()
      _UpperCAmelCase     							=   3_0_0
      return config




 def      lowercase	(					self       :    Union[str, Any]    ):
      (
          (
          _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      lowercase	(					self       :    Optional[int]	,			snake_case_       :    Tuple	,			snake_case_       :    str	,			snake_case_       :    Dict	,			snake_case_       :    Any	,			snake_case_       :    Union[str, Any]	,			snake_case_       :    Optional[Any]	,			snake_case_       :    List[Any]    ):
      _UpperCAmelCase     							=   MraModel(config=snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   model(snake_case_	,			attention_mask=snake_case_	,			token_type_ids=snake_case_    )
      _UpperCAmelCase     							=   model(snake_case_	,			token_type_ids=snake_case_    )
      _UpperCAmelCase     							=   model(snake_case_    )
      self.parent.assertEqual(result.last_hidden_state.shape	,			(self.batch_size, self.seq_length, self.hidden_size)    )




 def      lowercase	(					self       :    int	,			snake_case_       :    Optional[Any]	,			snake_case_       :    Any	,			snake_case_       :    Optional[Any]	,			snake_case_       :    List[str]	,			snake_case_       :    str	,			snake_case_       :    Tuple	,			snake_case_       :    Any	,			snake_case_       :    Tuple	,			snake_case_       :    Any	,			):
      _UpperCAmelCase     							=   True
      _UpperCAmelCase     							=   MraModel(snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   model(
          snake_case_	,			attention_mask=snake_case_	,			token_type_ids=snake_case_	,			encoder_hidden_states=snake_case_	,			encoder_attention_mask=snake_case_	,			)
      _UpperCAmelCase     							=   model(
          snake_case_	,			attention_mask=snake_case_	,			token_type_ids=snake_case_	,			encoder_hidden_states=snake_case_	,			)
      _UpperCAmelCase     							=   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       :    str	,			snake_case_       :    int	,			snake_case_       :    List[str]	,			snake_case_       :    Optional[int]	,			snake_case_       :    Any	,			snake_case_       :    str	,			snake_case_       :    Union[str, Any]	,			snake_case_       :    List[str]    ):
      _UpperCAmelCase     							=   MraForMaskedLM(config=snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   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       :    List[Any]	,			snake_case_       :    Any	,			snake_case_       :    Any	,			snake_case_       :    str	,			snake_case_       :    Optional[int]	,			snake_case_       :    Union[str, Any]	,			snake_case_       :    List[Any]	,			snake_case_       :    Dict    ):
      _UpperCAmelCase     							=   MraForQuestionAnswering(config=snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   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_       :    Dict	,			snake_case_       :    int	,			snake_case_       :    Union[str, Any]	,			snake_case_       :    List[Any]	,			snake_case_       :    List[Any]	,			snake_case_       :    Optional[Any]	,			snake_case_       :    Union[str, Any]    ):
      _UpperCAmelCase     							=   self.num_labels
      _UpperCAmelCase     							=   MraForSequenceClassification(snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   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       :    Union[str, Any]	,			snake_case_       :    List[Any]	,			snake_case_       :    List[str]	,			snake_case_       :    Optional[Any]	,			snake_case_       :    List[Any]	,			snake_case_       :    Tuple	,			snake_case_       :    Optional[Any]	,			snake_case_       :    List[Any]    ):
      _UpperCAmelCase     							=   self.num_labels
      _UpperCAmelCase     							=   MraForTokenClassification(config=snake_case_    )
      model.to(snake_case_    )
      model.eval()
      _UpperCAmelCase     							=   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       :    Optional[int]	,			snake_case_       :    Optional[int]	,			snake_case_       :    Tuple	,			snake_case_       :    Tuple	,			snake_case_       :    Optional[Any]	,			snake_case_       :    Tuple	,			snake_case_       :    List[str]	,			snake_case_       :    Optional[int]    ):
      _UpperCAmelCase     							=   self.num_choices
      _UpperCAmelCase     							=   MraForMultipleChoice(config=snake_case_    )
      model.to(snake_case_    )
      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(
          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]    ):
      _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   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Tuple           =							(
     (
         MraModel,
         MraForMaskedLM,
         MraForMultipleChoice,
         MraForQuestionAnswering,
         MraForSequenceClassification,
         MraForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 _lowerCamelCase  : List[Any]           =							False
 _lowerCamelCase  : str           =							False
 _lowerCamelCase  : List[str]           =							False
 _lowerCamelCase  : Dict           =							False

 _lowerCamelCase  : Dict           =							()




 def      lowercase	(					self       :    Union[str, Any]    ):
      _UpperCAmelCase     							=   MraModelTester(self    )
      _UpperCAmelCase     							=   ConfigTester(self	,			config_class=snake_case_	,			hidden_size=3_7    )




 def      lowercase	(					self       :    List[Any]    ):
      self.config_tester.run_common_tests()




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*snake_case_    )




 def      lowercase	(					self       :    Optional[Any]    ):
      _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(*snake_case_    )




 def      lowercase	(					self       :    Union[str, Any]    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*snake_case_    )




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*snake_case_    )




 def      lowercase	(					self       :    Optional[Any]    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*snake_case_    )




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*snake_case_    )




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase     							=   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*snake_case_    )




 @slow
 def      lowercase	(					self       :    Optional[int]    ):
      for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           _UpperCAmelCase     							=   MraModel.from_pretrained(snake_case_    )
           self.assertIsNotNone(snake_case_    )




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







@require_torch
class   A_	(  unittest.TestCase			):




 @slow
 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   MraModel.from_pretrained("uw-madison/mra-base-512-4"    )
      _UpperCAmelCase     							=   torch.arange(2_5_6    ).unsqueeze(0    )

      with torch.no_grad():
           _UpperCAmelCase     							=   model(snake_case_    )[0]

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

      _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]	,			snake_case_	,			atol=1e-4    )    )




 @slow
 def      lowercase	(					self       :    str    ):
      _UpperCAmelCase     							=   MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"    )
      _UpperCAmelCase     							=   torch.arange(2_5_6    ).unsqueeze(0    )

      with torch.no_grad():
           _UpperCAmelCase     							=   model(snake_case_    )[0]

      _UpperCAmelCase     							=   5_0_2_6_5

      _UpperCAmelCase     							=   torch.Size((1, 2_5_6, vocab_size)    )
      self.assertEqual(output.shape	,			snake_case_    )

      _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]	,			snake_case_	,			atol=1e-4    )    )




 @slow
 def      lowercase	(					self       :    int    ):
      _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(snake_case_    )[0]

      _UpperCAmelCase     							=   5_0_2_6_5

      _UpperCAmelCase     							=   torch.Size((1, 4_0_9_6, vocab_size)    )
      self.assertEqual(output.shape	,			snake_case_    )

      _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]	,			snake_case_	,			atol=1e-4    )    )











'''simple docstring'''




def 	UpperCAmelCase_							(					__lowercase							:      str       )		->       list:


     '''simple docstring'''



     if n_term == "":
          return []
     _UpperCAmelCase     							=   []
     for temp in range(int(__lowercase       )       ):
          series.append(f'1/{temp + 1}' if series else "1"       )
     return series


if __name__ == "__main__":
  __SCREAMING_SNAKE_CASE     :str       =				input('''Enter the last number (nth term) of the Harmonic Series''')
  print('''Formula of Harmonic Series => 1+1/2+1/3 ..... 1/n''')
  print(harmonic_series(nth_term))




