





from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 import (
           TFConvBertForMaskedLM,
           TFConvBertForMultipleChoice,
           TFConvBertForQuestionAnswering,
           TFConvBertForSequenceClassification,
           TFConvBertForTokenClassification,
           TFConvBertModel,
       )

class  __A:

     def __init__(      self,       A,       A=13,       A=7,       A=True,       A=True,       A=True,       A=True,       A=99,       A=32,       A=2,       A=4,       A=37,       A="gelu",       A=0.1,       A=0.1,       A=512,       A=16,       A=2,       A=0.02,       A=3,       A=4,       A=None,       ):





            """simple docstring"""

            _UpperCamelCase              =						parent
            _UpperCamelCase              =						13
            _UpperCamelCase              =						7
            _UpperCamelCase              =						True
            _UpperCamelCase              =						True
            _UpperCamelCase              =						True
            _UpperCamelCase              =						True
            _UpperCamelCase              =						99
            _UpperCamelCase              =						384
            _UpperCamelCase              =						2
            _UpperCamelCase              =						4
            _UpperCamelCase              =						37
            _UpperCamelCase              =						'''gelu'''
            _UpperCamelCase              =						0.1
            _UpperCamelCase              =						0.1
            _UpperCamelCase              =						512
            _UpperCamelCase              =						16
            _UpperCamelCase              =						2
            _UpperCamelCase              =						0.02
            _UpperCamelCase              =						3
            _UpperCamelCase              =						4
            _UpperCamelCase              =						128
            _UpperCamelCase              =						2
            _UpperCamelCase              =						9
            _UpperCamelCase              =						1
            _UpperCamelCase              =						None

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

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

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

            _UpperCamelCase              =						None
            if self.use_token_type_ids:
                   _UpperCamelCase              =						ids_tensor([self.batch_size, self.seq_length],       self.type_vocab_size      )

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

            _UpperCamelCase              =						ConvBertConfig(
                vocab_size=self.vocab_size,       hidden_size=self.hidden_size,       num_hidden_layers=self.num_hidden_layers,       num_attention_heads=self.num_attention_heads,       intermediate_size=self.intermediate_size,       hidden_act=self.hidden_act,       hidden_dropout_prob=self.hidden_dropout_prob,       attention_probs_dropout_prob=self.attention_probs_dropout_prob,       max_position_embeddings=self.max_position_embeddings,       type_vocab_size=self.type_vocab_size,       initializer_range=self.initializer_range,       return_dict=A,       )

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

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertModel(config=A      )
            _UpperCamelCase              =						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

            _UpperCamelCase              =						[input_ids, input_mask]
            _UpperCamelCase              =						model(A      )

            _UpperCamelCase              =						model(A      )

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

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertForMaskedLM(config=A      )
            _UpperCamelCase              =						{
                '''input_ids''': input_ids,
                '''attention_mask''': input_mask,
                '''token_type_ids''': token_type_ids,
            }
            _UpperCamelCase              =						model(A      )
            self.parent.assertEqual(result.logits.shape,       (self.batch_size, self.seq_length, self.vocab_size)      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.num_labels
            _UpperCamelCase              =						TFConvBertForSequenceClassification(config=A      )
            _UpperCamelCase              =						{
                '''input_ids''': input_ids,
                '''attention_mask''': input_mask,
                '''token_type_ids''': token_type_ids,
            }

            _UpperCamelCase              =						model(A      )
            self.parent.assertEqual(result.logits.shape,       (self.batch_size, self.num_labels)      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.num_choices
            _UpperCamelCase              =						TFConvBertForMultipleChoice(config=A      )
            _UpperCamelCase              =						tf.tile(tf.expand_dims(A,       1      ),       (1, self.num_choices, 1)      )
            _UpperCamelCase              =						tf.tile(tf.expand_dims(A,       1      ),       (1, self.num_choices, 1)      )
            _UpperCamelCase              =						tf.tile(tf.expand_dims(A,       1      ),       (1, self.num_choices, 1)      )
            _UpperCamelCase              =						{
                '''input_ids''': multiple_choice_inputs_ids,
                '''attention_mask''': multiple_choice_input_mask,
                '''token_type_ids''': multiple_choice_token_type_ids,
            }
            _UpperCamelCase              =						model(A      )
            self.parent.assertEqual(result.logits.shape,       (self.batch_size, self.num_choices)      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						self.num_labels
            _UpperCamelCase              =						TFConvBertForTokenClassification(config=A      )
            _UpperCamelCase              =						{
                '''input_ids''': input_ids,
                '''attention_mask''': input_mask,
                '''token_type_ids''': token_type_ids,
            }
            _UpperCamelCase              =						model(A      )
            self.parent.assertEqual(result.logits.shape,       (self.batch_size, self.seq_length, self.num_labels)      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertForQuestionAnswering(config=A      )
            _UpperCamelCase              =						{
                '''input_ids''': input_ids,
                '''attention_mask''': input_mask,
                '''token_type_ids''': token_type_ids,
            }

            _UpperCamelCase              =						model(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      ):





            """simple docstring"""

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






@require_tf
class  __A(						__UpperCAmelCase						,			__UpperCAmelCase						,			unittest.TestCase ):
     __A	  =       (
         (
             TFConvBertModel,
             TFConvBertForMaskedLM,
             TFConvBertForQuestionAnswering,
             TFConvBertForSequenceClassification,
             TFConvBertForTokenClassification,
             TFConvBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     __A	  =       (
         {
             "feature-extraction": TFConvBertModel,
             "fill-mask": TFConvBertForMaskedLM,
             "question-answering": TFConvBertForQuestionAnswering,
             "text-classification": TFConvBertForSequenceClassification,
             "token-classification": TFConvBertForTokenClassification,
             "zero-shot": TFConvBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __A	  =       False
     __A	  =       False
     __A	  =       False

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertModelTester(self      )
            _UpperCamelCase              =						ConfigTester(self,       config_class=A,       hidden_size=37      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            self.config_tester.run_common_tests()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*A      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_masked_lm(*A      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_multiple_choice(*A      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_question_answering(*A      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_sequence_classification(*A      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_token_classification(*A      )

     @slow
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase       ,		_UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()
            _UpperCamelCase              =						True
            _UpperCamelCase              =						True

            if hasattr(A,       '''use_cache'''      ):
                   _UpperCamelCase              =						True

            _UpperCamelCase              =						getattr(self.model_tester,       '''encoder_seq_length''',       self.model_tester.seq_length      )
            _UpperCamelCase              =						getattr(self.model_tester,       '''key_length''',       A      )

            for model_class in self.all_model_classes:
                   _UpperCamelCase              =						self._prepare_for_class(A,       A      )
                   _UpperCamelCase              =						model_class(A      )
                   _UpperCamelCase              =						len(model(A      )      )

                   with tempfile.TemporaryDirectory() as tmpdirname:
                          model.save_pretrained(A,       saved_model=A      )
                          _UpperCamelCase              =						os.path.join(A,       '''saved_model''',       '''1'''      )
                          _UpperCamelCase              =						tf.keras.models.load_model(A      )
                          _UpperCamelCase              =						model(A      )

                          if self.is_encoder_decoder:
                                 _UpperCamelCase              =						outputs['''encoder_hidden_states''']
                                 _UpperCamelCase              =						outputs['''encoder_attentions''']
                          else:
                                 _UpperCamelCase              =						outputs['''hidden_states''']
                                 _UpperCamelCase              =						outputs['''attentions''']

                          self.assertEqual(len(A      ),       A      )

                          _UpperCamelCase              =						getattr(
                              self.model_tester,       '''expected_num_hidden_layers''',       self.model_tester.num_hidden_layers + 1      )

                          self.assertEqual(len(A      ),       A      )
                          self.assertListEqual(
                              list(output_hidden_states[0].shape[-2:]      ),       [self.model_tester.seq_length, self.model_tester.hidden_size],       )

                          self.assertEqual(len(A      ),       self.model_tester.num_hidden_layers      )
                          self.assertListEqual(
                              list(output_attentions[0].shape[-3:]      ),       [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length],       )

     @slow
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''      )
            self.assertIsNotNone(A      )



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase       ,		_UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()
            _UpperCamelCase              =						True
            _UpperCamelCase              =						getattr(self.model_tester,       '''decoder_seq_length''',       self.model_tester.seq_length      )
            _UpperCamelCase              =						getattr(self.model_tester,       '''encoder_seq_length''',       self.model_tester.seq_length      )
            _UpperCamelCase              =						getattr(self.model_tester,       '''key_length''',       A      )
            _UpperCamelCase              =						getattr(self.model_tester,       '''key_length''',       A      )

            def check_decoder_attentions_output(A      ):
                   _UpperCamelCase              =						len(A      )
                   self.assertEqual(out_len % 2,       0      )
                   _UpperCamelCase              =						outputs.decoder_attentions
                   self.assertEqual(len(A      ),       self.model_tester.num_hidden_layers      )
                   self.assertListEqual(
                       list(decoder_attentions[0].shape[-3:]      ),       [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length],       )

            def check_encoder_attentions_output(A      ):
                   _UpperCamelCase              =						[
                       t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
                   ]
                   self.assertEqual(len(A      ),       self.model_tester.num_hidden_layers      )
                   self.assertListEqual(
                       list(attentions[0].shape[-3:]      ),       [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length],       )

            for model_class in self.all_model_classes:
                   _UpperCamelCase              =						True
                   _UpperCamelCase              =						False
                   _UpperCamelCase              =						model_class(A      )
                   _UpperCamelCase              =						model(self._prepare_for_class(A,       A      )      )
                   _UpperCamelCase              =						len(A      )
                   self.assertEqual(config.output_hidden_states,       A      )
                   check_encoder_attentions_output(A      )

                   if self.is_encoder_decoder:
                          _UpperCamelCase              =						model_class(A      )
                          _UpperCamelCase              =						model(self._prepare_for_class(A,       A      )      )
                          self.assertEqual(config.output_hidden_states,       A      )
                          check_decoder_attentions_output(A      )

                   # Check that output attentions can also be changed via the config
                   del inputs_dict["output_attentions"]
                   _UpperCamelCase              =						True
                   _UpperCamelCase              =						model_class(A      )
                   _UpperCamelCase              =						model(self._prepare_for_class(A,       A      )      )
                   self.assertEqual(config.output_hidden_states,       A      )
                   check_encoder_attentions_output(A      )

                   # Check attention is always last and order is fine
                   _UpperCamelCase              =						True
                   _UpperCamelCase              =						True
                   _UpperCamelCase              =						model_class(A      )
                   _UpperCamelCase              =						model(self._prepare_for_class(A,       A      )      )

                   self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1),       len(A      )      )
                   self.assertEqual(model.config.output_hidden_states,       A      )
                   check_encoder_attentions_output(A      )






@require_tf
class  __A(						unittest.TestCase ):

     @slow
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''      )
            _UpperCamelCase              =						tf.constant([[0, 1, 2, 3, 4, 5]]      )
            _UpperCamelCase              =						model(A      )[0]

            _UpperCamelCase              =						[1, 6, 768]
            self.assertEqual(output.shape,       A      )

            _UpperCamelCase              =						tf.constant(
                [
                    [
                        [-0.03_475_493, -0.4_686_034, -0.30_638_832],
                        [0.22_637_248, -0.26_988_646, -0.7_423_424],
                        [0.10_324_868, -0.45_013_508, -0.58_280_784],
                    ]
                ]      )
            tf.debugging.assert_near(output[:, :3, :3],       A,       atol=1E-4      )













from math import factorial


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase = 20					):
       _UpperCamelCase              =						2 * n  # middle entry of odd rows starting at row 3 is the solution for n = 1,
       # 2, 3,...
       _UpperCamelCase              =						n // 2

       return int(factorial(lowerCAmelCase					) / (factorial(lowerCAmelCase					) * factorial(n - k					))					)


if __name__ == "__main__":
       import sys

       if len(sys.argv) == 1:
              print(solution(20))
       else:
              try:
                     lowercase    : Dict    	=  int(sys.argv[1])
                     print(solution(n))
              except ValueError:
                     print("""Invalid entry - please enter a number.""")






