





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     __snake_case       (							__lowerCamelCase			):





       '''simple docstring'''







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




       def 							UpperCAmelCase__ (  self :    Dict		):
         __snake_case:						Union[str, Any]   =						ids_tensor([self.batch_size, self.seq_length]							,				self.vocab_size		)

         __snake_case:						Tuple   =						None
         if self.use_input_mask:
           __snake_case:						str   =						random_attention_mask([self.batch_size, self.seq_length]		)

         __snake_case:						Union[str, Any]   =						None
         __snake_case:						List[Any]   =						None
         __snake_case:						str   =						None
         if self.use_labels:
           __snake_case:						Optional[int]   =						ids_tensor([self.batch_size]							,				self.type_sequence_label_size		)
           __snake_case:						Dict   =						ids_tensor([self.batch_size, self.seq_length]							,				self.num_labels		)
           __snake_case:						Optional[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 							UpperCAmelCase__ (  self :    List[Any]		):
         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 							UpperCAmelCase__ (  self :    Dict							,				A :    List[str]							,				A :    Tuple							,				A :    List[str]							,				A :    Any							,				A :    Dict							,				A :    Optional[Any]		):
         __snake_case:						Any   =						DistilBertModel(config=A		)
         model.to(A		)
         model.eval()
         __snake_case:						str   =						model(A							,				A		)
         __snake_case:						List[Any]   =						model(A		)
         self.parent.assertEqual(result.last_hidden_state.shape							,				(self.batch_size, self.seq_length, self.hidden_size)		)




       def 							UpperCAmelCase__ (  self :    Any							,				A :    Union[str, Any]							,				A :    List[Any]							,				A :    List[Any]							,				A :    Tuple							,				A :    Tuple							,				A :    List[str]		):
         __snake_case:						Union[str, Any]   =						DistilBertForMaskedLM(config=A		)
         model.to(A		)
         model.eval()
         __snake_case:						Optional[Any]   =						model(A							,				attention_mask=A							,				labels=A		)
         self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.seq_length, self.vocab_size)		)




       def 							UpperCAmelCase__ (  self :    Union[str, Any]							,				A :    Optional[int]							,				A :    Optional[int]							,				A :    Tuple							,				A :    Union[str, Any]							,				A :    Optional[Any]							,				A :    List[str]		):
         __snake_case:						List[Any]   =						DistilBertForQuestionAnswering(config=A		)
         model.to(A		)
         model.eval()
         __snake_case:						Dict   =						model(
             A							,				attention_mask=A							,				start_positions=A							,				end_positions=A		)
         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 							UpperCAmelCase__ (  self :    str							,				A :    Tuple							,				A :    List[str]							,				A :    Optional[Any]							,				A :    Optional[int]							,				A :    List[Any]							,				A :    Any		):
         __snake_case:						Union[str, Any]   =						self.num_labels
         __snake_case:						str   =						DistilBertForSequenceClassification(A		)
         model.to(A		)
         model.eval()
         __snake_case:						Tuple   =						model(A							,				attention_mask=A							,				labels=A		)
         self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.num_labels)		)




       def 							UpperCAmelCase__ (  self :    Any							,				A :    Tuple							,				A :    Union[str, Any]							,				A :    Optional[int]							,				A :    List[Any]							,				A :    List[Any]							,				A :    Dict		):
         __snake_case:						Dict   =						self.num_labels
         __snake_case:						List[str]   =						DistilBertForTokenClassification(config=A		)
         model.to(A		)
         model.eval()

         __snake_case:						str   =						model(A							,				attention_mask=A							,				labels=A		)
         self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.seq_length, self.num_labels)		)




       def 							UpperCAmelCase__ (  self :    Optional[Any]							,				A :    List[Any]							,				A :    str							,				A :    Optional[Any]							,				A :    str							,				A :    List[str]							,				A :    List[Any]		):
         __snake_case:						Any   =						self.num_choices
         __snake_case:						Union[str, Any]   =						DistilBertForMultipleChoice(config=A		)
         model.to(A		)
         model.eval()
         __snake_case:						Any   =						input_ids.unsqueeze(1		).expand(-1							,				self.num_choices							,				-1		).contiguous()
         __snake_case:						Union[str, Any]   =						input_mask.unsqueeze(1		).expand(-1							,				self.num_choices							,				-1		).contiguous()
         __snake_case:						Dict   =						model(
             A							,				attention_mask=A							,				labels=A							,				)
         self.parent.assertEqual(result.logits.shape							,				(self.batch_size, self.num_choices)		)






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







