





"""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        _lowerCamelCase      :


						def __init__(self   ,							__a   ,							__a=2   ,							__a=8   ,							__a=True   ,							__a=True   ,							__a=True   ,							__a=True   ,							__a=99   ,							__a=16   ,							__a=5   ,							__a=2   ,							__a=36   ,							__a="gelu"   ,							__a=0.0   ,							__a=0.0   ,							__a=5_12   ,							__a=16   ,							__a=2   ,							__a=0.02   ,							__a=3   ,							__a=4   ,							__a=None   ,							) ->   Union[str, Any]:
								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     snake_case_   (self		) ->   List[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     snake_case_   (self		) ->   Tuple:
								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=__a   ,							initializer_range=self.initializer_range   ,							)


						def     snake_case_   (self		) ->   List[str]:
								UpperCamelCase   =	self.get_config()
								UpperCamelCase   =	3_00
								return config


						def     snake_case_   (self		) ->   int:
								(
								    (
								    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     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a		) ->   int:
								UpperCamelCase   =	MraModel(config=__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a   ,							attention_mask=__a   ,							token_type_ids=__a		)
								UpperCamelCase   =	model(__a   ,							token_type_ids=__a		)
								UpperCamelCase   =	model(__a		)
								self.parent.assertEqual(result.last_hidden_state.shape   ,							(self.batch_size, self.seq_length, self.hidden_size)		)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							) ->   str:
								UpperCamelCase   =	True
								UpperCamelCase   =	MraModel(__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(
								    __a   ,							attention_mask=__a   ,							token_type_ids=__a   ,							encoder_hidden_states=__a   ,							encoder_attention_mask=__a   ,							)
								UpperCamelCase   =	model(
								    __a   ,							attention_mask=__a   ,							token_type_ids=__a   ,							encoder_hidden_states=__a   ,							)
								UpperCamelCase   =	model(__a   ,							attention_mask=__a   ,							token_type_ids=__a		)
								self.parent.assertEqual(result.last_hidden_state.shape   ,							(self.batch_size, self.seq_length, self.hidden_size)		)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a		) ->   str:
								UpperCamelCase   =	MraForMaskedLM(config=__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a   ,							attention_mask=__a   ,							token_type_ids=__a   ,							labels=__a		)
								self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.seq_length, self.vocab_size)		)


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


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a		) ->   Tuple:
								UpperCamelCase   =	self.num_labels
								UpperCamelCase   =	MraForTokenClassification(config=__a		)
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a   ,							attention_mask=__a   ,							token_type_ids=__a   ,							labels=__a		)
								self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.seq_length, self.num_labels)		)


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a		) ->   List[Any]:
								UpperCamelCase   =	self.num_choices
								UpperCamelCase   =	MraForMultipleChoice(config=__a		)
								model.to(__a		)
								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(
								    __a   ,							attention_mask=__a   ,							token_type_ids=__a   ,							labels=__a   ,							)
								self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.num_choices)		)




						def     snake_case_   (self		) ->   Tuple:
								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        _lowerCamelCase      (       _lowercase  ,			unittest.TestCase ):
						UpperCAmelCase_ =			(
						    (
						        MraModel,
						        MraForMaskedLM,
						        MraForMultipleChoice,
						        MraForQuestionAnswering,
						        MraForSequenceClassification,
						        MraForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False
						UpperCAmelCase_ =			False

						UpperCAmelCase_ =			()


						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	MraModelTester(self		)
								UpperCamelCase   =	ConfigTester(self   ,							config_class=__a   ,							hidden_size=37		)


						def     snake_case_   (self		) ->   Dict:
								self.config_tester.run_common_tests()


						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__a		)


						def     snake_case_   (self		) ->   Union[str, 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(*__a		)


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*__a		)


						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*__a		)


						def     snake_case_   (self		) ->   List[Any]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*__a		)


						def     snake_case_   (self		) ->   List[str]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*__a		)


						def     snake_case_   (self		) ->   Dict:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*__a		)


						@slow
						def     snake_case_   (self		) ->   Optional[int]:
								for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										UpperCamelCase   =	MraModel.from_pretrained(__a		)
										self.assertIsNotNone(__a		)




						@unittest.skip(reason="MRA does not output attentions"		)
						def     snake_case_   (self		) ->   int:
								return





@require_torch
class        _lowerCamelCase      (       unittest.TestCase ):


						@slow
						def     snake_case_   (self		) ->   Dict:
								UpperCamelCase   =	MraModel.from_pretrained("uw-madison/mra-base-512-4"		)
								UpperCamelCase   =	torch.arange(2_56		).unsqueeze(0		)

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

								UpperCamelCase   =	torch.Size((1, 2_56, 7_68)		)
								self.assertEqual(output.shape   ,							__a		)

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


						@slow
						def     snake_case_   (self		) ->   Dict:
								UpperCamelCase   =	MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"		)
								UpperCamelCase   =	torch.arange(2_56		).unsqueeze(0		)

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

								UpperCamelCase   =	5_02_65

								UpperCamelCase   =	torch.Size((1, 2_56, vocab_size)		)
								self.assertEqual(output.shape   ,							__a		)

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




						@slow
						def     snake_case_   (self		) ->   Any:
								UpperCamelCase   =	MraForMaskedLM.from_pretrained("uw-madison/mra-base-4096-8-d3"		)
								UpperCamelCase   =	torch.arange(40_96		).unsqueeze(0		)

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

								UpperCamelCase   =	5_02_65

								UpperCamelCase   =	torch.Size((1, 40_96, vocab_size)		)
								self.assertEqual(output.shape   ,							__a		)

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













"""simple docstring"""





def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		UpperCamelCase   =	0
		for ch in input_str:
				UpperCamelCase   =	ord(_SCREAMING_SNAKE_CASE    )
				UpperCamelCase   =	pow(2  ,	_SCREAMING_SNAKE_CASE    )

				# If we already turned on bit for current character's unicode
				if bitmap >> ch_unicode & 1 == 1:
						return False
				bitmap |= ch_bit_index_on
		return True


if __name__ == "__main__":
						import doctest

						doctest.testmod()






