





'''simple docstring'''






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   _lowercase						:


   def __init__( self    ,   _UpperCAmelCase    ,   ):
       A       :       Optional[int]							=						parent
       A       :       List[Any]							=						13
       A       :       Optional[int]							=						7
       A       :       Any							=						True
       A       :       Tuple							=						True
       A       :       List[Any]							=						False
       A       :       Any							=						True
       A       :       Optional[int]							=						99
       A       :       int							=						32
       A       :       Dict							=						2
       A       :       Dict							=						4
       A       :       Optional[int]							=						37
       A       :       Tuple							=						'''gelu'''
       A       :       Optional[Any]							=						0.1
       A       :       Dict							=						0.1
       A       :       str							=						512
       A       :       List[Any]							=						16
       A       :       Dict							=						2
       A       :       List[str]							=						0.02
       A       :       int							=						3
       A       :       Optional[int]							=						4
       A       :       Tuple							=						None


   def 					snake_case				( self					):
       A       :       Optional[Any]							=						ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size					)

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

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

       A       :       Any							=						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 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Tuple							=						TFDistilBertModel(config=UpperCAmelCase__					)
       A       :       int							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}

       A       :       Union[str, Any]							=						model(UpperCAmelCase__					)

       A       :       Tuple							=						[input_ids, input_mask]

       A       :       int							=						model(UpperCAmelCase__					)

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


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Optional[int]							=						TFDistilBertForMaskedLM(config=UpperCAmelCase__					)
       A       :       int							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
       A       :       Union[str, Any]							=						model(UpperCAmelCase__					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.vocab_size)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Union[str, Any]							=						TFDistilBertForQuestionAnswering(config=UpperCAmelCase__					)
       A       :       List[str]							=						{
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
       }
       A       :       Tuple							=						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 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Any							=						self.num_labels
       A       :       Optional[int]							=						TFDistilBertForSequenceClassification(UpperCAmelCase__					)
       A       :       Union[str, Any]							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
       A       :       List[Any]							=						model(UpperCAmelCase__					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Dict							=						self.num_choices
       A       :       Tuple							=						TFDistilBertForMultipleChoice(UpperCAmelCase__					)
       A       :       Dict							=						tf.tile(tf.expand_dims(UpperCAmelCase__    ,   1					)    ,   (1, self.num_choices, 1)					)
       A       :       str							=						tf.tile(tf.expand_dims(UpperCAmelCase__    ,   1					)    ,   (1, self.num_choices, 1)					)
       A       :       Tuple							=						{
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
       }
       A       :       Optional[Any]							=						model(UpperCAmelCase__					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_choices)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Optional[Any]							=						self.num_labels
       A       :       Any							=						TFDistilBertForTokenClassification(UpperCAmelCase__					)
       A       :       Tuple							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
       A       :       List[Any]							=						model(UpperCAmelCase__					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.num_labels)					)


   def 					snake_case				( self					):
       A       :       List[str]							=						self.prepare_config_and_inputs()
       (A)       :       Union[str, Any]							=						config_and_inputs
       A       :       Tuple							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
       return config, inputs_dict







@require_tf
class   _lowercase						(							a		,					a		,					unittest.TestCase				):
   _UpperCamelCase       		=   (
       (
           TFDistilBertModel,
           TFDistilBertForMaskedLM,
           TFDistilBertForQuestionAnswering,
           TFDistilBertForSequenceClassification,
           TFDistilBertForTokenClassification,
           TFDistilBertForMultipleChoice,
       )
       if is_tf_available()
       else None
   )
   _UpperCamelCase       		=   (
       {
           'feature-extraction': TFDistilBertModel,
           'fill-mask': TFDistilBertForMaskedLM,
           'question-answering': TFDistilBertForQuestionAnswering,
           'text-classification': TFDistilBertForSequenceClassification,
           'token-classification': TFDistilBertForTokenClassification,
           'zero-shot': TFDistilBertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   _UpperCamelCase       		=   False
   _UpperCamelCase       		=   False


   def 					snake_case				( self					):
       A       :       List[Any]							=						TFDistilBertModelTester(self					)
       A       :       Optional[Any]							=						ConfigTester(self    ,   config_class=UpperCAmelCase__    ,   dim=37					)


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


   def 					snake_case				( self					):
       A       :       Optional[Any]							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_model(*UpperCAmelCase__					)


   def 					snake_case				( self					):
       A       :       str							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_masked_lm(*UpperCAmelCase__					)


   def 					snake_case				( self					):
       A       :       List[str]							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_question_answering(*UpperCAmelCase__					)


   def 					snake_case				( self					):
       A       :       Optional[Any]							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_sequence_classification(*UpperCAmelCase__					)


   def 					snake_case				( self					):
       A       :       str							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_distilbert_for_multiple_choice(*UpperCAmelCase__					)


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


   @slow
   def 					snake_case				( self					):
       for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]					):
           A       :       str							=						TFDistilBertModel.from_pretrained(UpperCAmelCase__					)
           self.assertIsNotNone(UpperCAmelCase__					)







@require_tf
class   _lowercase						(							unittest.TestCase				):


   @slow
   def 					snake_case				( self					):
       A       :       Union[str, Any]							=						TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''					)
       A       :       List[str]							=						tf.constant([[0, 1, 2, 3, 4, 5]]					)
       A       :       Tuple							=						model(UpperCAmelCase__					)[0]

       A       :       List[str]							=						[1, 6, 768]
       self.assertEqual(output.shape    ,   UpperCAmelCase__					)

       A       :       Dict							=						tf.constant(
           [
               [
                   [0.19261885, -0.13732955, 0.4119799],
                   [0.22150156, -0.07422661, 0.39037204],
                   [0.22756018, -0.0896414, 0.3701467],
               ]
           ]					)
       tf.debugging.assert_near(output[:, :3, :3]    ,   UpperCAmelCase__    ,   atol=1E-4					)







'''simple docstring'''






from __future__ import annotations


class   _lowercase						:


   def __init__( self    ,   _UpperCAmelCase					):
       A       :       str							=						data
       A       :       Node | None							=						None
       A       :       Node | None							=						None







def 							_lowerCamelCase(  UpperCamelCase__    : Node | None		)		->  None:  # In Order traversal of the tree
    if tree:
        display(tree.left		)
        print(tree.data		)
        display(tree.right		)
def 							_lowerCamelCase(  UpperCamelCase__    : Node | None		)		->  int:
    return 1 + max(depth_of_tree(tree.left		)    ,       depth_of_tree(tree.right		)		) if tree else 0
def 							_lowerCamelCase(  UpperCamelCase__    : Node		)		->  bool:
    if not tree:
        return True
    if tree.left and tree.right:
        return is_full_binary_tree(tree.left		) and is_full_binary_tree(tree.right		)
    else:
        return not tree.left and not tree.right
def 							_lowerCamelCase(  )		->  None:  # Main function for testing.
    A       :       Optional[int]							=						Node(1		)
    A       :       Tuple							=						Node(2		)
    A       :       Dict							=						Node(3		)
    A       :       List[str]							=						Node(4		)
    A       :       Union[str, Any]							=						Node(5		)
    A       :       str							=						Node(6		)
    A       :       Any							=						Node(7		)
    A       :       str							=						Node(8		)
    A       :       Optional[int]							=						Node(9		)

    print(is_full_binary_tree(UpperCamelCase__		)		)
    print(depth_of_tree(UpperCamelCase__		)		)
    print('''Tree is: '''		)
    display(UpperCamelCase__		)


if __name__ == "__main__":
     main()
