


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      ,				lowerCAmelCase      ,				lowerCAmelCase=1_3      ,				lowerCAmelCase=7      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=9_9      ,				lowerCAmelCase=3_2      ,				lowerCAmelCase=2      ,				lowerCAmelCase=4      ,				lowerCAmelCase=3_7      ,				lowerCAmelCase="gelu"      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=5_1_2      ,				lowerCAmelCase=1_6      ,				lowerCAmelCase=2      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=3      ,				lowerCAmelCase=4      ,				lowerCAmelCase=None      ,				):
									__lowercase=			parent
									__lowercase=			1_3
									__lowercase=			7
									__lowercase=			True
									__lowercase=			True
									__lowercase=			True
									__lowercase=			True
									__lowercase=			9_9
									__lowercase=			3_8_4
									__lowercase=			2
									__lowercase=			4
									__lowercase=			3_7
									__lowercase=			'gelu'
									__lowercase=			0.1
									__lowercase=			0.1
									__lowercase=			5_1_2
									__lowercase=			1_6
									__lowercase=			2
									__lowercase=			0.02
									__lowercase=			3
									__lowercase=			4
									__lowercase=			1_2_8
									__lowercase=			2
									__lowercase=			9
									__lowercase=			1
									__lowercase=			None


							def 			_A       (self					):
									__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
									if self.use_token_type_ids:
											__lowercase=			ids_tensor([self.batch_size, self.seq_length]      ,				self.type_vocab_size					)

									__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=			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=UpperCamelCase__      ,				)

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


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			TFConvBertModel(config=UpperCamelCase__					)
									__lowercase=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

									__lowercase=			[input_ids, input_mask]
									__lowercase=			model(UpperCamelCase__					)

									__lowercase=			model(UpperCamelCase__					)

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


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			TFConvBertForMaskedLM(config=UpperCamelCase__					)
									__lowercase=			{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}
									__lowercase=			model(UpperCamelCase__					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			TFConvBertForSequenceClassification(config=UpperCamelCase__					)
									__lowercase=			{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

									__lowercase=			model(UpperCamelCase__					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels)					)


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


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			TFConvBertForTokenClassification(config=UpperCamelCase__					)
									__lowercase=			{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}
									__lowercase=			model(UpperCamelCase__					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			TFConvBertForQuestionAnswering(config=UpperCamelCase__					)
									__lowercase=			{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

									__lowercase=			model(UpperCamelCase__					)
									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 			_A       (self					):
									__lowercase=			self.prepare_config_and_inputs()
									(
									    (
									    __lowercase      
									),							(
									    __lowercase      
									),							(
									    __lowercase      
									),							(
									    __lowercase      
									),							(
									    __lowercase      
									),							(
									    __lowercase      
									),							(
									    __lowercase      
									),							      
									)=			config_and_inputs
									__lowercase=			{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict





@require_tf
class       A    (   _a					,				_a					,				unittest.TestCase ):
							UpperCamelCase_   :							str       =(
							    (
							        TFConvBertModel,
							        TFConvBertForMaskedLM,
							        TFConvBertForQuestionAnswering,
							        TFConvBertForSequenceClassification,
							        TFConvBertForTokenClassification,
							        TFConvBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							UpperCamelCase_   :							int       =(
							    {
							        '''feature-extraction''': TFConvBertModel,
							        '''fill-mask''': TFConvBertForMaskedLM,
							        '''question-answering''': TFConvBertForQuestionAnswering,
							        '''text-classification''': TFConvBertForSequenceClassification,
							        '''token-classification''': TFConvBertForTokenClassification,
							        '''zero-shot''': TFConvBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							UpperCamelCase_   :							List[Any]       =False
							UpperCamelCase_   :							Optional[Any]       =False
							UpperCamelCase_   :							Optional[Any]       =False


							def 			_A       (self					):
									__lowercase=			TFConvBertModelTester(self					)
									__lowercase=			ConfigTester(self      ,				config_class=UpperCamelCase__      ,				hidden_size=3_7					)


							def 			_A       (self					):
									self.config_tester.run_common_tests()


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*UpperCamelCase__					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__					)


							@slow
							def 			_A       (self					):
									__lowercase,							__lowercase=			self.model_tester.prepare_config_and_inputs_for_common()
									__lowercase=			True
									__lowercase=			True

									if hasattr(UpperCamelCase__      ,				'use_cache'					):
											__lowercase=			True

									__lowercase=			getattr(self.model_tester      ,				'encoder_seq_length'      ,				self.model_tester.seq_length					)
									__lowercase=			getattr(self.model_tester      ,				'key_length'      ,				UpperCamelCase__					)

									for model_class in self.all_model_classes:
											__lowercase=			self._prepare_for_class(UpperCamelCase__      ,				UpperCamelCase__					)
											__lowercase=			model_class(UpperCamelCase__					)
											__lowercase=			len(model(UpperCamelCase__					)					)

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

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

													self.assertEqual(len(UpperCamelCase__					)      ,				UpperCamelCase__					)

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

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

													self.assertEqual(len(UpperCamelCase__					)      ,				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 			_A       (self					):
									__lowercase=			TFConvBertModel.from_pretrained('YituTech/conv-bert-base'					)
									self.assertIsNotNone(UpperCamelCase__					)







							def 			_A       (self					):
									__lowercase,							__lowercase=			self.model_tester.prepare_config_and_inputs_for_common()
									__lowercase=			True
									__lowercase=			getattr(self.model_tester      ,				'decoder_seq_length'      ,				self.model_tester.seq_length					)
									__lowercase=			getattr(self.model_tester      ,				'encoder_seq_length'      ,				self.model_tester.seq_length					)
									__lowercase=			getattr(self.model_tester      ,				'key_length'      ,				UpperCamelCase__					)
									__lowercase=			getattr(self.model_tester      ,				'key_length'      ,				UpperCamelCase__					)

									def check_decoder_attentions_output(lowerCAmelCase					):
											__lowercase=			len(UpperCamelCase__					)
											self.assertEqual(out_len % 2      ,				0					)
											__lowercase=			outputs.decoder_attentions
											self.assertEqual(len(UpperCamelCase__					)      ,				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(lowerCAmelCase					):
											__lowercase=			[
											    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
											]
											self.assertEqual(len(UpperCamelCase__					)      ,				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:
											__lowercase=			True
											__lowercase=			False
											__lowercase=			model_class(UpperCamelCase__					)
											__lowercase=			model(self._prepare_for_class(UpperCamelCase__      ,				UpperCamelCase__					)					)
											__lowercase=			len(UpperCamelCase__					)
											self.assertEqual(config.output_hidden_states      ,				UpperCamelCase__					)
											check_encoder_attentions_output(UpperCamelCase__					)

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

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

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

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





@require_tf
class       A    (   unittest.TestCase ):


							@slow
							def 			_A       (self					):
									__lowercase=			TFConvBertModel.from_pretrained('YituTech/conv-bert-base'					)
									__lowercase=			tf.constant([[0, 1, 2, 3, 4, 5]]					)
									__lowercase=			model(UpperCamelCase__					)[0]

									__lowercase=			[1, 6, 7_6_8]
									self.assertEqual(output.shape      ,				UpperCamelCase__					)

									__lowercase=			tf.constant(
									    [
									        [
									            [-0.03_47_54_93, -0.4_68_60_34, -0.30_63_88_32],
									            [0.22_63_72_48, -0.26_98_86_46, -0.7_42_34_24],
									            [0.10_32_48_68, -0.45_01_35_08, -0.58_28_07_84],
									        ]
									    ]					)
									tf.debugging.assert_near(output[:, :3, :3]      ,				UpperCamelCase__      ,				atol=1E-4					)











'''simple docstring'''


def 				__lowerCamelCase				(   A__ = 50    )       ->	int:






   """simple docstring"""
   UpperCamelCase					=  [1] * (length + 1)

   for row_length in range(3    ,						length + 1    ):
      for block_length in range(3    ,						row_length + 1    ):
         for block_start in range(row_length - block_length    ):
            ways_number[row_length] += ways_number[
                row_length - block_start - block_length - 1
            ]

         ways_number[row_length] += 1

   return ways_number[length]


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

