






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







		'''simple docstring'''



		def __init__(							self    ,		_UpperCamelCase    ,		_UpperCamelCase=1_3    ,		_UpperCamelCase=7    ,		_UpperCamelCase=True    ,		_UpperCamelCase=True    ,		_UpperCamelCase=True    ,		_UpperCamelCase=True    ,		_UpperCamelCase=9_9    ,		_UpperCamelCase=3_2    ,		_UpperCamelCase=2    ,		_UpperCamelCase=4    ,		_UpperCamelCase=3_7    ,		_UpperCamelCase="gelu"    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=5_1_2    ,		_UpperCamelCase=1_6    ,		_UpperCamelCase=2    ,		_UpperCamelCase=0.02    ,		_UpperCamelCase=3    ,		_UpperCamelCase=4    ,		_UpperCamelCase=None    ,		)     ->							List[Any]:
							UpperCAmelCase_   :				List[Any]						=						parent
							UpperCAmelCase_   :				List[Any]						=						1_3
							UpperCAmelCase_   :				str						=						7
							UpperCAmelCase_   :				str						=						True
							UpperCAmelCase_   :				Union[str, Any]						=						True
							UpperCAmelCase_   :				Optional[int]						=						True
							UpperCAmelCase_   :				Dict						=						True
							UpperCAmelCase_   :				Optional[Any]						=						9_9
							UpperCAmelCase_   :				Optional[Any]						=						3_8_4
							UpperCAmelCase_   :				List[str]						=						2
							UpperCAmelCase_   :				str						=						4
							UpperCAmelCase_   :				Optional[Any]						=						3_7
							UpperCAmelCase_   :				Dict						=						'gelu'
							UpperCAmelCase_   :				List[str]						=						0.1
							UpperCAmelCase_   :				List[str]						=						0.1
							UpperCAmelCase_   :				Any						=						5_1_2
							UpperCAmelCase_   :				str						=						1_6
							UpperCAmelCase_   :				Optional[int]						=						2
							UpperCAmelCase_   :				str						=						0.02
							UpperCAmelCase_   :				Tuple						=						3
							UpperCAmelCase_   :				Dict						=						4
							UpperCAmelCase_   :				Optional[int]						=						1_2_8
							UpperCAmelCase_   :				List[str]						=						2
							UpperCAmelCase_   :				Optional[int]						=						9
							UpperCAmelCase_   :				Union[str, Any]						=						1
							UpperCAmelCase_   :				Union[str, Any]						=						None



		def  __UpperCAmelCase      (							self       )     ->							Tuple:
							UpperCAmelCase_   :				Any						=						ids_tensor([self.batch_size, self.seq_length]    ,		self.vocab_size       )

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

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

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

							UpperCAmelCase_   :				Optional[int]						=						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  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							Tuple:
							UpperCAmelCase_   :				Optional[Any]						=						TFConvBertModel(config=_UpperCamelCase       )
							UpperCAmelCase_   :				List[str]						=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

							UpperCAmelCase_   :				Optional[Any]						=						[input_ids, input_mask]
							UpperCAmelCase_   :				Dict						=						model(_UpperCamelCase       )

							UpperCAmelCase_   :				List[str]						=						model(_UpperCamelCase       )

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



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							Union[str, Any]:
							UpperCAmelCase_   :				Dict						=						TFConvBertForMaskedLM(config=_UpperCamelCase       )
							UpperCAmelCase_   :				Dict						=						{
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							UpperCAmelCase_   :				Dict						=						model(_UpperCamelCase       )
							self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.seq_length, self.vocab_size)       )



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							List[str]:
							UpperCAmelCase_   :				str						=						self.num_labels
							UpperCAmelCase_   :				Dict						=						TFConvBertForSequenceClassification(config=_UpperCamelCase       )
							UpperCAmelCase_   :				int						=						{
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							UpperCAmelCase_   :				List[Any]						=						model(_UpperCamelCase       )
							self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.num_labels)       )



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							Optional[Any]:
							UpperCAmelCase_   :				Any						=						self.num_choices
							UpperCAmelCase_   :				Union[str, Any]						=						TFConvBertForMultipleChoice(config=_UpperCamelCase       )
							UpperCAmelCase_   :				Union[str, Any]						=						tf.tile(tf.expand_dims(_UpperCamelCase    ,		1       )    ,		(1, self.num_choices, 1)       )
							UpperCAmelCase_   :				Dict						=						tf.tile(tf.expand_dims(_UpperCamelCase    ,		1       )    ,		(1, self.num_choices, 1)       )
							UpperCAmelCase_   :				List[str]						=						tf.tile(tf.expand_dims(_UpperCamelCase    ,		1       )    ,		(1, self.num_choices, 1)       )
							UpperCAmelCase_   :				Union[str, Any]						=						{
							    'input_ids': multiple_choice_inputs_ids,
							    'attention_mask': multiple_choice_input_mask,
							    'token_type_ids': multiple_choice_token_type_ids,
							}
							UpperCAmelCase_   :				List[str]						=						model(_UpperCamelCase       )
							self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.num_choices)       )



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							Tuple:
							UpperCAmelCase_   :				Union[str, Any]						=						self.num_labels
							UpperCAmelCase_   :				str						=						TFConvBertForTokenClassification(config=_UpperCamelCase       )
							UpperCAmelCase_   :				Optional[int]						=						{
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							UpperCAmelCase_   :				Any						=						model(_UpperCamelCase       )
							self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.seq_length, self.num_labels)       )



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )     ->							Union[str, Any]:
							UpperCAmelCase_   :				str						=						TFConvBertForQuestionAnswering(config=_UpperCamelCase       )
							UpperCAmelCase_   :				str						=						{
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							UpperCAmelCase_   :				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  __UpperCAmelCase      (							self       )     ->							Any:
							UpperCAmelCase_   :				Any						=						self.prepare_config_and_inputs()
							(
							    (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  (
							    UpperCAmelCase_
							)	,  
							)   :				List[Any]						=						config_and_inputs
							UpperCAmelCase_   :				Optional[int]						=						{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict





@require_tf
class   lowerCamelCase				(_snake_case			,  _snake_case			,  unittest.TestCase      ):







		'''simple docstring'''



		_snake_case   :   str							=  (
		    (
		        TFConvBertModel,
		        TFConvBertForMaskedLM,
		        TFConvBertForQuestionAnswering,
		        TFConvBertForSequenceClassification,
		        TFConvBertForTokenClassification,
		        TFConvBertForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		_snake_case   :   Tuple							=  (
		    {
		        '''feature-extraction''': TFConvBertModel,
		        '''fill-mask''': TFConvBertForMaskedLM,
		        '''question-answering''': TFConvBertForQuestionAnswering,
		        '''text-classification''': TFConvBertForSequenceClassification,
		        '''token-classification''': TFConvBertForTokenClassification,
		        '''zero-shot''': TFConvBertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		_snake_case   :   List[Any]							=  False
		_snake_case   :   Union[str, Any]							=  False
		_snake_case   :   str							=  False



		def  __UpperCAmelCase      (							self       )     ->							List[Any]:
							UpperCAmelCase_   :				Union[str, Any]						=						TFConvBertModelTester(self       )
							UpperCAmelCase_   :				Dict						=						ConfigTester(self    ,		config_class=_UpperCamelCase    ,		hidden_size=3_7       )



		def  __UpperCAmelCase      (							self       )     ->							List[Any]:
							self.config_tester.run_common_tests()



		def  __UpperCAmelCase      (							self       )     ->							Any:
							UpperCAmelCase_   :				int						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							int:
							UpperCAmelCase_   :				str						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							str:
							UpperCAmelCase_   :				Tuple						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							Optional[Any]:
							UpperCAmelCase_   :				str						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							int:
							UpperCAmelCase_   :				Optional[int]						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							Optional[Any]:
							UpperCAmelCase_   :				Dict						=						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*_UpperCamelCase       )



		@slow
		def  __UpperCAmelCase      (							self       )     ->							Tuple:
							UpperCAmelCase_	,  UpperCAmelCase_   :				int						=						self.model_tester.prepare_config_and_inputs_for_common()
							UpperCAmelCase_   :				Optional[int]						=						True
							UpperCAmelCase_   :				Tuple						=						True

							if hasattr(_UpperCamelCase    ,		'use_cache'       ):
												UpperCAmelCase_   :				List[str]						=						True

							UpperCAmelCase_   :				List[Any]						=						getattr(self.model_tester    ,		'encoder_seq_length'    ,		self.model_tester.seq_length       )
							UpperCAmelCase_   :				Optional[int]						=						getattr(self.model_tester    ,		'key_length'    ,		_UpperCamelCase       )

							for model_class in self.all_model_classes:
												UpperCAmelCase_   :				Union[str, Any]						=						self._prepare_for_class(_UpperCamelCase    ,		_UpperCamelCase       )
												UpperCAmelCase_   :				Dict						=						model_class(_UpperCamelCase       )
												UpperCAmelCase_   :				List[Any]						=						len(model(_UpperCamelCase       )       )

												with tempfile.TemporaryDirectory() as tmpdirname:
																	model.save_pretrained(_UpperCamelCase    ,		saved_model=_UpperCamelCase       )
																	UpperCAmelCase_   :				List[str]						=						os.path.join(_UpperCamelCase    ,		'saved_model'    ,		'1'       )
																	UpperCAmelCase_   :				Tuple						=						tf.keras.models.load_model(_UpperCamelCase       )
																	UpperCAmelCase_   :				List[str]						=						model(_UpperCamelCase       )

																	if self.is_encoder_decoder:
																						UpperCAmelCase_   :				str						=						outputs['encoder_hidden_states']
																						UpperCAmelCase_   :				List[Any]						=						outputs['encoder_attentions']
																	else:
																						UpperCAmelCase_   :				str						=						outputs['hidden_states']
																						UpperCAmelCase_   :				List[Any]						=						outputs['attentions']

																	self.assertEqual(len(_UpperCamelCase       )    ,		_UpperCamelCase       )

																	UpperCAmelCase_   :				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  __UpperCAmelCase      (							self       )     ->							Union[str, Any]:
							UpperCAmelCase_   :				Tuple						=						TFConvBertModel.from_pretrained('YituTech/conv-bert-base'       )
							self.assertIsNotNone(_UpperCamelCase       )



		def  __UpperCAmelCase      (							self       )     ->							Any:
							UpperCAmelCase_	,  UpperCAmelCase_   :				Union[str, Any]						=						self.model_tester.prepare_config_and_inputs_for_common()
							UpperCAmelCase_   :				Any						=						True
							UpperCAmelCase_   :				List[Any]						=						getattr(self.model_tester    ,		'decoder_seq_length'    ,		self.model_tester.seq_length       )
							UpperCAmelCase_   :				Optional[int]						=						getattr(self.model_tester    ,		'encoder_seq_length'    ,		self.model_tester.seq_length       )
							UpperCAmelCase_   :				Dict						=						getattr(self.model_tester    ,		'key_length'    ,		_UpperCamelCase       )
							UpperCAmelCase_   :				int						=						getattr(self.model_tester    ,		'key_length'    ,		_UpperCamelCase       )

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

												if self.is_encoder_decoder:
																	UpperCAmelCase_   :				Any						=						model_class(_UpperCamelCase       )
																	UpperCAmelCase_   :				Tuple						=						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"]
												UpperCAmelCase_   :				str						=						True
												UpperCAmelCase_   :				Tuple						=						model_class(_UpperCamelCase       )
												UpperCAmelCase_   :				Union[str, 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
												UpperCAmelCase_   :				List[Any]						=						True
												UpperCAmelCase_   :				Tuple						=						True
												UpperCAmelCase_   :				Optional[int]						=						model_class(_UpperCamelCase       )
												UpperCAmelCase_   :				Dict						=						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   lowerCamelCase				(unittest.TestCase      ):







		'''simple docstring'''



		@slow
		def  __UpperCAmelCase      (							self       )     ->							Optional[Any]:
							UpperCAmelCase_   :				Optional[int]						=						TFConvBertModel.from_pretrained('YituTech/conv-bert-base'       )
							UpperCAmelCase_   :				Any						=						tf.constant([[0, 1, 2, 3, 4, 5]]       )
							UpperCAmelCase_   :				List[str]						=						model(_UpperCamelCase       )[0]

							UpperCAmelCase_   :				Dict						=						[1, 6, 7_6_8]
							self.assertEqual(output.shape    ,		_UpperCamelCase       )

							UpperCAmelCase_   :				Optional[int]						=						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 collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


if TYPE_CHECKING:
		from ...processing_utils import ProcessorMixin
		from ...utils import TensorType


__UpperCAmelCase     							=						logging.get_logger(__name__)

__UpperCAmelCase     							=						{
    'microsoft/layoutlmv3-base': 'https://huggingface.co/microsoft/layoutlmv3-base/resolve/main/config.json',
}



class   lowerCamelCase				(_snake_case      ):







		'''simple docstring'''



		_snake_case   :   Dict							=  '''layoutlmv3'''



		def __init__(							self    ,		_UpperCamelCase=5_0_2_6_5    ,		_UpperCamelCase=7_6_8    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=1_2    ,		_UpperCamelCase=3_0_7_2    ,		_UpperCamelCase="gelu"    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=0.1    ,		_UpperCamelCase=5_1_2    ,		_UpperCamelCase=2    ,		_UpperCamelCase=0.02    ,		_UpperCamelCase=1E-5    ,		_UpperCamelCase=1    ,		_UpperCamelCase=0    ,		_UpperCamelCase=2    ,		_UpperCamelCase=1_0_2_4    ,		_UpperCamelCase=1_2_8    ,		_UpperCamelCase=1_2_8    ,		_UpperCamelCase=True    ,		_UpperCamelCase=3_2    ,		_UpperCamelCase=1_2_8    ,		_UpperCamelCase=6_4    ,		_UpperCamelCase=2_5_6    ,		_UpperCamelCase=True    ,		_UpperCamelCase=True    ,		_UpperCamelCase=True    ,		_UpperCamelCase=2_2_4    ,		_UpperCamelCase=3    ,		_UpperCamelCase=1_6    ,		_UpperCamelCase=None    ,		**_UpperCamelCase    ,		)     ->							Optional[Any]:
							super().__init__(
							    vocab_size=_UpperCamelCase    ,		hidden_size=_UpperCamelCase    ,		num_hidden_layers=_UpperCamelCase    ,		num_attention_heads=_UpperCamelCase    ,		intermediate_size=_UpperCamelCase    ,		hidden_act=_UpperCamelCase    ,		hidden_dropout_prob=_UpperCamelCase    ,		attention_probs_dropout_prob=_UpperCamelCase    ,		max_position_embeddings=_UpperCamelCase    ,		type_vocab_size=_UpperCamelCase    ,		initializer_range=_UpperCamelCase    ,		layer_norm_eps=_UpperCamelCase    ,		pad_token_id=_UpperCamelCase    ,		bos_token_id=_UpperCamelCase    ,		eos_token_id=_UpperCamelCase    ,		**_UpperCamelCase    ,		)
							UpperCAmelCase_   :				str						=						max_ad_position_embeddings
							UpperCAmelCase_   :				Union[str, Any]						=						coordinate_size
							UpperCAmelCase_   :				Union[str, Any]						=						shape_size
							UpperCAmelCase_   :				str						=						has_relative_attention_bias
							UpperCAmelCase_   :				Tuple						=						rel_pos_bins
							UpperCAmelCase_   :				Dict						=						max_rel_pos
							UpperCAmelCase_   :				Any						=						has_spatial_attention_bias
							UpperCAmelCase_   :				Optional[Any]						=						rel_ad_pos_bins
							UpperCAmelCase_   :				List[str]						=						max_rel_ad_pos
							UpperCAmelCase_   :				List[str]						=						text_embed
							UpperCAmelCase_   :				Dict						=						visual_embed
							UpperCAmelCase_   :				Optional[int]						=						input_size
							UpperCAmelCase_   :				List[Any]						=						num_channels
							UpperCAmelCase_   :				List[Any]						=						patch_size
							UpperCAmelCase_   :				Union[str, Any]						=						classifier_dropout





class   lowerCamelCase				(_snake_case      ):







		'''simple docstring'''



		_snake_case   :   Tuple							=  version.parse('''1.12'''      )



		@property
		def  __UpperCAmelCase      (							self       )     ->							Mapping[str, Mapping[int, str]]:
							# The order of inputs is different for question answering and sequence classification
							if self.task in ["question-answering", "sequence-classification"]:
												return OrderedDict(
												    [
												        ('input_ids', {0: 'batch', 1: 'sequence'}),
												        ('attention_mask', {0: 'batch', 1: 'sequence'}),
												        ('bbox', {0: 'batch', 1: 'sequence'}),
												        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
												    ]       )
							else:
												return OrderedDict(
												    [
												        ('input_ids', {0: 'batch', 1: 'sequence'}),
												        ('bbox', {0: 'batch', 1: 'sequence'}),
												        ('attention_mask', {0: 'batch', 1: 'sequence'}),
												        ('pixel_values', {0: 'batch', 1: 'num_channels'}),
												    ]       )



		@property
		def  __UpperCAmelCase      (							self       )     ->							float:
							return 1E-5



		@property
		def  __UpperCAmelCase      (							self       )     ->							int:
							return 1_2



		def  __UpperCAmelCase      (							self    ,		_UpperCamelCase    ,		_UpperCamelCase = -1    ,		_UpperCamelCase = -1    ,		_UpperCamelCase = False    ,		_UpperCamelCase = None    ,		_UpperCamelCase = 3    ,		_UpperCamelCase = 4_0    ,		_UpperCamelCase = 4_0    ,		)     ->							Mapping[str, Any]:
							setattr(processor.image_processor    ,		'apply_ocr'    ,		_UpperCamelCase       )

							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							UpperCAmelCase_   :				Optional[int]						=						compute_effective_axis_dimension(
							    _UpperCamelCase    ,		fixed_dimension=OnnxConfig.default_fixed_batch    ,		num_token_to_add=0       )
							# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
							UpperCAmelCase_   :				Any						=						processor.tokenizer.num_special_tokens_to_add(_UpperCamelCase       )
							UpperCAmelCase_   :				Any						=						compute_effective_axis_dimension(
							    _UpperCamelCase    ,		fixed_dimension=OnnxConfig.default_fixed_sequence    ,		num_token_to_add=_UpperCamelCase       )
							# Generate dummy inputs according to compute batch and sequence
							UpperCAmelCase_   :				Tuple						=						[[' '.join([processor.tokenizer.unk_token]       ) * seq_length]] * batch_size

							# Generate dummy bounding boxes
							UpperCAmelCase_   :				List[str]						=						[[[4_8, 8_4, 7_3, 1_2_8]]] * batch_size

							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							# batch_size = compute_effective_axis_dimension(batch_size, fixed_dimension=OnnxConfig.default_fixed_batch)
							UpperCAmelCase_   :				str						=						self._generate_dummy_images(_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase    ,		_UpperCamelCase       )

							UpperCAmelCase_   :				List[str]						=						dict(
							    processor(
							        _UpperCamelCase    ,		text=_UpperCamelCase    ,		boxes=_UpperCamelCase    ,		return_tensors=_UpperCamelCase    ,		)       )

							return inputs






