



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 lowerCAmelCase_       :







	'''simple docstring'''




	def __init__(	self   ,       lowerCamelCase   ,       lowerCamelCase=13   ,       lowerCamelCase=7   ,       lowerCamelCase=True   ,       lowerCamelCase=True   ,       lowerCamelCase=True   ,       lowerCamelCase=99   ,       lowerCamelCase=32   ,       lowerCamelCase=5   ,       lowerCamelCase=4   ,       lowerCamelCase=37   ,       lowerCamelCase="gelu"   ,       lowerCamelCase=0.1   ,       lowerCamelCase=0.1   ,       lowerCamelCase=512   ,       lowerCamelCase=16   ,       lowerCamelCase=2   ,       lowerCamelCase=0.0_2   ,       lowerCamelCase=3   ,       lowerCamelCase=4   ,       lowerCamelCase=None   ,       ):



				'''simple docstring'''


				a__					=  parent
				a__					=  batch_size
				a__					=  seq_length
				a__					=  is_training
				a__					=  use_input_mask
				a__					=  use_labels
				a__					=  vocab_size
				a__					=  hidden_size
				a__					=  num_hidden_layers
				a__					=  num_attention_heads
				a__					=  intermediate_size
				a__					=  hidden_act
				a__					=  hidden_dropout_prob
				a__					=  attention_probs_dropout_prob
				a__					=  max_position_embeddings
				a__					=  type_vocab_size
				a__					=  type_sequence_label_size
				a__					=  initializer_range
				a__					=  num_labels
				a__					=  num_choices
				a__					=  scope

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  ids_tensor([self.batch_size, self.seq_length]   ,       self.vocab_size       )

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

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

				a__					=  self.get_config()

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

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  ids_tensor([self.batch_size, self.seq_length]   ,       self.vocab_size       )

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

				return config, input_ids, input_mask

	def 				_A			(	self       ):



				'''simple docstring'''


				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 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  ErnieMModel(config=lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				a__					=  model(lowerCamelCase__   ,       return_dict=lowerCamelCase__       )
				self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, self.seq_length, self.hidden_size)       )

	def 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  ErnieMForQuestionAnswering(config=lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				a__					=  model(
				    lowerCamelCase__   ,       attention_mask=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 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  ErnieMForInformationExtraction(config=lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				a__					=  torch.ones_like(lowerCamelCase__   ,       dtype=torch.floataa       )
				a__					=  model(
				    lowerCamelCase__   ,       attention_mask=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 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  self.num_labels
				a__					=  ErnieMForSequenceClassification(lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				a__					=  model(lowerCamelCase__   ,       attention_mask=lowerCamelCase__   ,       labels=lowerCamelCase__       )
				self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.num_labels)       )

	def 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  self.num_labels
				a__					=  ErnieMForTokenClassification(config=lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				input_ids.to(lowerCamelCase__       )
				input_mask.to(lowerCamelCase__       )
				token_labels.to(lowerCamelCase__       )

				a__					=  model(lowerCamelCase__   ,       attention_mask=lowerCamelCase__   ,       labels=lowerCamelCase__       )

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

	def 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  self.num_choices
				a__					=  ErnieMForMultipleChoice(config=lowerCamelCase__       )
				model.to(lowerCamelCase__       )
				model.eval()
				a__					=  input_ids.unsqueeze(1       ).expand(-1   ,       self.num_choices   ,       -1       ).contiguous()
				a__					=  input_mask.unsqueeze(1       ).expand(-1   ,       self.num_choices   ,       -1       ).contiguous()
				a__					=  model(
				    lowerCamelCase__   ,       attention_mask=lowerCamelCase__   ,       labels=lowerCamelCase__   ,       )
				self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.num_choices)       )







	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.prepare_config_and_inputs()
				(
				    (
				    a__   
				)				,       (
				    a__   
				)				,       (
				    a__   
				)				,       (
				    a__   
				)				,       (
				    a__   
				)				,       (
				    a__   
				)				,          
				)					=  config_and_inputs
				a__					=  {"""input_ids""": input_ids, """attention_mask""": input_mask}
				return config, inputs_dict


@require_torch
class lowerCAmelCase_       (   lowerCAmelCase_ ,lowerCAmelCase_ ,unittest.TestCase			):







	'''simple docstring'''




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

	def 				_A			(	self   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase   ,       lowerCamelCase       ):



				'''simple docstring'''


				if pipeline_test_casse_name == "QAPipelineTests":
							return True

				return False

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  ErnieMModelTester(self       )
				a__					=  ConfigTester(self   ,       config_class=lowerCamelCase__   ,       hidden_size=37       )

	def 				_A			(	self       ):



				'''simple docstring'''


				self.config_tester.run_common_tests()

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
							a__					=  type
							self.model_tester.create_and_check_model(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_information_extraction(*lowerCamelCase__       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__       )







	@slow
	def 				_A			(	self       ):



				'''simple docstring'''


				for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							a__					=  ErnieMModel.from_pretrained(lowerCamelCase__       )
							self.assertIsNotNone(lowerCamelCase__       )


@require_torch
class lowerCAmelCase_       (   unittest.TestCase			):







	'''simple docstring'''




	@slow
	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  ErnieMModel.from_pretrained("""susnato/ernie-m-base_pytorch"""       )
				model.eval()
				a__					=  torch.tensor([[0, 1, 2, 3, 4, 5]]       )
				a__					=  model(lowerCamelCase__       )[0]

				# TODO Replace vocab size
				a__					=  768

				a__					=  torch.Size((1, 6, hidden_size)       )
				self.assertEqual(output.shape   ,       lowerCamelCase__       )

				a__					=  torch.tensor(
				    [[[-0.0_0_1_2, 0.1_2_4_5, -0.0_2_1_4], [-0.0_7_4_2, 0.0_2_4_4, -0.0_7_7_1], [-0.0_3_3_3, 0.1_1_6_4, -0.1_5_5_4]]]       )

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








import os



def   __lowercase  ( )					->  int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		os.path.dirname(os.path.realpath(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		os.path.join(_SCREAMING_SNAKE_CASE					,		"""triangle.txt"""      )

      with open(_SCREAMING_SNAKE_CASE      ) as in_file:
            SCREAMING_SNAKE_CASE						=		[[int(_SCREAMING_SNAKE_CASE      ) for i in line.split()] for line in in_file]

      while len(_SCREAMING_SNAKE_CASE      ) != 1:
            SCREAMING_SNAKE_CASE						=		triangle.pop()
            SCREAMING_SNAKE_CASE						=		triangle[-1]
            for j in range(len(_SCREAMING_SNAKE_CASE      ) - 1      ):
                  curr_row[j] += max(last_row[j]					,		last_row[j + 1]      )
      return triangle[0][0]


if __name__ == "__main__":
      print(solution())


