'''simple docstring'''

import unittest

from transformers import ErnieMConfig, 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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    ErnieMForInformationExtraction,
						    ErnieMForMultipleChoice,
						    ErnieMForQuestionAnswering,
						    ErnieMForSequenceClassification,
						    ErnieMForTokenClassification,
						    ErnieMModel,
						)
						from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST




class 		SCREAMING_SNAKE_CASE_					:



			"""simple docstring"""






			def __init__(							self				,			snake_case_				,			snake_case_=13				,			snake_case_=7				,			snake_case_=True				,			snake_case_=True				,			snake_case_=True				,			snake_case_=99				,			snake_case_=32				,			snake_case_=5				,			snake_case_=4				,			snake_case_=37				,			snake_case_="gelu"				,			snake_case_=0.1				,			snake_case_=0.1				,			snake_case_=512				,			snake_case_=16				,			snake_case_=2				,			snake_case_=0.02				,			snake_case_=3				,			snake_case_=4				,			snake_case_=None				,			):
									snake_case :       List[Any]				=    parent
									snake_case :       List[Any]				=    batch_size
									snake_case :       Optional[int]				=    seq_length
									snake_case :       Any				=    is_training
									snake_case :       Any				=    use_input_mask
									snake_case :       Optional[int]				=    use_labels
									snake_case :       Tuple				=    vocab_size
									snake_case :       Any				=    hidden_size
									snake_case :       Tuple				=    num_hidden_layers
									snake_case :       Dict				=    num_attention_heads
									snake_case :       Optional[int]				=    intermediate_size
									snake_case :       Dict				=    hidden_act
									snake_case :       str				=    hidden_dropout_prob
									snake_case :       List[Any]				=    attention_probs_dropout_prob
									snake_case :       int				=    max_position_embeddings
									snake_case :       List[Any]				=    type_vocab_size
									snake_case :       List[Any]				=    type_sequence_label_size
									snake_case :       Optional[int]				=    initializer_range
									snake_case :       Optional[int]				=    num_labels
									snake_case :       Tuple				=    num_choices
									snake_case :       Optional[Any]				=    scope



			def   lowerCamelCase (							self					):
									snake_case :       List[Any]				=    ids_tensor([self.batch_size, self.seq_length]				,			self.vocab_size					)

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

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

									snake_case :       Union[str, Any]				=    self.get_config()

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



			def   lowerCamelCase (							self					):
									snake_case :       str				=    ids_tensor([self.batch_size, self.seq_length]				,			self.vocab_size					)

									snake_case :       List[str]				=    None
									if self.use_input_mask:
															snake_case :       Union[str, Any]				=    random_attention_mask([self.batch_size, self.seq_length]					)
									snake_case :       Optional[Any]				=    self.get_config()

									return config, input_ids, input_mask



			def   lowerCamelCase (							self					):
									return ErnieMConfig(
									    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				,			)



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       Optional[int]				=    ErnieMModel(config=snake_case_					)
									model.to(snake_case_					)
									model.eval()
									snake_case :       Any				=    model(snake_case_				,			return_dict=snake_case_					)
									self.parent.assertEqual(result.last_hidden_state.shape				,			(self.batch_size, self.seq_length, self.hidden_size)					)



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       List[str]				=    ErnieMForQuestionAnswering(config=snake_case_					)
									model.to(snake_case_					)
									model.eval()
									snake_case :       Tuple				=    model(
									    snake_case_				,			attention_mask=snake_case_				,			start_positions=snake_case_				,			end_positions=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   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       Optional[Any]				=    ErnieMForInformationExtraction(config=snake_case_					)
									model.to(snake_case_					)
									model.eval()
									snake_case :       List[str]				=    torch.ones_like(snake_case_				,			dtype=torch.floataa					)
									snake_case :       Dict				=    model(
									    snake_case_				,			attention_mask=snake_case_				,			start_positions=snake_case_				,			end_positions=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   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       int				=    self.num_labels
									snake_case :       int				=    ErnieMForSequenceClassification(snake_case_					)
									model.to(snake_case_					)
									model.eval()
									snake_case :       str				=    model(snake_case_				,			attention_mask=snake_case_				,			labels=snake_case_					)
									self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.num_labels)					)



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       Dict				=    self.num_labels
									snake_case :       Dict				=    ErnieMForTokenClassification(config=snake_case_					)
									model.to(snake_case_					)
									model.eval()
									input_ids.to(snake_case_					)
									input_mask.to(snake_case_					)
									token_labels.to(snake_case_					)

									snake_case :       Union[str, Any]				=    model(snake_case_				,			attention_mask=snake_case_				,			labels=snake_case_					)

									self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.seq_length, self.num_labels)					)



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									snake_case :       Tuple				=    self.num_choices
									snake_case :       Dict				=    ErnieMForMultipleChoice(config=snake_case_					)
									model.to(snake_case_					)
									model.eval()
									snake_case :       Union[str, Any]				=    input_ids.unsqueeze(1					).expand(-1				,			self.num_choices				,			-1					).contiguous()
									snake_case :       Dict				=    input_mask.unsqueeze(1					).expand(-1				,			self.num_choices				,			-1					).contiguous()
									snake_case :       Optional[int]				=    model(
									    snake_case_				,			attention_mask=snake_case_				,			labels=snake_case_				,			)
									self.parent.assertEqual(result.logits.shape				,			(self.batch_size, self.num_choices)					)






			def   lowerCamelCase (							self					):
									snake_case :       str				=    self.prepare_config_and_inputs()
									(
									    (
									    snake_case
									)				,					(
									    snake_case
									)				,					(
									    snake_case
									)				,					(
									    snake_case
									)				,					(
									    snake_case
									)				,					(
									    snake_case
									)				,					
									) :       Optional[int]				=    config_and_inputs
									snake_case :       Tuple				=    {"input_ids": input_ids, "attention_mask": input_mask}
									return config, inputs_dict







