

'''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    : int				,				UpperCAmelCase__    : Tuple				,				UpperCAmelCase__    : int=1_3				,				UpperCAmelCase__    : Tuple=7				,				UpperCAmelCase__    : Optional[Any]=True				,				UpperCAmelCase__    : Union[str, Any]=True				,				UpperCAmelCase__    : Dict=True				,				UpperCAmelCase__    : List[Any]=True				,				UpperCAmelCase__    : int=9_9				,				UpperCAmelCase__    : str=3_2				,				UpperCAmelCase__    : str=2				,				UpperCAmelCase__    : Tuple=4				,				UpperCAmelCase__    : Optional[Any]=3_7				,				UpperCAmelCase__    : List[str]="gelu"				,				UpperCAmelCase__    : List[Any]=0.1				,				UpperCAmelCase__    : str=0.1				,				UpperCAmelCase__    : Union[str, Any]=5_1_2				,				UpperCAmelCase__    : Optional[Any]=1_6				,				UpperCAmelCase__    : Optional[int]=2				,				UpperCAmelCase__    : Optional[Any]=0.02				,				UpperCAmelCase__    : str=3				,				UpperCAmelCase__    : int=4				,				UpperCAmelCase__    : int=None				,				)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[Any]       =   parent
        SCREAMING_SNAKE_CASE :      Tuple       =   1_3
        SCREAMING_SNAKE_CASE :      Dict       =   7
        SCREAMING_SNAKE_CASE :      List[str]       =   True
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   True
        SCREAMING_SNAKE_CASE :      Tuple       =   True
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   True
        SCREAMING_SNAKE_CASE :      str       =   9_9
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   3_8_4
        SCREAMING_SNAKE_CASE :      Optional[int]       =   2
        SCREAMING_SNAKE_CASE :      str       =   4
        SCREAMING_SNAKE_CASE :      str       =   3_7
        SCREAMING_SNAKE_CASE :      List[Any]       =   """gelu"""
        SCREAMING_SNAKE_CASE :      Dict       =   0.1
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   0.1
        SCREAMING_SNAKE_CASE :      Dict       =   5_1_2
        SCREAMING_SNAKE_CASE :      int       =   1_6
        SCREAMING_SNAKE_CASE :      List[Any]       =   2
        SCREAMING_SNAKE_CASE :      str       =   0.02
        SCREAMING_SNAKE_CASE :      Optional[int]       =   3
        SCREAMING_SNAKE_CASE :      Tuple       =   4
        SCREAMING_SNAKE_CASE :      Any       =   1_2_8
        SCREAMING_SNAKE_CASE :      List[Any]       =   2
        SCREAMING_SNAKE_CASE :      str       =   9
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   1
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   None


  def  _lowercase      (			self    : Optional[int]		)					->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Any       =   ids_tensor([self.batch_size, self.seq_length]				,				self.vocab_size		)

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

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

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

        SCREAMING_SNAKE_CASE :      Dict       =   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  _lowercase      (			self    : Union[str, Any]				,				UpperCAmelCase__    : Optional[int]				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : Any				,				UpperCAmelCase__    : Any				,				UpperCAmelCase__    : Optional[Any]				,				UpperCAmelCase__    : Tuple				,				UpperCAmelCase__    : Dict		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   TFConvBertModel(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

        SCREAMING_SNAKE_CASE :      str       =   [input_ids, input_mask]
        SCREAMING_SNAKE_CASE :      Any       =   model(UpperCAmelCase__		)

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

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


  def  _lowercase      (			self    : Optional[int]				,				UpperCAmelCase__    : Dict				,				UpperCAmelCase__    : List[str]				,				UpperCAmelCase__    : Dict				,				UpperCAmelCase__    : Dict				,				UpperCAmelCase__    : Union[str, Any]				,				UpperCAmelCase__    : List[str]				,				UpperCAmelCase__    : str		)					->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   TFConvBertForMaskedLM(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Any       =   {
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }
        SCREAMING_SNAKE_CASE :      int       =   model(UpperCAmelCase__		)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size)		)


  def  _lowercase      (			self    : List[str]				,				UpperCAmelCase__    : Optional[Any]				,				UpperCAmelCase__    : List[Any]				,				UpperCAmelCase__    : List[str]				,				UpperCAmelCase__    : List[Any]				,				UpperCAmelCase__    : Union[str, Any]				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : Dict		)					->List[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   self.num_labels
        SCREAMING_SNAKE_CASE :      Tuple       =   TFConvBertForSequenceClassification(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   {
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }

        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   model(UpperCAmelCase__		)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_labels)		)


  def  _lowercase      (			self    : List[Any]				,				UpperCAmelCase__    : Any				,				UpperCAmelCase__    : List[Any]				,				UpperCAmelCase__    : Any				,				UpperCAmelCase__    : Optional[int]				,				UpperCAmelCase__    : str				,				UpperCAmelCase__    : List[str]				,				UpperCAmelCase__    : Tuple		)					->Any:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   self.num_choices
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   TFConvBertForMultipleChoice(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Dict       =   tf.tile(tf.expand_dims(UpperCAmelCase__				,				1		)				,				(1, self.num_choices, 1)		)
        SCREAMING_SNAKE_CASE :      Dict       =   tf.tile(tf.expand_dims(UpperCAmelCase__				,				1		)				,				(1, self.num_choices, 1)		)
        SCREAMING_SNAKE_CASE :      Dict       =   tf.tile(tf.expand_dims(UpperCAmelCase__				,				1		)				,				(1, self.num_choices, 1)		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   {
            """input_ids""": multiple_choice_inputs_ids,
            """attention_mask""": multiple_choice_input_mask,
            """token_type_ids""": multiple_choice_token_type_ids,
        }
        SCREAMING_SNAKE_CASE :      Dict       =   model(UpperCAmelCase__		)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_choices)		)


  def  _lowercase      (			self    : Tuple				,				UpperCAmelCase__    : Any				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : Tuple				,				UpperCAmelCase__    : Dict				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : Optional[int]				,				UpperCAmelCase__    : Dict		)					->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.num_labels
        SCREAMING_SNAKE_CASE :      Optional[int]       =   TFConvBertForTokenClassification(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   {
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }
        SCREAMING_SNAKE_CASE :      Any       =   model(UpperCAmelCase__		)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.num_labels)		)


  def  _lowercase      (			self    : Tuple				,				UpperCAmelCase__    : Tuple				,				UpperCAmelCase__    : str				,				UpperCAmelCase__    : int				,				UpperCAmelCase__    : Tuple				,				UpperCAmelCase__    : List[str]				,				UpperCAmelCase__    : Optional[Any]				,				UpperCAmelCase__    : List[str]		)					->Dict:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   TFConvBertForQuestionAnswering(config=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   {
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }

        SCREAMING_SNAKE_CASE :      Optional[int]       =   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  _lowercase      (			self    : int		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      int       =   self.prepare_config_and_inputs()
        (
            SCREAMING_SNAKE_CASE	
        ) :      Dict       =   config_and_inputs
        SCREAMING_SNAKE_CASE :      Tuple       =   {"""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__      : Dict			       =(
      (
          TFConvBertModel,
          TFConvBertForMaskedLM,
          TFConvBertForQuestionAnswering,
          TFConvBertForSequenceClassification,
          TFConvBertForTokenClassification,
          TFConvBertForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  UpperCAmelCase__      : List[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__      : Dict			       =False
  UpperCAmelCase__      : Union[str, Any]			       =False
  UpperCAmelCase__      : List[str]			       =False


  def  _lowercase      (			self    : int		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[Any]       =   TFConvBertModelTester(self		)
        SCREAMING_SNAKE_CASE :      Any       =   ConfigTester(self				,				config_class=UpperCAmelCase__				,				hidden_size=3_7		)


  def  _lowercase      (			self    : str		)					->int:
        """simple docstring"""







        self.config_tester.run_common_tests()


  def  _lowercase      (			self    : Dict		)					->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__		)


  def  _lowercase      (			self    : Union[str, Any]		)					->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Tuple       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__		)


  def  _lowercase      (			self    : List[Any]		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Tuple       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase__		)


  def  _lowercase      (			self    : Any		)					->Dict:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[Any]       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__		)


  def  _lowercase      (			self    : Optional[int]		)					->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      int       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__		)


  def  _lowercase      (			self    : Union[str, Any]		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Any		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.model_tester.prepare_config_and_inputs_for_common()
        SCREAMING_SNAKE_CASE :      int       =   True
        SCREAMING_SNAKE_CASE :      Dict       =   True

        if hasattr(UpperCAmelCase__				,				"""use_cache"""		):
              SCREAMING_SNAKE_CASE :      Optional[Any]       =   True

        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   getattr(self.model_tester				,				"""encoder_seq_length"""				,				self.model_tester.seq_length		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   getattr(self.model_tester				,				"""key_length"""				,				UpperCAmelCase__		)

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE :      int       =   self._prepare_for_class(UpperCAmelCase__				,				UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      List[str]       =   model_class(UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      str       =   len(model(UpperCAmelCase__		)		)

              with tempfile.TemporaryDirectory() as tmpdirname:
                    model.save_pretrained(UpperCAmelCase__				,				saved_model=UpperCAmelCase__		)
                    SCREAMING_SNAKE_CASE :      List[Any]       =   os.path.join(UpperCAmelCase__				,				"""saved_model"""				,				"""1"""		)
                    SCREAMING_SNAKE_CASE :      int       =   tf.keras.models.load_model(UpperCAmelCase__		)
                    SCREAMING_SNAKE_CASE :      int       =   model(UpperCAmelCase__		)

                    if self.is_encoder_decoder:
                          SCREAMING_SNAKE_CASE :      int       =   outputs["""encoder_hidden_states"""]
                          SCREAMING_SNAKE_CASE :      Tuple       =   outputs["""encoder_attentions"""]
                    else:
                          SCREAMING_SNAKE_CASE :      str       =   outputs["""hidden_states"""]
                          SCREAMING_SNAKE_CASE :      Optional[int]       =   outputs["""attentions"""]

                    self.assertEqual(len(UpperCAmelCase__		)				,				UpperCAmelCase__		)

                    SCREAMING_SNAKE_CASE :      List[str]       =   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  _lowercase      (			self    : List[str]		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      int       =   TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""		)
        self.assertIsNotNone(UpperCAmelCase__		)




  def  _lowercase      (			self    : Any		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[Any]       =   self.model_tester.prepare_config_and_inputs_for_common()
        SCREAMING_SNAKE_CASE :      List[Any]       =   True
        SCREAMING_SNAKE_CASE :      Dict       =   getattr(self.model_tester				,				"""decoder_seq_length"""				,				self.model_tester.seq_length		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   getattr(self.model_tester				,				"""encoder_seq_length"""				,				self.model_tester.seq_length		)
        SCREAMING_SNAKE_CASE :      int       =   getattr(self.model_tester				,				"""key_length"""				,				UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[str]       =   getattr(self.model_tester				,				"""key_length"""				,				UpperCAmelCase__		)

        def check_decoder_attentions_output(UpperCAmelCase__    : Optional[int]		):
              SCREAMING_SNAKE_CASE :      str       =   len(UpperCAmelCase__		)
              self.assertEqual(out_len % 2				,				0		)
              SCREAMING_SNAKE_CASE :      Optional[int]       =   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(UpperCAmelCase__    : Union[str, Any]		):
              SCREAMING_SNAKE_CASE :      Any       =   [
                  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:
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   True
              SCREAMING_SNAKE_CASE :      Dict       =   False
              SCREAMING_SNAKE_CASE :      Any       =   model_class(UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      str       =   model(self._prepare_for_class(UpperCAmelCase__				,				UpperCAmelCase__		)		)
              SCREAMING_SNAKE_CASE :      List[Any]       =   len(UpperCAmelCase__		)
              self.assertEqual(config.output_hidden_states				,				UpperCAmelCase__		)
              check_encoder_attentions_output(UpperCAmelCase__		)

              if self.is_encoder_decoder:
                    SCREAMING_SNAKE_CASE :      List[Any]       =   model_class(UpperCAmelCase__		)
                    SCREAMING_SNAKE_CASE :      List[Any]       =   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"]
              SCREAMING_SNAKE_CASE :      Optional[Any]       =   True
              SCREAMING_SNAKE_CASE :      Optional[int]       =   model_class(UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Any       =   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
              SCREAMING_SNAKE_CASE :      Optional[Any]       =   True
              SCREAMING_SNAKE_CASE :      List[str]       =   True
              SCREAMING_SNAKE_CASE :      List[str]       =   model_class(UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Optional[Any]       =   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       ):







  """simple docstring"""




  @slow
  def  _lowercase      (			self    : Tuple		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[Any]       =   TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   tf.constant([[0, 1, 2, 3, 4, 5]]		)
        SCREAMING_SNAKE_CASE :      Tuple       =   model(UpperCAmelCase__		)[0]

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

        SCREAMING_SNAKE_CASE :      Any       =   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		)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


UpperCAmelCase__ :     str				    =    {"""processing_layoutxlm""": ["""LayoutXLMProcessor"""]}

try:
  if not is_sentencepiece_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__ :     Any				    =    ["""LayoutXLMTokenizer"""]

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__ :     List[str]				    =    ["""LayoutXLMTokenizerFast"""]

if TYPE_CHECKING:
  from .processing_layoutxlm import LayoutXLMProcessor

  try:
    if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_layoutxlm import LayoutXLMTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_layoutxlm_fast import LayoutXLMTokenizerFast

else:
  import sys

  UpperCAmelCase__ :     List[str]				    =    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




