






'''simple docstring'''







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     :   Tuple	      =		logging.get_logger(__name__)

UpperCamelCase     :   List[str]	      =		{
    'microsoft/layoutlmv3-base': 'https://huggingface.co/microsoft/layoutlmv3-base/resolve/main/config.json',
}




class 		UpperCamelCase__     (a      ):




		'''simple docstring'''





		_UpperCamelCase						=       "layoutlmv3"






		def __init__(   self ,_lowerCAmelCase=5_02_65 ,_lowerCAmelCase=7_68 ,_lowerCAmelCase=12 ,_lowerCAmelCase=12 ,_lowerCAmelCase=30_72 ,_lowerCAmelCase="gelu" ,_lowerCAmelCase=0.1 ,_lowerCAmelCase=0.1 ,_lowerCAmelCase=5_12 ,_lowerCAmelCase=2 ,_lowerCAmelCase=0.02 ,_lowerCAmelCase=1E-5 ,_lowerCAmelCase=1 ,_lowerCAmelCase=0 ,_lowerCAmelCase=2 ,_lowerCAmelCase=10_24 ,_lowerCAmelCase=1_28 ,_lowerCAmelCase=1_28 ,_lowerCAmelCase=True ,_lowerCAmelCase=32 ,_lowerCAmelCase=1_28 ,_lowerCAmelCase=64 ,_lowerCAmelCase=2_56 ,_lowerCAmelCase=True ,_lowerCAmelCase=True ,_lowerCAmelCase=True ,_lowerCAmelCase=2_24 ,_lowerCAmelCase=3 ,_lowerCAmelCase=16 ,_lowerCAmelCase=None ,**_lowerCAmelCase ,):
								super().__init__(
								    vocab_size=_lowerCAmelCase ,hidden_size=_lowerCAmelCase ,num_hidden_layers=_lowerCAmelCase ,num_attention_heads=_lowerCAmelCase ,intermediate_size=_lowerCAmelCase ,hidden_act=_lowerCAmelCase ,hidden_dropout_prob=_lowerCAmelCase ,attention_probs_dropout_prob=_lowerCAmelCase ,max_position_embeddings=_lowerCAmelCase ,type_vocab_size=_lowerCAmelCase ,initializer_range=_lowerCAmelCase ,layer_norm_eps=_lowerCAmelCase ,pad_token_id=_lowerCAmelCase ,bos_token_id=_lowerCAmelCase ,eos_token_id=_lowerCAmelCase ,**_lowerCAmelCase ,)
								lowerCamelCase__								=	max_ad_position_embeddings
								lowerCamelCase__								=	coordinate_size
								lowerCamelCase__								=	shape_size
								lowerCamelCase__								=	has_relative_attention_bias
								lowerCamelCase__								=	rel_pos_bins
								lowerCamelCase__								=	max_rel_pos
								lowerCamelCase__								=	has_spatial_attention_bias
								lowerCamelCase__								=	rel_ad_pos_bins
								lowerCamelCase__								=	max_rel_ad_pos
								lowerCamelCase__								=	text_embed
								lowerCamelCase__								=	visual_embed
								lowerCamelCase__								=	input_size
								lowerCamelCase__								=	num_channels
								lowerCamelCase__								=	patch_size
								lowerCamelCase__								=	classifier_dropout




class 		UpperCamelCase__     (a      ):




		'''simple docstring'''





		_UpperCamelCase						=       version.parse('1.12'      )






		@property
		def       UpperCamelCase_       (   self							):
								# 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							):
								return 1E-5






		@property
		def       UpperCamelCase_       (   self							):
								return 12






		def       UpperCamelCase_       (   self ,_lowerCAmelCase ,_lowerCAmelCase = -1 ,_lowerCAmelCase = -1 ,_lowerCAmelCase = False ,_lowerCAmelCase = None ,_lowerCAmelCase = 3 ,_lowerCAmelCase = 40 ,_lowerCAmelCase = 40 ,):
								setattr(processor.image_processor ,"""apply_ocr""" ,_lowerCAmelCase							)

								# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
								lowerCamelCase__								=	compute_effective_axis_dimension(
								    _lowerCAmelCase ,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
								lowerCamelCase__								=	processor.tokenizer.num_special_tokens_to_add(_lowerCAmelCase							)
								lowerCamelCase__								=	compute_effective_axis_dimension(
								    _lowerCAmelCase ,fixed_dimension=OnnxConfig.default_fixed_sequence ,num_token_to_add=_lowerCAmelCase							)
								# Generate dummy inputs according to compute batch and sequence
								lowerCamelCase__								=	[[""" """.join([processor.tokenizer.unk_token]							) * seq_length]] * batch_size

								# Generate dummy bounding boxes
								lowerCamelCase__								=	[[[48, 84, 73, 1_28]]] * 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)
								lowerCamelCase__								=	self._generate_dummy_images(_lowerCAmelCase ,_lowerCAmelCase ,_lowerCAmelCase ,_lowerCAmelCase							)

								lowerCamelCase__								=	dict(
								    processor(
								        _lowerCAmelCase ,text=_lowerCAmelCase ,boxes=_lowerCAmelCase ,return_tensors=_lowerCAmelCase ,)							)

								return inputs








