

import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, 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 (
         DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
         DistilBertForMaskedLM,
         DistilBertForMultipleChoice,
         DistilBertForQuestionAnswering,
         DistilBertForSequenceClassification,
         DistilBertForTokenClassification,
         DistilBertModel,
     )


class 			A						(							UpperCAmelCase__			):







    """simple docstring"""





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





        '''simple docstring'''







        A__   				=       parent
        A__   				=       batch_size
        A__   				=       seq_length
        A__   				=       is_training
        A__   				=       use_input_mask
        A__   				=       use_token_type_ids
        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 						snake_case__					(				self			:	Dict		)->   List[str]:





        '''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 						snake_case__					(				self			:	str		)->   Tuple:





        '''simple docstring'''







        return DistilBertConfig(
            vocab_size=self.vocab_size,dim=self.hidden_size,n_layers=self.num_hidden_layers,n_heads=self.num_attention_heads,hidden_dim=self.intermediate_size,hidden_act=self.hidden_act,dropout=self.hidden_dropout_prob,attention_dropout=self.attention_probs_dropout_prob,max_position_embeddings=self.max_position_embeddings,initializer_range=self.initializer_range,)


    def 						snake_case__					(				self			:	List[Any],lowercase_			:	Any,lowercase_			:	int,lowercase_			:	str,lowercase_			:	Union[str, Any],lowercase_			:	Union[str, Any],lowercase_			:	str		)->   List[Any]:





        '''simple docstring'''







        A__   				=       DistilBertModel(config=_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        model.eval()
        A__   				=       model(_SCREAMING_SNAKE_CASE,_SCREAMING_SNAKE_CASE		)
        A__   				=       model(_SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.last_hidden_state.shape,(self.batch_size, self.seq_length, self.hidden_size)		)


    def 						snake_case__					(				self			:	List[Any],lowercase_			:	Dict,lowercase_			:	Dict,lowercase_			:	List[Any],lowercase_			:	Tuple,lowercase_			:	Tuple,lowercase_			:	Tuple		)->   Union[str, Any]:





        '''simple docstring'''







        A__   				=       DistilBertForMaskedLM(config=_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        model.eval()
        A__   				=       model(_SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE,labels=_SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape,(self.batch_size, self.seq_length, self.vocab_size)		)


    def 						snake_case__					(				self			:	List[Any],lowercase_			:	Optional[Any],lowercase_			:	str,lowercase_			:	str,lowercase_			:	Dict,lowercase_			:	Any,lowercase_			:	Any		)->   int:





        '''simple docstring'''







        A__   				=       DistilBertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        model.eval()
        A__   				=       model(
            _SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE,start_positions=_SCREAMING_SNAKE_CASE,end_positions=_SCREAMING_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 						snake_case__					(				self			:	List[Any],lowercase_			:	Optional[int],lowercase_			:	Optional[int],lowercase_			:	Tuple,lowercase_			:	Any,lowercase_			:	Any,lowercase_			:	Dict		)->   Optional[int]:





        '''simple docstring'''







        A__   				=       self.num_labels
        A__   				=       DistilBertForSequenceClassification(_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        model.eval()
        A__   				=       model(_SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE,labels=_SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape,(self.batch_size, self.num_labels)		)


    def 						snake_case__					(				self			:	Optional[int],lowercase_			:	int,lowercase_			:	Union[str, Any],lowercase_			:	Dict,lowercase_			:	List[str],lowercase_			:	Dict,lowercase_			:	Tuple		)->   Optional[Any]:





        '''simple docstring'''







        A__   				=       self.num_labels
        A__   				=       DistilBertForTokenClassification(config=_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        model.eval()

        A__   				=       model(_SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE,labels=_SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape,(self.batch_size, self.seq_length, self.num_labels)		)


    def 						snake_case__					(				self			:	List[Any],lowercase_			:	Union[str, Any],lowercase_			:	Union[str, Any],lowercase_			:	List[Any],lowercase_			:	int,lowercase_			:	Optional[Any],lowercase_			:	List[str]		)->   Any:





        '''simple docstring'''







        A__   				=       self.num_choices
        A__   				=       DistilBertForMultipleChoice(config=_SCREAMING_SNAKE_CASE		)
        model.to(_SCREAMING_SNAKE_CASE		)
        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(
            _SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE,labels=_SCREAMING_SNAKE_CASE,)
        self.parent.assertEqual(result.logits.shape,(self.batch_size, self.num_choices)		)


    def 						snake_case__					(				self			:	Tuple		)->   Dict:





        '''simple docstring'''







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




@require_torch
class 			A						(							UpperCAmelCase__   ,							UpperCAmelCase__   ,							unittest.TestCase			):







    """simple docstring"""





    lowerCamelCase		     =							(
        (
            DistilBertModel,
            DistilBertForMaskedLM,
            DistilBertForMultipleChoice,
            DistilBertForQuestionAnswering,
            DistilBertForSequenceClassification,
            DistilBertForTokenClassification,
        )
        if is_torch_available()
        else None
    )
    lowerCamelCase		     =							(
        {
            'feature-extraction': DistilBertModel,
            'fill-mask': DistilBertForMaskedLM,
            'question-answering': DistilBertForQuestionAnswering,
            'text-classification': DistilBertForSequenceClassification,
            'token-classification': DistilBertForTokenClassification,
            'zero-shot': DistilBertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    lowerCamelCase		     =							True
    lowerCamelCase		     =							True
    lowerCamelCase		     =							True
    lowerCamelCase		     =							True


    def 						snake_case__					(				self			:	List[Any]		)->   List[str]:





        '''simple docstring'''







        A__   				=       DistilBertModelTester(self		)
        A__   				=       ConfigTester(self,config_class=_SCREAMING_SNAKE_CASE,dim=3_7		)


    def 						snake_case__					(				self			:	Tuple		)->   Dict:





        '''simple docstring'''







        self.config_tester.run_common_tests()


    def 						snake_case__					(				self			:	int		)->   int:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_model(*_SCREAMING_SNAKE_CASE		)


    def 						snake_case__					(				self			:	Optional[int]		)->   Tuple:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_masked_lm(*_SCREAMING_SNAKE_CASE		)


    def 						snake_case__					(				self			:	Union[str, Any]		)->   int:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_question_answering(*_SCREAMING_SNAKE_CASE		)


    def 						snake_case__					(				self			:	Any		)->   List[str]:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_sequence_classification(*_SCREAMING_SNAKE_CASE		)


    def 						snake_case__					(				self			:	Dict		)->   int:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_token_classification(*_SCREAMING_SNAKE_CASE		)


    def 						snake_case__					(				self			:	List[Any]		)->   int:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_multiple_choice(*_SCREAMING_SNAKE_CASE		)


    @slow
    def 						snake_case__					(				self			:	str		)->   List[Any]:





        '''simple docstring'''







        for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            A__   				=       DistilBertModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
            self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)


    @slow
    @require_torch_gpu
    def 						snake_case__					(				self			:	List[str]		)->   Tuple:





        '''simple docstring'''







        A__   				=       self.model_tester.prepare_config_and_inputs_for_common()
        for model_class in self.all_model_classes:
            # BertForMultipleChoice behaves incorrectly in JIT environments.
            if model_class == DistilBertForMultipleChoice:
                return

            A__   				=       True
            A__   				=       model_class(config=_SCREAMING_SNAKE_CASE		)

            A__   				=       self._prepare_for_class(_SCREAMING_SNAKE_CASE,_SCREAMING_SNAKE_CASE		)
            A__   				=       torch.jit.trace(
                _SCREAMING_SNAKE_CASE,(inputs_dict['input_ids'].to('cpu'		), inputs_dict['attention_mask'].to('cpu'		))		)

            with tempfile.TemporaryDirectory() as tmp:
                torch.jit.save(_SCREAMING_SNAKE_CASE,os.path.join(_SCREAMING_SNAKE_CASE,'traced_model.pt'		)		)
                A__   				=       torch.jit.load(os.path.join(_SCREAMING_SNAKE_CASE,'traced_model.pt'		),map_location=_SCREAMING_SNAKE_CASE		)
                loaded(inputs_dict['input_ids'].to(_SCREAMING_SNAKE_CASE		),inputs_dict['attention_mask'].to(_SCREAMING_SNAKE_CASE		)		)




@require_torch
class 			A						(							unittest.TestCase			):







    """simple docstring"""





    @slow
    def 						snake_case__					(				self			:	Union[str, Any]		)->   Optional[int]:





        '''simple docstring'''







        A__   				=       DistilBertModel.from_pretrained('distilbert-base-uncased'		)
        A__   				=       torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]		)
        A__   				=       torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
        with torch.no_grad():
            A__   				=       model(_SCREAMING_SNAKE_CASE,attention_mask=_SCREAMING_SNAKE_CASE		)[0]
        A__   				=       torch.Size((1, 1_1, 7_6_8)		)
        self.assertEqual(output.shape,_SCREAMING_SNAKE_CASE		)
        A__   				=       torch.tensor(
            [[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]		)

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




from collections.abc import Sequence
def 						_snake_case(   SCREAMING_SNAKE_CASE__      :     Sequence[int] | None = None				)							->				int:





    '''simple docstring'''






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

    A__   				=       nums[0]
    for i in range(1   ,      len(SCREAMING_SNAKE_CASE__				)				):
        A__   				=       nums[i]
        A__   				=       max(SCREAMING_SNAKE_CASE__   ,      ans + num   ,      SCREAMING_SNAKE_CASE__				)

    return ans


if __name__ == "__main__":
     import doctest

     doctest.testmod()

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