@require_torch
class 		SCREAMING_SNAKE_CASE_					(_UpperCAmelCase							,				_UpperCAmelCase							,				unittest.TestCase      ):



			"""simple docstring"""






			__magic_name__ :				int   							=       (
			    (
			        ErnieMModel,
			        ErnieMForMultipleChoice,
			        ErnieMForQuestionAnswering,
			        ErnieMForSequenceClassification,
			        ErnieMForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			__magic_name__ :				Any   							=       ()
			__magic_name__ :				Dict   							=       (
			    {
			        """feature-extraction""": ErnieMModel,
			        """question-answering""": ErnieMForQuestionAnswering,
			        """text-classification""": ErnieMForSequenceClassification,
			        """token-classification""": ErnieMForTokenClassification,
			        """zero-shot""": ErnieMForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__magic_name__ :				int   							=       False



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_				,			snake_case_					):
									if pipeline_test_casse_name == "QAPipelineTests":
															return True

									return False



			def   lowerCamelCase (							self					):
									snake_case :       str				=    ErnieMModelTester(self					)
									snake_case :       str				=    ConfigTester(self				,			config_class=snake_case_				,			hidden_size=37					)



			def   lowerCamelCase (							self					):
									self.config_tester.run_common_tests()



			def   lowerCamelCase (							self					):
									snake_case :       Optional[int]				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       Union[str, Any]				=    self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
															snake_case :       Optional[Any]				=    type
															self.model_tester.create_and_check_model(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       int				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       Union[str, Any]				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       int				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_information_extraction(*snake_case_					)



			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*snake_case_					)






			@slow
			def   lowerCamelCase (							self					):
									for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case :       List[str]				=    ErnieMModel.from_pretrained(snake_case_					)
															self.assertIsNotNone(snake_case_					)







@require_torch
class 		SCREAMING_SNAKE_CASE_					(unittest.TestCase      ):



			"""simple docstring"""






			@slow
			def   lowerCamelCase (							self					):
									snake_case :       str				=    ErnieMModel.from_pretrained("susnato/ernie-m-base_pytorch"					)
									model.eval()
									snake_case :       Optional[int]				=    torch.tensor([[0, 1, 2, 3, 4, 5]]					)
									snake_case :       List[str]				=    model(snake_case_					)[0]

									# TODO Replace vocab size
									snake_case :       Any				=    768

									snake_case :       str				=    torch.Size((1, 6, hidden_size)					)
									self.assertEqual(output.shape				,			snake_case_					)

									snake_case :       int				=    torch.tensor(
									    [[[-0.0_012, 0.1_245, -0.0_214], [-0.0_742, 0.0_244, -0.0_771], [-0.0_333, 0.1_164, -0.1_554]]]					)

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






'''simple docstring'''

def        UpperCAmelCase__   (				_lowerCAmelCase    :			int = 400_0000)    ->		int:



						"""simple docstring"""

						snake_case :       List[Any]				=    1
						snake_case :       int				=    2
						snake_case :       List[str]				=    0
						while j <= n:
												if j % 2 == 0:
																		total += j
												snake_case				,					snake_case :       Any				=    j, i + j

						return total


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





