


"""simple docstring"""







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  :







    """simple docstring"""




    def __init__( self    :   Optional[int]    ,			__UpperCAmelCase    :   str    ,			__UpperCAmelCase    :   List[str]=13    ,			__UpperCAmelCase    :   str=7    ,			__UpperCAmelCase    :   List[str]=True    ,			__UpperCAmelCase    :   List[Any]=True    ,			__UpperCAmelCase    :   str=True    ,			__UpperCAmelCase    :   int=True    ,			__UpperCAmelCase    :   Optional[Any]=99    ,			__UpperCAmelCase    :   Union[str, Any]=32    ,			__UpperCAmelCase    :   int=2    ,			__UpperCAmelCase    :   Optional[Any]=4    ,			__UpperCAmelCase    :   Optional[Any]=37    ,			__UpperCAmelCase    :   Union[str, Any]="gelu"    ,			__UpperCAmelCase    :   str=0.1    ,			__UpperCAmelCase    :   List[Any]=0.1    ,			__UpperCAmelCase    :   Optional[Any]=512    ,			__UpperCAmelCase    :   Optional[int]=16    ,			__UpperCAmelCase    :   Optional[int]=2    ,			__UpperCAmelCase    :   List[Any]=0.02    ,			__UpperCAmelCase    :   List[str]=3    ,			__UpperCAmelCase    :   str=4    ,			__UpperCAmelCase    :   Tuple=None    ,			):
      a						:		Union[str, Any]											=      parent
      a						:		Dict											=      13
      a						:		Dict											=      7
      a						:		Tuple											=      True
      a						:		str											=      True
      a						:		Any											=      True
      a						:		str											=      True
      a						:		Union[str, Any]											=      99
      a						:		int											=      384
      a						:		Any											=      2
      a						:		str											=      4
      a						:		Union[str, Any]											=      37
      a						:		str											=      "gelu"
      a						:		List[Any]											=      0.1
      a						:		Optional[Any]											=      0.1
      a						:		int											=      512
      a						:		int											=      16
      a						:		Any											=      2
      a						:		Optional[int]											=      0.02
      a						:		int											=      3
      a						:		List[Any]											=      4
      a						:		Any											=      128
      a						:		List[Any]											=      2
      a						:		Optional[int]											=      9
      a						:		Dict											=      1
      a						:		Union[str, Any]											=      None






    def      __snake_case							( self    :   Optional[Any]):
      a						:		str											=      ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size)

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

      a						:		Dict											=      None
      if self.use_token_type_ids:
        a						:		List[str]											=      ids_tensor([self.batch_size, self.seq_length]    ,			self.type_vocab_size)

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

      a						:		List[str]											=      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=_SCREAMING_SNAKE_CASE    ,			)

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






    def      __snake_case							( self    :   str    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   Optional[Any]    ,			__UpperCAmelCase    :   str    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   Tuple):
      a						:		List[Any]											=      TFConvBertModel(config=_SCREAMING_SNAKE_CASE)
      a						:		Optional[int]											=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

      a						:		Tuple											=      [input_ids, input_mask]
      a						:		Optional[int]											=      model(_SCREAMING_SNAKE_CASE)

      a						:		Union[str, Any]											=      model(_SCREAMING_SNAKE_CASE)

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






    def      __snake_case							( self    :   int    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Dict    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Dict):
      a						:		Optional[Any]											=      TFConvBertForMaskedLM(config=_SCREAMING_SNAKE_CASE)
      a						:		Any											=      {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }
      a						:		Optional[int]											=      model(_SCREAMING_SNAKE_CASE)
      self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size))






    def      __snake_case							( self    :   Optional[int]    ,			__UpperCAmelCase    :   Optional[Any]    ,			__UpperCAmelCase    :   Tuple    ,			__UpperCAmelCase    :   Dict    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   Optional[Any]    ,			__UpperCAmelCase    :   Union[str, Any]    ,			__UpperCAmelCase    :   int):
      a						:		List[Any]											=      self.num_labels
      a						:		Union[str, Any]											=      TFConvBertForSequenceClassification(config=_SCREAMING_SNAKE_CASE)
      a						:		Union[str, Any]											=      {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }

      a						:		Any											=      model(_SCREAMING_SNAKE_CASE)
      self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels))






    def      __snake_case							( self    :   List[Any]    ,			__UpperCAmelCase    :   Union[str, Any]    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Optional[int]    ,			__UpperCAmelCase    :   Union[str, Any]    ,			__UpperCAmelCase    :   Tuple):
      a						:		Dict											=      self.num_choices
      a						:		Tuple											=      TFConvBertForMultipleChoice(config=_SCREAMING_SNAKE_CASE)
      a						:		Tuple											=      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,			1)    ,			(1, self.num_choices, 1))
      a						:		Optional[int]											=      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,			1)    ,			(1, self.num_choices, 1))
      a						:		List[Any]											=      tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,			1)    ,			(1, self.num_choices, 1))
      a						:		Any											=      {
          "input_ids": multiple_choice_inputs_ids,
          "attention_mask": multiple_choice_input_mask,
          "token_type_ids": multiple_choice_token_type_ids,
      }
      a						:		Tuple											=      model(_SCREAMING_SNAKE_CASE)
      self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices))






    def      __snake_case							( self    :   Tuple    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   str    ,			__UpperCAmelCase    :   Optional[int]    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Dict    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   Tuple):
      a						:		Optional[int]											=      self.num_labels
      a						:		Dict											=      TFConvBertForTokenClassification(config=_SCREAMING_SNAKE_CASE)
      a						:		int											=      {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }
      a						:		List[str]											=      model(_SCREAMING_SNAKE_CASE)
      self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels))






    def      __snake_case							( self    :   List[Any]    ,			__UpperCAmelCase    :   Optional[int]    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Dict    ,			__UpperCAmelCase    :   str    ,			__UpperCAmelCase    :   Optional[int]    ,			__UpperCAmelCase    :   Any    ,			__UpperCAmelCase    :   Union[str, Any]):
      a						:		Any											=      TFConvBertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE)
      a						:		Any											=      {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }

      a						:		Any											=      model(_SCREAMING_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      __snake_case							( self    :   List[str]):
      a						:		Optional[int]											=      self.prepare_config_and_inputs()
      (
          (
          a
      )							,		(
          a
      )							,		(
          a
      )							,		(
          a
      )							,		(
          a
      )							,		(
          a
      )							,		(
          a
      )							,		
      )						:		str											=      config_and_inputs
      a						:		Optional[int]											=      {"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  ):







    """simple docstring"""




    UpperCAmelCase	:							Any     =	(
        (
            TFConvBertModel,
            TFConvBertForMaskedLM,
            TFConvBertForQuestionAnswering,
            TFConvBertForSequenceClassification,
            TFConvBertForTokenClassification,
            TFConvBertForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    UpperCAmelCase	:							str     =	(
        {
            '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	:							Union[str, Any]     =	False
    UpperCAmelCase	:							List[str]     =	False






    def      __snake_case							( self    :   int):
      a						:		Any											=      TFConvBertModelTester(self)
      a						:		Any											=      ConfigTester(self    ,			config_class=_SCREAMING_SNAKE_CASE    ,			hidden_size=37)






    def      __snake_case							( self    :   Optional[int]):
      self.config_tester.run_common_tests()






    def      __snake_case							( self    :   Optional[Any]):
      a						:		Optional[int]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   int):
      a						:		List[Any]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   Tuple):
      a						:		Optional[Any]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   Union[str, Any]):
      a						:		Union[str, Any]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   Tuple):
      a						:		Dict											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   Dict):
      a						:		Optional[int]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE)






    @slow
    def      __snake_case							( self    :   str):
      a							,		a						:		Optional[int]											=      self.model_tester.prepare_config_and_inputs_for_common()
      a						:		int											=      True
      a						:		Union[str, Any]											=      True

      if hasattr(_SCREAMING_SNAKE_CASE    ,			"use_cache"):
        a						:		List[Any]											=      True

      a						:		List[str]											=      getattr(self.model_tester    ,			"encoder_seq_length"    ,			self.model_tester.seq_length)
      a						:		Optional[Any]											=      getattr(self.model_tester    ,			"key_length"    ,			_SCREAMING_SNAKE_CASE)

      for model_class in self.all_model_classes:
        a						:		str											=      self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE)
        a						:		int											=      model_class(_SCREAMING_SNAKE_CASE)
        a						:		int											=      len(model(_SCREAMING_SNAKE_CASE))

        with tempfile.TemporaryDirectory() as tmpdirname:
          model.save_pretrained(_SCREAMING_SNAKE_CASE    ,			saved_model=_SCREAMING_SNAKE_CASE)
          a						:		Any											=      os.path.join(_SCREAMING_SNAKE_CASE    ,			"saved_model"    ,			"1")
          a						:		Union[str, Any]											=      tf.keras.models.load_model(_SCREAMING_SNAKE_CASE)
          a						:		Optional[Any]											=      model(_SCREAMING_SNAKE_CASE)

          if self.is_encoder_decoder:
            a						:		str											=      outputs["encoder_hidden_states"]
            a						:		Tuple											=      outputs["encoder_attentions"]
          else:
            a						:		Any											=      outputs["hidden_states"]
            a						:		List[Any]											=      outputs["attentions"]

          self.assertEqual(len(_SCREAMING_SNAKE_CASE)    ,			_SCREAMING_SNAKE_CASE)

          a						:		List[str]											=      getattr(
              self.model_tester    ,			"expected_num_hidden_layers"    ,			self.model_tester.num_hidden_layers + 1)

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

          self.assertEqual(len(_SCREAMING_SNAKE_CASE)    ,			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      __snake_case							( self    :   List[str]):
      a						:		List[str]											=      TFConvBertModel.from_pretrained("YituTech/conv-bert-base")
      self.assertIsNotNone(_SCREAMING_SNAKE_CASE)






    def      __snake_case							( self    :   Tuple):
      a							,		a						:		Union[str, Any]											=      self.model_tester.prepare_config_and_inputs_for_common()
      a						:		Dict											=      True
      a						:		str											=      getattr(self.model_tester    ,			"decoder_seq_length"    ,			self.model_tester.seq_length)
      a						:		str											=      getattr(self.model_tester    ,			"encoder_seq_length"    ,			self.model_tester.seq_length)
      a						:		Optional[int]											=      getattr(self.model_tester    ,			"key_length"    ,			_SCREAMING_SNAKE_CASE)
      a						:		int											=      getattr(self.model_tester    ,			"key_length"    ,			_SCREAMING_SNAKE_CASE)

      def check_decoder_attentions_output(__UpperCAmelCase    :   Any):
        a						:		Tuple											=      len(_SCREAMING_SNAKE_CASE)
        self.assertEqual(out_len % 2    ,			0)
        a						:		Dict											=      outputs.decoder_attentions
        self.assertEqual(len(_SCREAMING_SNAKE_CASE)    ,			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(__UpperCAmelCase    :   List[str]):
        a						:		Optional[Any]											=      [
            t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
        ]
        self.assertEqual(len(_SCREAMING_SNAKE_CASE)    ,			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:
        a						:		Dict											=      True
        a						:		str											=      False
        a						:		List[Any]											=      model_class(_SCREAMING_SNAKE_CASE)
        a						:		Union[str, Any]											=      model(self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE))
        a						:		List[str]											=      len(_SCREAMING_SNAKE_CASE)
        self.assertEqual(config.output_hidden_states    ,			_SCREAMING_SNAKE_CASE)
        check_encoder_attentions_output(_SCREAMING_SNAKE_CASE)

        if self.is_encoder_decoder:
          a						:		Optional[int]											=      model_class(_SCREAMING_SNAKE_CASE)
          a						:		List[str]											=      model(self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE))
          self.assertEqual(config.output_hidden_states    ,			_SCREAMING_SNAKE_CASE)
          check_decoder_attentions_output(_SCREAMING_SNAKE_CASE)

        # Check that output attentions can also be changed via the config
        del inputs_dict["output_attentions"]
        a						:		str											=      True
        a						:		List[str]											=      model_class(_SCREAMING_SNAKE_CASE)
        a						:		Union[str, Any]											=      model(self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE))
        self.assertEqual(config.output_hidden_states    ,			_SCREAMING_SNAKE_CASE)
        check_encoder_attentions_output(_SCREAMING_SNAKE_CASE)

        # Check attention is always last and order is fine
        a						:		Tuple											=      True
        a						:		Union[str, Any]											=      True
        a						:		List[Any]											=      model_class(_SCREAMING_SNAKE_CASE)
        a						:		Union[str, Any]											=      model(self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE))

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