'''simple docstring'''


import math

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE									=				{
    "facebook/data2vec-base-960h": "https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json",
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}

class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				List[Any]								=       "data2vec-audio"




 def __init__(						self      ,  _lowerCAmelCase=32      ,  _lowerCAmelCase=768      ,  _lowerCAmelCase=12      ,  _lowerCAmelCase=12      ,  _lowerCAmelCase=3072      ,  _lowerCAmelCase="gelu"      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase=0.02      ,  _lowerCAmelCase=1E-5      ,  _lowerCAmelCase="gelu"      ,  _lowerCAmelCase=(512, 512, 512, 512, 512, 512, 512)      ,  _lowerCAmelCase=(5, 2, 2, 2, 2, 2, 2)      ,  _lowerCAmelCase=(10, 3, 3, 3, 3, 2, 2)      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=16      ,  _lowerCAmelCase=19      ,  _lowerCAmelCase=5      ,  _lowerCAmelCase=0.05      ,  _lowerCAmelCase=10      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=10      ,  _lowerCAmelCase=0      ,  _lowerCAmelCase="sum"      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=256      ,  _lowerCAmelCase=(512, 512, 512, 512, 1500)      ,  _lowerCAmelCase=(5, 3, 3, 1, 1)      ,  _lowerCAmelCase=(1, 2, 3, 1, 1)      ,  _lowerCAmelCase=512      ,  _lowerCAmelCase=0      ,  _lowerCAmelCase=1      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=3      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=3      ,  _lowerCAmelCase=None      ,  **_lowerCAmelCase      ,  )     ->				Dict:
     super().__init__(**_lowerCAmelCase      ,  pad_token_id=_lowerCAmelCase      ,  bos_token_id=_lowerCAmelCase      ,  eos_token_id=_lowerCAmelCase		)
     _lowerCAmelCase						      =   hidden_size
     _lowerCAmelCase						      =   feat_extract_activation
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   conv_bias
     _lowerCAmelCase						      =   num_conv_pos_embeddings
     _lowerCAmelCase						      =   num_conv_pos_embedding_groups
     _lowerCAmelCase						      =   conv_pos_kernel_size
     _lowerCAmelCase						      =   len(self.conv_dim		)
     _lowerCAmelCase						      =   num_hidden_layers
     _lowerCAmelCase						      =   intermediate_size
     _lowerCAmelCase						      =   hidden_act
     _lowerCAmelCase						      =   num_attention_heads
     _lowerCAmelCase						      =   hidden_dropout
     _lowerCAmelCase						      =   attention_dropout
     _lowerCAmelCase						      =   activation_dropout
     _lowerCAmelCase						      =   feat_proj_dropout
     _lowerCAmelCase						      =   final_dropout
     _lowerCAmelCase						      =   layerdrop
     _lowerCAmelCase						      =   layer_norm_eps
     _lowerCAmelCase						      =   initializer_range
     _lowerCAmelCase						      =   vocab_size
     _lowerCAmelCase						      =   use_weighted_layer_sum

     if (
         (len(self.conv_stride		) != self.num_feat_extract_layers)
         or (len(self.conv_kernel		) != self.num_feat_extract_layers)
         or (len(self.conv_dim		) != self.num_feat_extract_layers)
     ):
         raise ValueError(
             "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
             " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
             f''' {len(self.conv_dim		)}`, `len(config.conv_stride) = {len(self.conv_stride		)}`,'''
             f''' `len(config.conv_kernel) = {len(self.conv_kernel		)}`.'''		)

     # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
     _lowerCAmelCase						      =   mask_time_prob
     _lowerCAmelCase						      =   mask_time_length
     _lowerCAmelCase						      =   mask_time_min_masks
     _lowerCAmelCase						      =   mask_feature_prob
     _lowerCAmelCase						      =   mask_feature_length
     _lowerCAmelCase						      =   mask_feature_min_masks

     # ctc loss
     _lowerCAmelCase						      =   ctc_loss_reduction
     _lowerCAmelCase						      =   ctc_zero_infinity

     # adapter
     _lowerCAmelCase						      =   add_adapter
     _lowerCAmelCase						      =   adapter_kernel_size
     _lowerCAmelCase						      =   adapter_stride
     _lowerCAmelCase						      =   num_adapter_layers
     _lowerCAmelCase						      =   output_hidden_size or hidden_size

     # SequenceClassification-specific parameter. Feel free to ignore for other classes.
     _lowerCAmelCase						      =   classifier_proj_size

     # XVector-specific parameters. Feel free to ignore for other classes.
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   list(_lowerCAmelCase		)
     _lowerCAmelCase						      =   xvector_output_dim





 @property
 def 				_snake_case (						self		)     ->				str:
     return math.prod(self.conv_stride		)


