





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     SCREAMING_SNAKE_CASE       (a_				):


   def __init__(   self      :    Any      ,					a      :    Optional[Any]      ,					a      :    Dict=13      ,					a      :    Dict=7      ,					a      :    Optional[int]=True      ,					a      :    Tuple=True      ,					a      :    List[Any]=False      ,					a      :    int=True      ,					a      :    Optional[Any]=99      ,					a      :    Optional[int]=32      ,					a      :    Tuple=5      ,					a      :    List[Any]=4      ,					a      :    str=37      ,					a      :    Optional[int]="gelu"      ,					a      :    str=0.1      ,					a      :    List[str]=0.1      ,					a      :    Optional[Any]=512      ,					a      :    List[Any]=16      ,					a      :    int=2      ,					a      :    List[str]=0.02      ,					a      :    List[str]=3      ,					a      :    int=4      ,					a      :    Any=None      ,					)->       List[str]:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       Union[str, Any]:





     """simple docstring"""







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

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

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

     lowercase__           =  self.get_config()

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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple	)->       Union[str, Any]:





     """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 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    int      ,					a      :    Union[str, Any]      ,					a      :    int      ,					a      :    Optional[int]      ,					a      :    Dict      ,					a      :    Dict	)->       int:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str      ,					a      :    List[str]      ,					a      :    Any      ,					a      :    Optional[int]      ,					a      :    Any      ,					a      :    Tuple      ,					a      :    List[Any]	)->       Optional[int]:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]      ,					a      :    List[Any]      ,					a      :    Optional[Any]      ,					a      :    List[str]      ,					a      :    List[Any]      ,					a      :    Optional[int]      ,					a      :    Dict	)->       Dict:





     """simple docstring"""







     lowercase__           =  DistilBertForQuestionAnswering(config=lowercase_	)
     model.to(lowercase_	)
     model.eval()
     lowercase__           =  model(
         lowercase_      ,					attention_mask=lowercase_      ,					start_positions=lowercase_      ,					end_positions=lowercase_	)
     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 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]      ,					a      :    List[str]      ,					a      :    Tuple      ,					a      :    str      ,					a      :    Optional[Any]      ,					a      :    Optional[Any]      ,					a      :    Union[str, Any]	)->       Union[str, Any]:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    List[Any]      ,					a      :    Any      ,					a      :    Tuple      ,					a      :    List[Any]      ,					a      :    int      ,					a      :    int	)->       Optional[Any]:





     """simple docstring"""







     lowercase__           =  self.num_labels
     lowercase__           =  DistilBertForTokenClassification(config=lowercase_	)
     model.to(lowercase_	)
     model.eval()

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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str      ,					a      :    int      ,					a      :    Union[str, Any]      ,					a      :    Dict      ,					a      :    Optional[int]      ,					a      :    Dict      ,					a      :    Tuple	)->       Tuple:





     """simple docstring"""







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


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





     """simple docstring"""







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






@require_torch
class     SCREAMING_SNAKE_CASE       (a_      ,     a_      ,     unittest.TestCase				):
   _UpperCamelCase   :		List[Any]			 =	(
       (
           DistilBertModel,
           DistilBertForMaskedLM,
           DistilBertForMultipleChoice,
           DistilBertForQuestionAnswering,
           DistilBertForSequenceClassification,
           DistilBertForTokenClassification,
       )
       if is_torch_available()
       else None
   )
   _UpperCamelCase   :		Tuple			 =	(
       {
           '''feature-extraction''': DistilBertModel,
           '''fill-mask''': DistilBertForMaskedLM,
           '''question-answering''': DistilBertForQuestionAnswering,
           '''text-classification''': DistilBertForSequenceClassification,
           '''token-classification''': DistilBertForTokenClassification,
           '''zero-shot''': DistilBertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   _UpperCamelCase   :		str			 =	True
   _UpperCamelCase   :		Optional[int]			 =	True
   _UpperCamelCase   :		Optional[int]			 =	True
   _UpperCamelCase   :		Tuple			 =	True


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]	)->       int:





     """simple docstring"""







     lowercase__           =  DistilBertModelTester(self	)
     lowercase__           =  ConfigTester(self      ,					config_class=lowercase_      ,					dim=37	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Tuple:





     """simple docstring"""







     self.config_tester.run_common_tests()


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       str:





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_model(*lowercase_	)


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





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase_	)


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





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase_	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]	)->       List[str]:





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase_	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase_	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase_	)


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





     """simple docstring"""







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


   @slow
   @require_torch_gpu
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       Optional[Any]:





     """simple docstring"""







     lowercase__      ,   lowercase__           =  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

       lowercase__           =  True
       lowercase__           =  model_class(config=lowercase_	)

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

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






@require_torch
class     SCREAMING_SNAKE_CASE       (unittest.TestCase				):


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    str	)->       int:





     """simple docstring"""







     lowercase__           =  DistilBertModel.from_pretrained('distilbert-base-uncased'	)
     lowercase__           =  torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]	)
     lowercase__           =  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
     with torch.no_grad():
       lowercase__           =  model(lowercase_      ,					attention_mask=lowercase_	)[0]
     lowercase__           =  torch.Size((1, 11, 768)	)
     self.assertEqual(output.shape      ,					lowercase_	)
     lowercase__           =  torch.tensor(
         [[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]	)

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









import sys

lowercase_          =		(
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE = N		)    ->       int:
  lowercase__           =  -sys.maxsize - 1
  for i in range(len(_SCREAMING_SNAKE_CASE		) - 12		):
    lowercase__           =  1
    for j in range(13		):
      product *= int(n[i + j]		)
    if product > largest_product:
      lowercase__           =  product
  return largest_product


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