@require_tf
class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    @slow
    def      __snake_case							( self    :   Optional[Any]):
      a						:		int											=      TFConvBertModel.from_pretrained("YituTech/conv-bert-base")
      a						:		Optional[Any]											=      tf.constant([[0, 1, 2, 3, 4, 5]])
      a						:		Any											=      model(_SCREAMING_SNAKE_CASE)[0]

      a						:		Any											=      [1, 6, 768]
      self.assertEqual(output.shape    ,			_SCREAMING_SNAKE_CASE)

      a						:		Union[str, Any]											=      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]    ,			_SCREAMING_SNAKE_CASE    ,			atol=1e-4)










"""simple docstring"""







import sys
import turtle


def 					lowercase      (    A_  ,       A_	)->				tuple[float, float]:
  '''simple docstring'''







  return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2


def 					lowercase      (    A_  ,       A_  ,       A_  ,       A_  ,       )->				None:
  '''simple docstring'''







  my_pen.up()
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.down()
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)

  if depth == 0:
    return

  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)
  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)
  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)


if __name__ == "__main__":
 if len(sys.argv) != 2:
  raise ValueError(
      """Correct format for using this script: """
      """python fractals.py <int:depth_for_fractal>"""
  )
 __lowercase    =				turtle.Turtle()
 my_pen.ht()
 my_pen.speed(5)
 my_pen.pencolor("""red""")

 __lowercase    =				[(-175, -125), (0, 175), (175, -125)]  # vertices of triangle
 triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))






