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




					"""simple docstring"""

					def __init__(				self   :	str    ,lowerCamelCase__   :	Union[str, Any]    ,lowerCamelCase__   :	Tuple=2    ,lowerCamelCase__   :	Any=8    ,lowerCamelCase__   :	Tuple=True    ,lowerCamelCase__   :	Optional[Any]=True    ,lowerCamelCase__   :	str=True    ,lowerCamelCase__   :	List[str]=True    ,lowerCamelCase__   :	Tuple=99    ,lowerCamelCase__   :	List[Any]=16    ,lowerCamelCase__   :	Union[str, Any]=5    ,lowerCamelCase__   :	Tuple=2    ,lowerCamelCase__   :	Optional[int]=36    ,lowerCamelCase__   :	Optional[Any]="gelu"    ,lowerCamelCase__   :	Dict=0.0    ,lowerCamelCase__   :	Any=0.0    ,lowerCamelCase__   :	Optional[Any]=512    ,lowerCamelCase__   :	Tuple=16    ,lowerCamelCase__   :	int=2    ,lowerCamelCase__   :	str=0.0_2    ,lowerCamelCase__   :	str=3    ,lowerCamelCase__   :	Optional[Any]=4    ,lowerCamelCase__   :	Tuple=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 		__lowerCAmelCase						(				self   :	int			):
									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 		__lowerCAmelCase						(				self   :	int			):
									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=lowerCamelCase__    ,initializer_range=self.initializer_range    ,)







					def 		__lowerCAmelCase						(				self   :	Union[str, Any]			):
									UpperCAmelCase__             =							self.get_config()
									UpperCAmelCase__             =							300
									return config







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







					def 		__lowerCAmelCase						(				self   :	Tuple    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Any    ,lowerCamelCase__   :	List[str]    ,lowerCamelCase__   :	Any    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Optional[int]    ,lowerCamelCase__   :	List[Any]    ,lowerCamelCase__   :	Any    ,lowerCamelCase__   :	Optional[Any]    ,):
									UpperCAmelCase__             =							True
									UpperCAmelCase__             =							MraModel(lowerCamelCase__			)
									model.to(lowerCamelCase__			)
									model.eval()
									UpperCAmelCase__             =							model(
									    lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__    ,encoder_hidden_states=lowerCamelCase__    ,encoder_attention_mask=lowerCamelCase__    ,)
									UpperCAmelCase__             =							model(
									    lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__    ,encoder_hidden_states=lowerCamelCase__    ,)
									UpperCAmelCase__             =							model(lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__			)
									self.parent.assertEqual(result.last_hidden_state.shape    ,(self.batch_size, self.seq_length, self.hidden_size)			)







					def 		__lowerCAmelCase						(				self   :	Optional[int]    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	str    ,lowerCamelCase__   :	List[str]    ,lowerCamelCase__   :	Optional[int]    ,lowerCamelCase__   :	List[str]    ,lowerCamelCase__   :	str    ,lowerCamelCase__   :	Any			):
									UpperCAmelCase__             =							MraForMaskedLM(config=lowerCamelCase__			)
									model.to(lowerCamelCase__			)
									model.eval()
									UpperCAmelCase__             =							model(lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__    ,labels=lowerCamelCase__			)
									self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.seq_length, self.vocab_size)			)







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







					def 		__lowerCAmelCase						(				self   :	Union[str, Any]    ,lowerCamelCase__   :	int    ,lowerCamelCase__   :	List[str]    ,lowerCamelCase__   :	int    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	int    ,lowerCamelCase__   :	int    ,lowerCamelCase__   :	int			):
									UpperCAmelCase__             =							self.num_labels
									UpperCAmelCase__             =							MraForTokenClassification(config=lowerCamelCase__			)
									model.to(lowerCamelCase__			)
									model.eval()
									UpperCAmelCase__             =							model(lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__    ,labels=lowerCamelCase__			)
									self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.seq_length, self.num_labels)			)







					def 		__lowerCAmelCase						(				self   :	int    ,lowerCamelCase__   :	List[Any]    ,lowerCamelCase__   :	List[Any]    ,lowerCamelCase__   :	List[Any]    ,lowerCamelCase__   :	Tuple    ,lowerCamelCase__   :	Union[str, Any]    ,lowerCamelCase__   :	str    ,lowerCamelCase__   :	List[str]			):
									UpperCAmelCase__             =							self.num_choices
									UpperCAmelCase__             =							MraForMultipleChoice(config=lowerCamelCase__			)
									model.to(lowerCamelCase__			)
									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(
									    lowerCamelCase__    ,attention_mask=lowerCamelCase__    ,token_type_ids=lowerCamelCase__    ,labels=lowerCamelCase__    ,)
									self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.num_choices)			)







					def 		__lowerCAmelCase						(				self   :	List[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 				snake_case       ( __UpperCAmelCase      ,    unittest.TestCase				):




					"""simple docstring"""

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

					snake_case__				    = ()







					def 		__lowerCAmelCase						(				self   :	Dict			):
									UpperCAmelCase__             =							MraModelTester(self			)
									UpperCAmelCase__             =							ConfigTester(self    ,config_class=lowerCamelCase__    ,hidden_size=37			)







					def 		__lowerCAmelCase						(				self   :	Any			):
									self.config_tester.run_common_tests()







					def 		__lowerCAmelCase						(				self   :	int			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	int			):
									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(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[str]			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	List[Any]			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	int			):
									UpperCAmelCase__             =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__			)







					@slow
					def 		__lowerCAmelCase						(				self   :	Any			):
									for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCAmelCase__             =							MraModel.from_pretrained(lowerCamelCase__			)
													self.assertIsNotNone(lowerCamelCase__			)







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






@require_torch
class 				snake_case       ( unittest.TestCase				):




					"""simple docstring"""

					@slow
					def 		__lowerCAmelCase						(				self   :	Optional[int]			):
									UpperCAmelCase__             =							MraModel.from_pretrained('uw-madison/mra-base-512-4'			)
									UpperCAmelCase__             =							torch.arange(256			).unsqueeze(0			)

									with torch.no_grad():
													UpperCAmelCase__             =							model(lowerCamelCase__			)[0]

									UpperCAmelCase__             =							torch.Size((1, 256, 768)			)
									self.assertEqual(output.shape    ,lowerCamelCase__			)

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







					@slow
					def 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							MraForMaskedLM.from_pretrained('uw-madison/mra-base-512-4'			)
									UpperCAmelCase__             =							torch.arange(256			).unsqueeze(0			)

									with torch.no_grad():
													UpperCAmelCase__             =							model(lowerCamelCase__			)[0]

									UpperCAmelCase__             =							50_265

									UpperCAmelCase__             =							torch.Size((1, 256, vocab_size)			)
									self.assertEqual(output.shape    ,lowerCamelCase__			)

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







					@slow
					def 		__lowerCAmelCase						(				self   :	Any			):
									UpperCAmelCase__             =							MraForMaskedLM.from_pretrained('uw-madison/mra-base-4096-8-d3'			)
									UpperCAmelCase__             =							torch.arange(4_096			).unsqueeze(0			)

									with torch.no_grad():
													UpperCAmelCase__             =							model(lowerCamelCase__			)[0]

									UpperCAmelCase__             =							50_265

									UpperCAmelCase__             =							torch.Size((1, 4_096, vocab_size)			)
									self.assertEqual(output.shape    ,lowerCamelCase__			)

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




"""simple docstring"""






def   a_						(					lowerCamelCase       ):
				return str(lowerCamelCase       ) == str(lowerCamelCase       )[::-1]



def   a_						(					lowerCamelCase       ):
				return int(lowerCamelCase       ) + int(str(lowerCamelCase       )[::-1]       )



def   a_						(					lowerCamelCase = 1_0_0_0_0       ):
				UpperCAmelCase__             =							[]
				for num in range(1					,			lowerCamelCase       ):
								UpperCAmelCase__             =							0
								UpperCAmelCase__             =							num
								while iterations < 5_0:
												UpperCAmelCase__             =							sum_reverse(lowerCamelCase       )
												iterations += 1
												if is_palindrome(lowerCamelCase       ):
																break
								else:
												lychrel_nums.append(lowerCamelCase       )
				return len(lowerCamelCase       )


if __name__ == "__main__":
						print(F"""{solution() = }""")