@require_torch
class     __snake_case       (							__lowerCamelCase   ,			__lowerCamelCase   ,			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 							UpperCAmelCase__ (  self :    Optional[int]		):
         __snake_case:						Union[str, Any]   =						DistilBertModelTester(self		)
         __snake_case:						Optional[int]   =						ConfigTester(self							,				config_class=A							,				dim=37		)




       def 							UpperCAmelCase__ (  self :    Any		):
         self.config_tester.run_common_tests()




       def 							UpperCAmelCase__ (  self :    Dict		):
         __snake_case:						Dict   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_model(*A		)




       def 							UpperCAmelCase__ (  self :    Optional[Any]		):
         __snake_case:						str   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_masked_lm(*A		)




       def 							UpperCAmelCase__ (  self :    Optional[int]		):
         __snake_case:						Dict   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_question_answering(*A		)




       def 							UpperCAmelCase__ (  self :    Dict		):
         __snake_case:						Union[str, Any]   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_sequence_classification(*A		)




       def 							UpperCAmelCase__ (  self :    List[Any]		):
         __snake_case:						Optional[int]   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_token_classification(*A		)




       def 							UpperCAmelCase__ (  self :    Optional[int]		):
         __snake_case:						Any   =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_multiple_choice(*A		)




       @slow
       def 							UpperCAmelCase__ (  self :    List[Any]		):
         for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __snake_case:						Tuple   =						DistilBertModel.from_pretrained(A		)
           self.assertIsNotNone(A		)






       @slow
       @require_torch_gpu
       def 							UpperCAmelCase__ (  self :    Any		):
         __snake_case  ,   __snake_case:						Any   =						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

           __snake_case:						Tuple   =						True
           __snake_case:						Optional[int]   =						model_class(config=A		)

           __snake_case:						List[Any]   =						self._prepare_for_class(A							,				A		)
           __snake_case:						Dict   =						torch.jit.trace(
               A							,				(inputs_dict["""input_ids"""].to("""cpu"""		), inputs_dict["""attention_mask"""].to("""cpu"""		))		)

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







@require_torch
class     __snake_case       (							unittest.TestCase			):





       '''simple docstring'''







       @slow
       def 							UpperCAmelCase__ (  self :    str		):
         __snake_case:						Optional[Any]   =						DistilBertModel.from_pretrained("""distilbert-base-uncased"""		)
         __snake_case:						Union[str, Any]   =						torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]		)
         __snake_case:						Any   =						torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
         with torch.no_grad():
           __snake_case:						Any   =						model(A							,				attention_mask=A		)[0]
         __snake_case:						Dict   =						torch.Size((1, 11, 768)		)
         self.assertEqual(output.shape							,				A		)
         __snake_case:						Optional[int]   =						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]							,				A							,				atol=1E-4		)		)













from __future__ import annotations

import typing
from collections import Counter







def 			A__							(    SCREAMING_SNAKE_CASE__)   ->    typing.Counter[int]:
  __snake_case:						typing.Counter[int]   =						Counter()
  for base in range(1					,					max_perimeter + 1):
    for perpendicular in range(SCREAMING_SNAKE_CASE__					,					max_perimeter + 1):
      __snake_case:						Dict   =						(base * base + perpendicular * perpendicular) ** 0.5
      if hypotenuse == int(SCREAMING_SNAKE_CASE__):
        __snake_case:						Any   =						int(base + perpendicular + hypotenuse)
        if perimeter > max_perimeter:
          continue
        triplets[perimeter] += 1
  return triplets







def 			A__							(    SCREAMING_SNAKE_CASE__ = 1000)   ->    int:
  __snake_case:						List[str]   =						pythagorean_triple(SCREAMING_SNAKE_CASE__)
  return triplets.most_common(1)[0][0]


if __name__ == "__main__":
      print(f'Perimeter {solution()} has maximum solutions')






