

'''simple docstring'''


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
					    OpenAIGPTConfig,
					    OpenAIGPTDoubleHeadsModel,
					    OpenAIGPTForSequenceClassification,
					    OpenAIGPTLMHeadModel,
					    OpenAIGPTModel,
					)




class     a			:






						"""simple docstring"""




						def __init__(							self					:      Dict			,			snake_case_					:      Optional[int]			,			snake_case_					:      List[Any]=1_3			,			snake_case_					:      Optional[Any]=7			,			snake_case_					:      Tuple=True			,			snake_case_					:      str=True			,			snake_case_					:      Dict=True			,			snake_case_					:      int=9_9			,			snake_case_					:      Union[str, Any]=3_2			,			snake_case_					:      Optional[int]=5			,			snake_case_					:      Optional[Any]=4			,			snake_case_					:      List[str]=3_7			,			snake_case_					:      str="gelu"			,			snake_case_					:      List[str]=0.1			,			snake_case_					:      Tuple=0.1			,			snake_case_					:      str=5_1_2			,			snake_case_					:      List[Any]=1_6			,			snake_case_					:      int=2			,			snake_case_					:      Optional[Any]=0.0_2			,			snake_case_					:      str=3			,			snake_case_					:      List[Any]=4			,			snake_case_					:      str=None			,			):



								'''simple docstring'''



								snake_case__						:       str       						=  parent
								snake_case__						:       List[Any]       						=  batch_size
								snake_case__						:       List[Any]       						=  seq_length
								snake_case__						:       List[Any]       						=  is_training
								snake_case__						:       Any       						=  use_token_type_ids
								snake_case__						:       Optional[Any]       						=  use_labels
								snake_case__						:       Tuple       						=  vocab_size
								snake_case__						:       Optional[Any]       						=  hidden_size
								snake_case__						:       List[Any]       						=  num_hidden_layers
								snake_case__						:       List[Any]       						=  num_attention_heads
								snake_case__						:       Union[str, Any]       						=  intermediate_size
								snake_case__						:       Optional[int]       						=  hidden_act
								snake_case__						:       str       						=  hidden_dropout_prob
								snake_case__						:       Any       						=  attention_probs_dropout_prob
								snake_case__						:       List[Any]       						=  max_position_embeddings
								snake_case__						:       Optional[Any]       						=  type_vocab_size
								snake_case__						:       List[Any]       						=  type_sequence_label_size
								snake_case__						:       Tuple       						=  initializer_range
								snake_case__						:       Any       						=  num_labels
								snake_case__						:       Union[str, Any]       						=  num_choices
								snake_case__						:       Tuple       						=  scope
								snake_case__						:       str       						=  self.vocab_size - 1







						def       __magic_name__							(							self					:      int  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  ids_tensor([self.batch_size, self.seq_length]			,			self.vocab_size  )

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

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

								snake_case__						:       Optional[Any]       						=  OpenAIGPTConfig(
								    vocab_size=self.vocab_size			,			n_embd=self.hidden_size			,			n_layer=self.num_hidden_layers			,			n_head=self.num_attention_heads			,			n_positions=self.max_position_embeddings			,			pad_token_id=self.pad_token_id			,			)

								snake_case__						:       Any       						=  ids_tensor([self.num_hidden_layers, self.num_attention_heads]			,			2  )

								return (
								    config,
								    input_ids,
								    head_mask,
								    token_type_ids,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								)







						def       __magic_name__							(							self					:      Optional[int]			,			snake_case_					:      int			,			snake_case_					:      Union[str, Any]			,			snake_case_					:      List[Any]			,			snake_case_					:      int			,			*snake_case_					:      int  ):



								'''simple docstring'''



								snake_case__						:       Tuple       						=  OpenAIGPTModel(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()

								snake_case__						:       Optional[int]       						=  model(snake_case_			,			token_type_ids=snake_case_			,			head_mask=snake_case_  )
								snake_case__						:       Optional[Any]       						=  model(snake_case_			,			token_type_ids=snake_case_  )
								snake_case__						:       List[Any]       						=  model(snake_case_  )

								self.parent.assertEqual(result.last_hidden_state.shape			,			(self.batch_size, self.seq_length, self.hidden_size)  )







						def       __magic_name__							(							self					:      Dict			,			snake_case_					:      int			,			snake_case_					:      int			,			snake_case_					:      Optional[int]			,			snake_case_					:      List[Any]			,			*snake_case_					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       Optional[Any]       						=  OpenAIGPTLMHeadModel(snake_case_  )
								model.to(snake_case_  )
								model.eval()

								snake_case__						:       List[str]       						=  model(snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.loss.shape			,			()  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)  )







						def       __magic_name__							(							self					:      Any			,			snake_case_					:      List[Any]			,			snake_case_					:      List[Any]			,			snake_case_					:      List[str]			,			snake_case_					:      Tuple			,			*snake_case_					:      List[str]  ):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  OpenAIGPTDoubleHeadsModel(snake_case_  )
								model.to(snake_case_  )
								model.eval()

								snake_case__						:       List[Any]       						=  model(snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.loss.shape			,			()  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)  )







						def       __magic_name__							(							self					:      int			,			snake_case_					:      Union[str, Any]			,			snake_case_					:      Optional[Any]			,			snake_case_					:      List[str]			,			snake_case_					:      List[str]			,			*snake_case_					:      str  ):



								'''simple docstring'''



								snake_case__						:       Any       						=  self.num_labels
								snake_case__						:       str       						=  OpenAIGPTForSequenceClassification(snake_case_  )
								model.to(snake_case_  )
								model.eval()

								snake_case__						:       List[Any]       						=  ids_tensor([self.batch_size]			,			self.type_sequence_label_size  )
								snake_case__						:       Optional[Any]       						=  model(snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_labels)  )







						def       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       Tuple       						=  self.prepare_config_and_inputs()
								(
								    (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       
								)						:       Any       						=  config_and_inputs
								snake_case__						:       str       						=  {
								    '''input_ids''': input_ids,
								    '''token_type_ids''': token_type_ids,
								    '''head_mask''': head_mask,
								}

								return config, inputs_dict





@require_torch
class     a			(				SCREAMING_SNAKE_CASE			,			SCREAMING_SNAKE_CASE			,			SCREAMING_SNAKE_CASE			,			unittest.TestCase       ):






						"""simple docstring"""




						__UpperCAmelCase			     =    (
						    (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
						    if is_torch_available()
						    else ()
						)
						__UpperCAmelCase			     =    (
						    (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
						)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
						__UpperCAmelCase			     =    (
						    {
						        """feature-extraction""": OpenAIGPTModel,
						        """text-classification""": OpenAIGPTForSequenceClassification,
						        """text-generation""": OpenAIGPTLMHeadModel,
						        """zero-shot""": OpenAIGPTForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)







						def       __magic_name__							(							self					:      Optional[int]			,			snake_case_					:      Any			,			snake_case_					:      Tuple			,			snake_case_					:      Optional[Any]			,			snake_case_					:      str			,			snake_case_					:      str  ):



								'''simple docstring'''



								if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
										# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
										# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
										# tiny config could not be created.
										return True

								return False







						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      List[str]			,			snake_case_					:      List[Any]			,			snake_case_					:      Dict=False  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  super()._prepare_for_class(snake_case_			,			snake_case_			,			return_labels=snake_case_  )

								if return_labels:
										if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
												snake_case__						:       str       						=  torch.zeros(
												    (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)			,			dtype=torch.long			,			device=snake_case_			,			)
												snake_case__						:       List[str]       						=  inputs_dict['''labels''']
												snake_case__						:       Any       						=  inputs_dict['''labels''']
												snake_case__						:       Any       						=  torch.zeros(
												    (self.model_tester.batch_size, self.model_tester.num_choices)			,			dtype=torch.long			,			device=snake_case_			,			)
												snake_case__						:       Optional[Any]       						=  torch.zeros(
												    self.model_tester.batch_size			,			dtype=torch.long			,			device=snake_case_  )
								return inputs_dict







						def       __magic_name__							(							self					:      List[str]  ):



								'''simple docstring'''



								snake_case__						:       Any       						=  OpenAIGPTModelTester(self  )
								snake_case__						:       Optional[Any]       						=  ConfigTester(self			,			config_class=snake_case_			,			n_embd=3_7  )







						def       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								self.config_tester.run_common_tests()







						def       __magic_name__							(							self					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_openai_gpt_model(*snake_case_  )







						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



								snake_case__						:       str       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head_model(*snake_case_  )







						def       __magic_name__							(							self					:      Optional[int]  ):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_double_lm_head_model(*snake_case_  )







						def       __magic_name__							(							self					:      Tuple  ):



								'''simple docstring'''



								snake_case__						:       List[Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*snake_case_  )







						@slow
						def       __magic_name__							(							self					:      List[str]  ):



								'''simple docstring'''



								for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case__						:       Any       						=  OpenAIGPTModel.from_pretrained(snake_case_  )
										self.assertIsNotNone(snake_case_  )





@require_torch
class     a			(				unittest.TestCase       ):






						"""simple docstring"""




						@slow
						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''  )
								model.to(snake_case_  )
								snake_case__						:       int       						=  torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]			,			dtype=torch.long			,			device=snake_case_  )  # the president is
								snake_case__						:       Union[str, Any]       						=  [
								    4_8_1,
								    4_7_3_5,
								    5_4_4,
								    2_4_6,
								    9_6_3,
								    8_7_0,
								    7_6_2,
								    2_3_9,
								    2_4_4,
								    4_0_4_7_7,
								    2_4_4,
								    2_4_9,
								    7_1_9,
								    8_8_1,
								    4_8_7,
								    5_4_4,
								    2_4_0,
								    2_4_4,
								    6_0_3,
								    4_8_1,
								]  # the president is a very good man. " \n " i\'m sure he is, " said the

								snake_case__						:       Any       						=  model.generate(snake_case_			,			do_sample=snake_case_  )
								self.assertListEqual(output_ids[0].tolist()			,			snake_case_  )






'''simple docstring'''


from collections.abc import Sequence




def 	_a       (				__lowerCAmelCase		:      Sequence[int] | None = None     ):

		"""simple docstring"""

		if nums is None or not nums:
				raise ValueError('''Input sequence should not be empty'''     )

		snake_case__						:       Optional[Any]       						=  nums[0]
		for i in range(1   ,							len(__lowerCAmelCase     )     ):
				snake_case__						:       Tuple       						=  nums[i]
				snake_case__						:       Optional[int]       						=  max(__lowerCAmelCase   ,							ans + num   ,							__lowerCAmelCase     )

		return ans


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					# Try on a sample input from the user
					lowerCAmelCase__						:       str										=						int(input("""Enter number of elements : """).strip())
					lowerCAmelCase__						:       Dict										=						list(map(int, input("""\nEnter the numbers : """).strip().split()))[:n]
					print(max_subsequence_sum(array))



