



'''simple docstring'''

from timeit import timeit

SCREAMING_SNAKE_CASE__     :						Optional[int]	=  {
    '''MALAYALAM''': True,
    '''String''': False,
    '''rotor''': True,
    '''level''': True,
    '''A''': True,
    '''BB''': True,
    '''ABC''': False,
    '''amanaplanacanalpanama''': True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())






def 				a  (     UpperCamelCase_    :    str			)       ->	bool:
		snake_case__	     =0
		snake_case__	     =len(UpperCamelCase_			) - 1
		while start_i < end_i:
				if s[start_i] == s[end_i]:
						start_i += 1
						end_i -= 1
				else:
						return False
		return True






def 				a  (     UpperCamelCase_    :    str			)       ->	bool:
		snake_case__	     =len(UpperCamelCase_			) // 2
		snake_case__	     =len(UpperCamelCase_			)

		# We need to traverse till half of the length of string
		# as we can get access of the i'th last element from
		# i'th index.
		# eg: [0,1,2,3,4,5] => 4th index can be accessed
		# with the help of 1st index (i==n-i-1)
		# where n is length of string
		return all(s[i] == s[n - i - 1] for i in range(UpperCamelCase_			)			)






def 				a  (     UpperCamelCase_    :    str			)       ->	bool:
		if len(UpperCamelCase_			) <= 2:
				return True
		if s[0] == s[len(UpperCamelCase_			) - 1]:
				return is_palindrome_recursive(s[1:-1]			)
		else:
				return False






def 				a  (     UpperCamelCase_    :    str			)       ->	bool:
		return s == s[::-1]






def 				a  (     UpperCamelCase_    :    str			)       ->	None:
		snake_case__	     =f"""all({name}(key) is value for key, value in test_data.items())"""
		snake_case__	     =f"""from __main__ import test_data, {name}"""
		snake_case__	     =500000
		snake_case__	     =timeit(stmt=UpperCamelCase_      ,					setup=UpperCamelCase_      ,					number=UpperCamelCase_			)
		print(f"""{name:<35} finished {number:,} runs in {result:.5f} seconds"""			)


if __name__ == "__main__":
			for key, value in test_data.items():
						assert is_palindrome(key) is is_palindrome_recursive(key)
						assert is_palindrome(key) is is_palindrome_slice(key)
						print(f"""{key:21} {value}""")
			print('''a man a plan a canal panama''')

			# finished 500,000 runs in 0.46793 seconds
			benchmark_function('''is_palindrome_slice''')
			# finished 500,000 runs in 0.85234 seconds
			benchmark_function('''is_palindrome''')
			# finished 500,000 runs in 1.32028 seconds
			benchmark_function('''is_palindrome_recursive''')
			# finished 500,000 runs in 2.08679 seconds
			benchmark_function('''is_palindrome_traversal''')









'''simple docstring'''

import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MODEL_FOR_PRETRAINING_MAPPING,
			    AlbertForMaskedLM,
			    AlbertForMultipleChoice,
			    AlbertForPreTraining,
			    AlbertForQuestionAnswering,
			    AlbertForSequenceClassification,
			    AlbertForTokenClassification,
			    AlbertModel,
			)
			from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST

