





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     lowercase__       :

   '''simple docstring'''


   def __init__(    self,		__magic_name__,		__magic_name__=2,		__magic_name__=8,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=99,		__magic_name__=16,		__magic_name__=5,		__magic_name__=2,		__magic_name__=36,		__magic_name__="gelu",		__magic_name__=0.0,		__magic_name__=0.0,		__magic_name__=512,		__magic_name__=16,		__magic_name__=2,		__magic_name__=0.02,		__magic_name__=3,		__magic_name__=4,		__magic_name__=None,		) ->      List[str]:






       """simple docstring"""
       UpperCamelCase__							:				str          =      parent
       UpperCamelCase__							:				Optional[Any]          =      batch_size
       UpperCamelCase__							:				Optional[Any]          =      seq_length
       UpperCamelCase__							:				Any          =      is_training
       UpperCamelCase__							:				List[str]          =      use_input_mask
       UpperCamelCase__							:				Union[str, Any]          =      use_token_type_ids
       UpperCamelCase__							:				str          =      use_labels
       UpperCamelCase__							:				Any          =      vocab_size
       UpperCamelCase__							:				Any          =      hidden_size
       UpperCamelCase__							:				int          =      num_hidden_layers
       UpperCamelCase__							:				Tuple          =      num_attention_heads
       UpperCamelCase__							:				Any          =      intermediate_size
       UpperCamelCase__							:				int          =      hidden_act
       UpperCamelCase__							:				Union[str, Any]          =      hidden_dropout_prob
       UpperCamelCase__							:				Union[str, Any]          =      attention_probs_dropout_prob
       UpperCamelCase__							:				int          =      max_position_embeddings
       UpperCamelCase__							:				Optional[int]          =      type_vocab_size
       UpperCamelCase__							:				Any          =      type_sequence_label_size
       UpperCamelCase__							:				int          =      initializer_range
       UpperCamelCase__							:				Optional[Any]          =      num_labels
       UpperCamelCase__							:				List[str]          =      num_choices
       UpperCamelCase__							:				List[str]          =      scope




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






       """simple docstring"""
       UpperCamelCase__							:				Any          =      ids_tensor([self.batch_size, self.seq_length],		self.vocab_size							)

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

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

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

       UpperCamelCase__							:				Tuple          =      self.get_config()

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




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




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      self.get_config()
       UpperCamelCase__							:				List[str]          =      300
       return config




   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       (
           (
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,
       )							:				Optional[int]          =      self.prepare_config_and_inputs()

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






       """simple docstring"""
       UpperCamelCase__							:				List[str]          =      MraModel(config=__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				List[str]          =      model(__magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__							)
       UpperCamelCase__							:				Union[str, Any]          =      model(__magic_name__,		token_type_ids=__magic_name__							)
       UpperCamelCase__							:				Any          =      model(__magic_name__							)
       self.parent.assertEqual(result.last_hidden_state.shape,		(self.batch_size, self.seq_length, self.hidden_size)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Tuple          =      True
       UpperCamelCase__							:				Any          =      MraModel(__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				Tuple          =      model(
           __magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		encoder_hidden_states=__magic_name__,		encoder_attention_mask=__magic_name__,		)
       UpperCamelCase__							:				Optional[int]          =      model(
           __magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		encoder_hidden_states=__magic_name__,		)
       UpperCamelCase__							:				List[Any]          =      model(__magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__							)
       self.parent.assertEqual(result.last_hidden_state.shape,		(self.batch_size, self.seq_length, self.hidden_size)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      MraForMaskedLM(config=__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				List[Any]          =      model(__magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		labels=__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.vocab_size)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				Dict          =      MraForQuestionAnswering(config=__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				Optional[int]          =      model(
           __magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		start_positions=__magic_name__,		end_positions=__magic_name__,		)
       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       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      self.num_labels
       UpperCamelCase__							:				int          =      MraForSequenceClassification(__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				List[Any]          =      model(__magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		labels=__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      self.num_labels
       UpperCamelCase__							:				List[Any]          =      MraForTokenClassification(config=__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				int          =      model(__magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		labels=__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      self.num_choices
       UpperCamelCase__							:				Optional[Any]          =      MraForMultipleChoice(config=__magic_name__							)
       model.to(__magic_name__							)
       model.eval()
       UpperCamelCase__							:				Optional[Any]          =      input_ids.unsqueeze(1							).expand(-1,		self.num_choices,		-1							).contiguous()
       UpperCamelCase__							:				Tuple          =      token_type_ids.unsqueeze(1							).expand(-1,		self.num_choices,		-1							).contiguous()
       UpperCamelCase__							:				Union[str, Any]          =      input_mask.unsqueeze(1							).expand(-1,		self.num_choices,		-1							).contiguous()
       UpperCamelCase__							:				List[Any]          =      model(
           __magic_name__,		attention_mask=__magic_name__,		token_type_ids=__magic_name__,		labels=__magic_name__,		)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)							)




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.prepare_config_and_inputs()
       (
           (
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,
       )							:				List[str]          =      config_and_inputs
       UpperCamelCase__							:				Tuple          =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_torch
class     lowercase__       (	__lowerCamelCase			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Any   		=		(
       (
           MraModel,
           MraForMaskedLM,
           MraForMultipleChoice,
           MraForQuestionAnswering,
           MraForSequenceClassification,
           MraForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   a						:							Optional[int]   		=		False
   a						:							Optional[int]   		=		False
   a						:							Dict   		=		False
   a						:							Optional[int]   		=		False

   a						:							Tuple   		=		()




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






       """simple docstring"""
       UpperCamelCase__							:				Dict          =      MraModelTester(self							)
       UpperCamelCase__							:				Union[str, Any]          =      ConfigTester(self,		config_class=__magic_name__,		hidden_size=37							)




   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       self.config_tester.run_common_tests()




   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
           UpperCamelCase__							:				Dict          =      type
           self.model_tester.create_and_check_model(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*__magic_name__							)




   @slow
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCamelCase__							:				Union[str, Any]          =      MraModel.from_pretrained(__magic_name__							)
           self.assertIsNotNone(__magic_name__							)




   @unittest.skip(reason='''MRA does not output attentions'''							)
   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       return






@require_torch
class     lowercase__       (	unittest.TestCase				):

   '''simple docstring'''


   @slow
   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      MraModel.from_pretrained('''uw-madison/mra-base-512-4'''							)
       UpperCamelCase__							:				Tuple          =      torch.arange(256							).unsqueeze(0							)

       with torch.no_grad():
           UpperCamelCase__							:				List[str]          =      model(__magic_name__							)[0]

       UpperCamelCase__							:				str          =      torch.Size((1, 256, 768)							)
       self.assertEqual(output.shape,		__magic_name__							)

       UpperCamelCase__							:				Union[str, Any]          =      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],		__magic_name__,		atol=1E-4							)							)




   @slow
   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				int          =      MraForMaskedLM.from_pretrained('''uw-madison/mra-base-512-4'''							)
       UpperCamelCase__							:				Optional[Any]          =      torch.arange(256							).unsqueeze(0							)

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

       UpperCamelCase__							:				Optional[int]          =      50265

       UpperCamelCase__							:				List[Any]          =      torch.Size((1, 256, vocab_size)							)
       self.assertEqual(output.shape,		__magic_name__							)

       UpperCamelCase__							:				Optional[int]          =      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],		__magic_name__,		atol=1E-4							)							)




   @slow
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      MraForMaskedLM.from_pretrained('''uw-madison/mra-base-4096-8-d3'''							)
       UpperCamelCase__							:				Optional[int]          =      torch.arange(4096							).unsqueeze(0							)

       with torch.no_grad():
           UpperCamelCase__							:				List[Any]          =      model(__magic_name__							)[0]

       UpperCamelCase__							:				Any          =      50265

       UpperCamelCase__							:				List[str]          =      torch.Size((1, 4096, vocab_size)							)
       self.assertEqual(output.shape,		__magic_name__							)

       UpperCamelCase__							:				Dict          =      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],		__magic_name__,		atol=1E-4							)							)








from __future__ import annotations




def 		lowerCAmelCase_    (  __UpperCAmelCase:			list[int]		,   __UpperCAmelCase:			int      )      ->	list[int]:
    UpperCamelCase__							:				Optional[int]          =      0
    UpperCamelCase__							:				Tuple          =      len(__UpperCAmelCase      ) - 1

    while i < j:
        if nums[i] + nums[j] == target:
            return [i, j]
        elif nums[i] + nums[j] < target:
            UpperCamelCase__							:				Tuple          =      i + 1
        else:
            UpperCamelCase__							:				str          =      j - 1

    return []


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  print(F'''{two_pointer([2, 7, 11, 15], 9) = }''')

