
from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import tensorflow as tf

      from transformers.models.distilbert.modeling_tf_distilbert import (
          TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFDistilBertForMaskedLM,
          TFDistilBertForMultipleChoice,
          TFDistilBertForQuestionAnswering,
          TFDistilBertForSequenceClassification,
          TFDistilBertForTokenClassification,
          TFDistilBertModel,
      )



class 		UpperCamelCase__  :
   def __init__(self :					int					,				snake_case_ :					int					,				):
    __a :  Optional[Any]						=  parent
    __a :  int						=  1_3
    __a :  List[Any]						=  7
    __a :  Union[str, Any]						=  True
    __a :  Optional[int]						=  True
    __a :  str						=  False
    __a :  Any						=  True
    __a :  Optional[Any]						=  9_9
    __a :  Any						=  3_2
    __a :  int						=  2
    __a :  str						=  4
    __a :  List[Any]						=  3_7
    __a :  List[str]						=  '''gelu'''
    __a :  List[str]						=  0.1
    __a :  Dict						=  0.1
    __a :  Dict						=  5_1_2
    __a :  Optional[Any]						=  1_6
    __a :  int						=  2
    __a :  List[str]						=  0.02
    __a :  Optional[Any]						=  3
    __a :  Optional[Any]						=  4
    __a :  Dict						=  None
   def       lowerCAmelCase			(self :					Tuple   ):
    __a :  int						=  ids_tensor([self.batch_size, self.seq_length]					,				self.vocab_size   )

    __a :  int						=  None
    if self.use_input_mask:
     __a :  Any						=  random_attention_mask([self.batch_size, self.seq_length]   )

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

    __a :  int						=  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					,				)

    return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
   def       lowerCAmelCase			(self :					int					,				snake_case_ :					Tuple					,				snake_case_ :					Tuple					,				snake_case_ :					str					,				snake_case_ :					Tuple					,				snake_case_ :					Tuple					,				snake_case_ :					List[str]   ):
    __a :  List[str]						=  TFDistilBertModel(config=snake_case_   )
    __a :  Tuple						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}

    __a :  str						=  model(snake_case_   )

    __a :  Dict						=  [input_ids, input_mask]

    __a :  Optional[int]						=  model(snake_case_   )

    self.parent.assertEqual(result.last_hidden_state.shape					,				(self.batch_size, self.seq_length, self.hidden_size)   )
   def       lowerCAmelCase			(self :					Optional[int]					,				snake_case_ :					Tuple					,				snake_case_ :					str					,				snake_case_ :					Optional[int]					,				snake_case_ :					int					,				snake_case_ :					Dict					,				snake_case_ :					str   ):
    __a :  Any						=  TFDistilBertForMaskedLM(config=snake_case_   )
    __a :  Any						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    __a :  Tuple						=  model(snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.seq_length, self.vocab_size)   )
   def       lowerCAmelCase			(self :					str					,				snake_case_ :					Dict					,				snake_case_ :					Dict					,				snake_case_ :					Any					,				snake_case_ :					Optional[Any]					,				snake_case_ :					List[Any]					,				snake_case_ :					List[Any]   ):
    __a :  List[Any]						=  TFDistilBertForQuestionAnswering(config=snake_case_   )
    __a :  Any						=  {
        '''input_ids''': input_ids,
        '''attention_mask''': input_mask,
    }
    __a :  List[Any]						=  model(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       lowerCAmelCase			(self :					str					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Optional[int]					,				snake_case_ :					Tuple					,				snake_case_ :					List[Any]					,				snake_case_ :					Union[str, Any]					,				snake_case_ :					Any   ):
    __a :  Dict						=  self.num_labels
    __a :  Any						=  TFDistilBertForSequenceClassification(snake_case_   )
    __a :  List[str]						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    __a :  List[str]						=  model(snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.num_labels)   )
   def       lowerCAmelCase			(self :					Dict					,				snake_case_ :					Tuple					,				snake_case_ :					Dict					,				snake_case_ :					Any					,				snake_case_ :					str					,				snake_case_ :					Optional[Any]					,				snake_case_ :					str   ):
    __a :  Union[str, Any]						=  self.num_choices
    __a :  List[str]						=  TFDistilBertForMultipleChoice(snake_case_   )
    __a :  int						=  tf.tile(tf.expand_dims(snake_case_					,				1   )					,				(1, self.num_choices, 1)   )
    __a :  List[Any]						=  tf.tile(tf.expand_dims(snake_case_					,				1   )					,				(1, self.num_choices, 1)   )
    __a :  Tuple						=  {
        '''input_ids''': multiple_choice_inputs_ids,
        '''attention_mask''': multiple_choice_input_mask,
    }
    __a :  List[str]						=  model(snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.num_choices)   )
   def       lowerCAmelCase			(self :					List[Any]					,				snake_case_ :					Union[str, Any]					,				snake_case_ :					Any					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Optional[int]					,				snake_case_ :					Any					,				snake_case_ :					List[Any]   ):
    __a :  Dict						=  self.num_labels
    __a :  Optional[int]						=  TFDistilBertForTokenClassification(snake_case_   )
    __a :  Optional[int]						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    __a :  str						=  model(snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.seq_length, self.num_labels)   )







   def       lowerCAmelCase			(self :					Union[str, Any]   ):
    __a :  Optional[int]						=  self.prepare_config_and_inputs()
    ((__a)				,       (__a)				,       (__a)				,       (__a)				,       (__a)				,       (__a)) :  Dict						=  config_and_inputs
    __a :  Union[str, Any]						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    return config, inputs_dict