class 							a__:






			def __init__(     self					,   _UpperCAmelCase					,   _UpperCAmelCase=13					,   _UpperCAmelCase=7					,   _UpperCAmelCase=True					,   _UpperCAmelCase=True					,   _UpperCAmelCase=True					,   _UpperCAmelCase=True					,   _UpperCAmelCase=99					,   _UpperCAmelCase=16					,   _UpperCAmelCase=36					,   _UpperCAmelCase=6					,   _UpperCAmelCase=6					,   _UpperCAmelCase=6					,   _UpperCAmelCase=37					,   _UpperCAmelCase="gelu"					,   _UpperCAmelCase=0.1					,   _UpperCAmelCase=0.1					,   _UpperCAmelCase=512					,   _UpperCAmelCase=16					,   _UpperCAmelCase=2					,   _UpperCAmelCase=0.02					,   _UpperCAmelCase=3					,   _UpperCAmelCase=4					,   _UpperCAmelCase=None					,   )							->							Dict:
					snake_case__	     =parent
					snake_case__	     =batch_size
					snake_case__	     =seq_length
					snake_case__	     =is_training
					snake_case__	     =use_input_mask
					snake_case__	     =use_token_type_ids
					snake_case__	     =use_labels
					snake_case__	     =vocab_size
					snake_case__	     =embedding_size
					snake_case__	     =hidden_size
					snake_case__	     =num_hidden_layers
					snake_case__	     =num_hidden_groups
					snake_case__	     =num_attention_heads
					snake_case__	     =intermediate_size
					snake_case__	     =hidden_act
					snake_case__	     =hidden_dropout_prob
					snake_case__	     =attention_probs_dropout_prob
					snake_case__	     =max_position_embeddings
					snake_case__	     =type_vocab_size
					snake_case__	     =type_sequence_label_size
					snake_case__	     =initializer_range
					snake_case__	     =num_labels
					snake_case__	     =num_choices
					snake_case__	     =scope






			def 						_lowercase  (     self						)							->							Tuple:
					snake_case__	     =ids_tensor([self.batch_size, self.seq_length]					,   self.vocab_size						)

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

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

					snake_case__	     =None
					snake_case__	     =None
					snake_case__	     =None
					if self.use_labels:
							snake_case__	     =ids_tensor([self.batch_size]					,   self.type_sequence_label_size						)
							snake_case__	     =ids_tensor([self.batch_size, self.seq_length]					,   self.num_labels						)
							snake_case__	     =ids_tensor([self.batch_size]					,   self.num_choices						)

					snake_case__	     =self.get_config()

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






			def 						_lowercase  (     self						)							->							Union[str, Any]:
					return AlbertConfig(
					    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					,   initializer_range=self.initializer_range					,   num_hidden_groups=self.num_hidden_groups					,   )






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							List[str]:
					snake_case__	     =AlbertModel(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase						)
					snake_case__	     =model(_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase						)
					snake_case__	     =model(_UpperCAmelCase						)
					self.parent.assertEqual(result.last_hidden_state.shape					,   (self.batch_size, self.seq_length, self.hidden_size)						)
					self.parent.assertEqual(result.pooler_output.shape					,   (self.batch_size, self.hidden_size)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Dict:
					snake_case__	     =AlbertForPreTraining(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(
					    _UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   labels=_UpperCAmelCase					,   sentence_order_label=_UpperCAmelCase					,   )
					self.parent.assertEqual(result.prediction_logits.shape					,   (self.batch_size, self.seq_length, self.vocab_size)						)
					self.parent.assertEqual(result.sop_logits.shape					,   (self.batch_size, config.num_labels)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							List[str]:
					snake_case__	     =AlbertForMaskedLM(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   labels=_UpperCAmelCase						)
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.seq_length, self.vocab_size)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							List[str]:
					snake_case__	     =AlbertForQuestionAnswering(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(
					    _UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   start_positions=_UpperCAmelCase					,   end_positions=_UpperCAmelCase					,   )
					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					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Optional[int]:
					snake_case__	     =self.num_labels
					snake_case__	     =AlbertForSequenceClassification(_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   labels=_UpperCAmelCase						)
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Any:
					snake_case__	     =self.num_labels
					snake_case__	     =AlbertForTokenClassification(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =model(_UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   labels=_UpperCAmelCase						)
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.seq_length, self.num_labels)						)






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase						)							->							Dict:
					snake_case__	     =self.num_choices
					snake_case__	     =AlbertForMultipleChoice(config=_UpperCAmelCase						)
					model.to(_UpperCAmelCase						)
					model.eval()
					snake_case__	     =input_ids.unsqueeze(1						).expand(-1					,   self.num_choices					,   -1						).contiguous()
					snake_case__	     =token_type_ids.unsqueeze(1						).expand(-1					,   self.num_choices					,   -1						).contiguous()
					snake_case__	     =input_mask.unsqueeze(1						).expand(-1					,   self.num_choices					,   -1						).contiguous()
					snake_case__	     =model(
					    _UpperCAmelCase					,   attention_mask=_UpperCAmelCase					,   token_type_ids=_UpperCAmelCase					,   labels=_UpperCAmelCase					,   )
					self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_choices)						)






			def 						_lowercase  (     self						)							->							List[Any]:
					snake_case__	     =self.prepare_config_and_inputs()
					(
					    (
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	(
					    snake_case__
					)     ,	
					)	     =config_and_inputs
					snake_case__	     ={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict





@require_torch
class 							a__( snake_case__   ,      snake_case__   ,      unittest.TestCase     ):
			a_	: Optional[int]									=      (
			    (
			        AlbertModel,
			        AlbertForPreTraining,
			        AlbertForMaskedLM,
			        AlbertForMultipleChoice,
			        AlbertForSequenceClassification,
			        AlbertForTokenClassification,
			        AlbertForQuestionAnswering,
			    )
			    if is_torch_available()
			    else ()
			)
			a_	: List[str]									=      (
			    {
			        '''feature-extraction''': AlbertModel,
			        '''fill-mask''': AlbertForMaskedLM,
			        '''question-answering''': AlbertForQuestionAnswering,
			        '''text-classification''': AlbertForSequenceClassification,
			        '''token-classification''': AlbertForTokenClassification,
			        '''zero-shot''': AlbertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			a_	: int									=      True






			def 						_lowercase  (     self					,   _UpperCAmelCase					,   _UpperCAmelCase					,   _UpperCAmelCase=False						)							->							Any:
					snake_case__	     =super()._prepare_for_class(_UpperCAmelCase					,   _UpperCAmelCase					,   return_labels=_UpperCAmelCase						)

					if return_labels:
							if model_class in get_values(_UpperCAmelCase						):
									snake_case__	     =torch.zeros(
									    (self.model_tester.batch_size, self.model_tester.seq_length)					,   dtype=torch.long					,   device=_UpperCAmelCase						)
									snake_case__	     =torch.zeros(
									    self.model_tester.batch_size					,   dtype=torch.long					,   device=_UpperCAmelCase						)
					return inputs_dict






			def 						_lowercase  (     self						)							->							int:
					snake_case__	     =AlbertModelTester(self						)
					snake_case__	     =ConfigTester(self					,   config_class=_UpperCAmelCase					,   hidden_size=37						)






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






			def 						_lowercase  (     self						)							->							str:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Optional[int]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Optional[Any]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Tuple:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							Optional[int]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase						)






			def 						_lowercase  (     self						)							->							List[str]:
					snake_case__	     =self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
							snake_case__	     =type
							self.model_tester.create_and_check_model(*_UpperCAmelCase						)






			@slow
			def 						_lowercase  (     self						)							->							Union[str, Any]:
					for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							snake_case__	     =AlbertModel.from_pretrained(_UpperCAmelCase						)
							self.assertIsNotNone(_UpperCAmelCase						)





@require_torch
class 							a__( unittest.TestCase     ):






			@slow
			def 						_lowercase  (     self						)							->							str:
					snake_case__	     =AlbertModel.from_pretrained('albert-base-v2'						)
					snake_case__	     =torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]						)
					snake_case__	     =torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
					with torch.no_grad():
							snake_case__	     =model(_UpperCAmelCase					,   attention_mask=_UpperCAmelCase						)[0]
					snake_case__	     =torch.Size((1, 11, 768)						)
					self.assertEqual(output.shape					,   _UpperCAmelCase						)
					snake_case__	     =torch.tensor(
					    [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]						)

					self.assertTrue(torch.allclose(output[:, 1:4, 1:4]					,   _UpperCAmelCase					,   atol=1E-4						)						)




