




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:






    """simple docstring"""





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





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							int       =      ids_tensor([self.batch_size, self.seq_length]       ,self.vocab_size  )

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

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

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

         UpperCAmelCase_      :							str       =      self.get_config()

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





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





    def 							a__				(				self  )			->		Union[str, Any]:
         UpperCAmelCase_      :							Optional[int]       =      self.get_config()
         UpperCAmelCase_      :							List[str]       =      300
         return config





    def 							a__				(				self  )			->		Tuple:
         (
             (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   
         )      :							int       =      self.prepare_config_and_inputs()

         UpperCAmelCase_      :							List[Any]       =      True
         UpperCAmelCase_      :							Optional[Any]       =      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]  )
         UpperCAmelCase_      :							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 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[Any]:
         UpperCAmelCase_      :							List[str]       =      MraModel(config=_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							Optional[int]       =      model(_SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Any       =      model(_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Optional[Any]       =      model(_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.last_hidden_state.shape       ,(self.batch_size, self.seq_length, self.hidden_size)  )





    def 							a__				(				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       ,)			->		str:
         UpperCAmelCase_      :							Any       =      True
         UpperCAmelCase_      :							Union[str, Any]       =      MraModel(_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							List[Any]       =      model(
             _SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,encoder_hidden_states=_SCREAMING_SNAKE_CASE       ,encoder_attention_mask=_SCREAMING_SNAKE_CASE       ,)
         UpperCAmelCase_      :							Any       =      model(
             _SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,encoder_hidden_states=_SCREAMING_SNAKE_CASE       ,)
         UpperCAmelCase_      :							Tuple       =      model(_SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.last_hidden_state.shape       ,(self.batch_size, self.seq_length, self.hidden_size)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		str:
         UpperCAmelCase_      :							int       =      MraForMaskedLM(config=_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							Optional[Any]       =      model(_SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,labels=_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.vocab_size)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		Tuple:
         UpperCAmelCase_      :							str       =      MraForQuestionAnswering(config=_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							str       =      model(
             _SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,start_positions=_SCREAMING_SNAKE_CASE       ,end_positions=_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 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		str:
         UpperCAmelCase_      :							List[str]       =      self.num_labels
         UpperCAmelCase_      :							Any       =      MraForSequenceClassification(_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							Union[str, Any]       =      model(_SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,labels=_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)  )





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		str:
         UpperCAmelCase_      :							Optional[int]       =      self.num_labels
         UpperCAmelCase_      :							Any       =      MraForTokenClassification(config=_SCREAMING_SNAKE_CASE  )
         model.to(_SCREAMING_SNAKE_CASE  )
         model.eval()
         UpperCAmelCase_      :							str       =      model(_SCREAMING_SNAKE_CASE       ,attention_mask=_SCREAMING_SNAKE_CASE       ,token_type_ids=_SCREAMING_SNAKE_CASE       ,labels=_SCREAMING_SNAKE_CASE  )
         self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.num_labels)  )





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





    def 							a__				(				self  )			->		List[str]:
         UpperCAmelCase_      :							str       =      self.prepare_config_and_inputs()
         (
             (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   (
             UpperCAmelCase_
         ),   
         )      :							Optional[Any]       =      config_and_inputs
         UpperCAmelCase_      :							int       =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict


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






    """simple docstring"""





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

    lowerCAmelCase        =				()





    def 							a__				(				self  )			->		Any:
         UpperCAmelCase_      :							str       =      MraModelTester(self  )
         UpperCAmelCase_      :							int       =      ConfigTester(self       ,config_class=_SCREAMING_SNAKE_CASE       ,hidden_size=37  )





    def 							a__				(				self  )			->		Optional[Any]:
         self.config_tester.run_common_tests()





    def 							a__				(				self  )			->		List[str]:
         UpperCAmelCase_      :							Dict       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		List[str]:
         UpperCAmelCase_      :							Optional[Any]       =      self.model_tester.prepare_config_and_inputs()
         for type in ["absolute", "relative_key", "relative_key_query"]:
              UpperCAmelCase_      :							Optional[Any]       =      type
              self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							str       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Optional[Any]:
         UpperCAmelCase_      :							List[Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		str:
         UpperCAmelCase_      :							Optional[Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		str:
         UpperCAmelCase_      :							Optional[Any]       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							str       =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE  )





    @slow
    def 							a__				(				self  )			->		int:
         for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_      :							Optional[Any]       =      MraModel.from_pretrained(_SCREAMING_SNAKE_CASE  )
              self.assertIsNotNone(_SCREAMING_SNAKE_CASE  )





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


@require_torch
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    @slow
    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Dict       =      MraModel.from_pretrained('''uw-madison/mra-base-512-4'''  )
         UpperCAmelCase_      :							Any       =      torch.arange(256  ).unsqueeze(0  )

         with torch.no_grad():
              UpperCAmelCase_      :							Optional[Any]       =      model(_SCREAMING_SNAKE_CASE  )[0]

         UpperCAmelCase_      :							Optional[Any]       =      torch.Size((1, 256, 768)  )
         self.assertEqual(output.shape       ,_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							int       =      torch.tensor(
             [[[-0.01_40, 0.08_30, -0.03_81], [0.15_46, 0.14_02, 0.02_20], [0.11_62, 0.08_51, 0.01_65]]]  )

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





    @slow
    def 							a__				(				self  )			->		List[str]:
         UpperCAmelCase_      :							int       =      MraForMaskedLM.from_pretrained('''uw-madison/mra-base-512-4'''  )
         UpperCAmelCase_      :							Union[str, Any]       =      torch.arange(256  ).unsqueeze(0  )

         with torch.no_grad():
              UpperCAmelCase_      :							Optional[int]       =      model(_SCREAMING_SNAKE_CASE  )[0]

         UpperCAmelCase_      :							int       =      50_265

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

         UpperCAmelCase_      :							Tuple       =      torch.tensor(
             [[[9.25_95, -3.60_38, 11.88_19], [9.38_69, -3.26_93, 11.09_56], [11.85_24, -3.49_38, 13.12_10]]]  )

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





    @slow
    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							Tuple       =      MraForMaskedLM.from_pretrained('''uw-madison/mra-base-4096-8-d3'''  )
         UpperCAmelCase_      :							Dict       =      torch.arange(4_096  ).unsqueeze(0  )

         with torch.no_grad():
              UpperCAmelCase_      :							List[str]       =      model(_SCREAMING_SNAKE_CASE  )[0]

         UpperCAmelCase_      :							List[str]       =      50_265

         UpperCAmelCase_      :							List[Any]       =      torch.Size((1, 4_096, vocab_size)  )
         self.assertEqual(output.shape       ,_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Union[str, Any]       =      torch.tensor(
             [[[5.47_89, -2.35_64, 7.50_64], [7.90_67, -1.33_69, 9.96_68], [9.07_12, -1.81_06, 7.03_80]]]  )

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





from collections import defaultdict







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Optional[int]       =      first_str.lower().strip()
     UpperCAmelCase_      :							Any       =      second_str.lower().strip()

     # Remove whitespace
     UpperCAmelCase_      :							Any       =      first_str.replace(''' '''			,						''''''				)
     UpperCAmelCase_      :							int       =      second_str.replace(''' '''			,						''''''				)

     # Strings of different lengths are not anagrams
     if len(_lowercase				) != len(_lowercase				):
          return False

     # Default values for count should be 0
     UpperCAmelCase_      :							defaultdict[str, int]       =      defaultdict(_lowercase				)

     # For each character in input strings,
     # increment count in the corresponding
     for i in range(len(_lowercase				)				):
          count[first_str[i]] += 1
          count[second_str[i]] -= 1

     return all(_count == 0 for _count in count.values()				)


if __name__ == "__main__":
     from doctest import testmod

     testmod()
     __a          =			input('Enter the first string ').strip()
     __a          =			input('Enter the second string ').strip()

     __a          =			check_anagrams(input_a, input_b)
     print(F"""{input_a} and {input_b} are {"" if status else "not "}anagrams.""")