@require_tf
class 		UpperCamelCase__  (       __lowercase    ,__lowercase    ,unittest.TestCase    ):
   _SCREAMING_SNAKE_CASE      :							Tuple	       =      (
       (
           TFDistilBertModel,
           TFDistilBertForMaskedLM,
           TFDistilBertForQuestionAnswering,
           TFDistilBertForSequenceClassification,
           TFDistilBertForTokenClassification,
           TFDistilBertForMultipleChoice,
       )
       if is_tf_available()
       else None
   )
   _SCREAMING_SNAKE_CASE      :							Any	       =      (
       {
           "feature-extraction": TFDistilBertModel,
           "fill-mask": TFDistilBertForMaskedLM,
           "question-answering": TFDistilBertForQuestionAnswering,
           "text-classification": TFDistilBertForSequenceClassification,
           "token-classification": TFDistilBertForTokenClassification,
           "zero-shot": TFDistilBertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   _SCREAMING_SNAKE_CASE      :							Optional[Any]	       =      False
   _SCREAMING_SNAKE_CASE      :							Optional[Any]	       =      False
   def       lowerCAmelCase			(self :					Tuple   ):
    __a :  Tuple						=  TFDistilBertModelTester(self   )
    __a :  Dict						=  ConfigTester(self					,				config_class=snake_case_					,				dim=3_7   )
   def       lowerCAmelCase			(self :					str   ):
    self.config_tester.run_common_tests()
   def       lowerCAmelCase			(self :					int   ):
    __a :  List[Any]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_model(*snake_case_   )
   def       lowerCAmelCase			(self :					Optional[Any]   ):
    __a :  List[str]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_for_masked_lm(*snake_case_   )
   def       lowerCAmelCase			(self :					Union[str, Any]   ):
    __a :  Dict						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_for_question_answering(*snake_case_   )
   def       lowerCAmelCase			(self :					Optional[Any]   ):
    __a :  Tuple						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_for_sequence_classification(*snake_case_   )
   def       lowerCAmelCase			(self :					Any   ):
    __a :  List[Any]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_for_multiple_choice(*snake_case_   )
   def       lowerCAmelCase			(self :					Optional[int]   ):
    __a :  Dict						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_distilbert_for_token_classification(*snake_case_   )







   @slow
   def       lowerCAmelCase			(self :					Any   ):
    for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]   ):
     __a :  Optional[Any]						=  TFDistilBertModel.from_pretrained(snake_case_   )
     self.assertIsNotNone(snake_case_   )





@require_tf
class 		UpperCamelCase__  (       unittest.TestCase    ):
   @slow
   def       lowerCAmelCase			(self :					int   ):
    __a :  Optional[int]						=  TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''   )
    __a :  Optional[int]						=  tf.constant([[0, 1, 2, 3, 4, 5]]   )
    __a :  str						=  model(snake_case_   )[0]

    __a :  Union[str, Any]						=  [1, 6, 7_6_8]
    self.assertEqual(output.shape					,				snake_case_   )

    __a :  int						=  tf.constant(
        [
            [
                [0.1926_1885, -0.1373_2955, 0.411_9799],
                [0.2215_0156, -0.0742_2661, 0.3903_7204],
                [0.2275_6018, -0.089_6414, 0.370_1467],
            ]
        ]   )
    tf.debugging.assert_near(output[:, :3, :3]					,				snake_case_					,				atol=1E-4   )


from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt




def    __UpperCamelCase     (				lowerCAmelCase__							:				int  ):
 __a :  int						=  int(number**0.5  )
 return number == sq * sq




def    __UpperCamelCase     (				lowerCAmelCase__							:				int  ,   lowerCAmelCase__							:				int  ,   lowerCAmelCase__							:				int  ,   lowerCAmelCase__							:				int  ,   lowerCAmelCase__							:				int  ,   lowerCAmelCase__							:				int  ):
 __a :  int						=  x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
 __a :  int						=  x_den * y_den * z_den
 __a :  int						=  gcd(lowerCAmelCase__  ,   lowerCAmelCase__  )
 top //= hcf
 bottom //= hcf
 return top, bottom




def    __UpperCamelCase     (				lowerCAmelCase__							:				int = 3_5  ):
 __a :  set						=  set()
 __a :  int
 __a :  Fraction						=  Fraction(0  )
 __a :  tuple[int, int]

 for x_num in range(1  ,   order + 1  ):
  for x_den in range(x_num + 1  ,   order + 1  ):
   for y_num in range(1  ,   order + 1  ):
    for y_den in range(y_num + 1  ,   order + 1  ):
     # n=1
     __a :  Any						=  x_num * y_den + x_den * y_num
     __a :  Dict						=  x_den * y_den
     __a :  int						=  gcd(lowerCAmelCase__  ,   lowerCAmelCase__  )
     z_num //= hcf
     z_den //= hcf
     if 0 < z_num < z_den <= order:
      __a :  str						=  add_three(
          lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  )
      unique_s.add(lowerCAmelCase__  )

     # n=2
     __a :  Union[str, Any]						=  (
         x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
     )
     __a :  Optional[Any]						=  x_den * x_den * y_den * y_den
     if is_sq(lowerCAmelCase__  ) and is_sq(lowerCAmelCase__  ):
      __a :  Any						=  int(sqrt(lowerCAmelCase__  )  )
      __a :  Optional[Any]						=  int(sqrt(lowerCAmelCase__  )  )
      __a :  int						=  gcd(lowerCAmelCase__  ,   lowerCAmelCase__  )
      z_num //= hcf
      z_den //= hcf
      if 0 < z_num < z_den <= order:
       __a :  str						=  add_three(
           lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  )
       unique_s.add(lowerCAmelCase__  )

                    # n=-1
     __a :  List[str]						=  x_num * y_num
     __a :  List[str]						=  x_den * y_num + x_num * y_den
     __a :  str						=  gcd(lowerCAmelCase__  ,   lowerCAmelCase__  )
     z_num //= hcf
     z_den //= hcf
     if 0 < z_num < z_den <= order:
      __a :  Optional[int]						=  add_three(
          lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  )
      unique_s.add(lowerCAmelCase__  )

     # n=2
     __a :  List[str]						=  x_num * x_num * y_num * y_num
     __a :  Optional[int]						=  (
         x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
     )
     if is_sq(lowerCAmelCase__  ) and is_sq(lowerCAmelCase__  ):
      __a :  Union[str, Any]						=  int(sqrt(lowerCAmelCase__  )  )
      __a :  List[str]						=  int(sqrt(lowerCAmelCase__  )  )
      __a :  Optional[int]						=  gcd(lowerCAmelCase__  ,   lowerCAmelCase__  )
      z_num //= hcf
      z_den //= hcf
      if 0 < z_num < z_den <= order:
       __a :  int						=  add_three(
           lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  )
       unique_s.add(lowerCAmelCase__  )

 for num, den in unique_s:
  total += Fraction(lowerCAmelCase__  ,   lowerCAmelCase__  )

 return total.denominator + total.numerator


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