






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


_SCREAMING_SNAKE_CASE   =  logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE   =  {
    "funnel-transformer/small": "https://huggingface.co/funnel-transformer/small/resolve/main/config.json",
    "funnel-transformer/small-base": "https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json",
    "funnel-transformer/medium": "https://huggingface.co/funnel-transformer/medium/resolve/main/config.json",
    "funnel-transformer/medium-base": "https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json",
    "funnel-transformer/intermediate": (
        "https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json"
    ),
    "funnel-transformer/intermediate-base": (
        "https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json"
    ),
    "funnel-transformer/large": "https://huggingface.co/funnel-transformer/large/resolve/main/config.json",
    "funnel-transformer/large-base": "https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json",
    "funnel-transformer/xlarge": "https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json",
    "funnel-transformer/xlarge-base": "https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json",
}






class 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		Optional[int]					='''funnel'''
       __lowerCAmelCase    :		str					={
           '''hidden_size''': '''d_model''',
           '''num_attention_heads''': '''n_head''',
       }





       def __init__(				self	:Dict,      snake_case	:Union[str, Any]=3_0522,      snake_case	:Any=[4, 4, 4],      snake_case	:Dict=None,      snake_case	:Any=2,      snake_case	:Dict=768,      snake_case	:str=12,      snake_case	:Dict=64,      snake_case	:Union[str, Any]=3072,      snake_case	:List[str]="gelu_new",      snake_case	:List[str]=0.1,      snake_case	:Union[str, Any]=0.1,      snake_case	:Union[str, Any]=0.0,      snake_case	:int=0.1,      snake_case	:Tuple=None,      snake_case	:Optional[Any]=1e-9,      snake_case	:Optional[int]="mean",      snake_case	:List[str]="relative_shift",      snake_case	:int=True,      snake_case	:str=True,      snake_case	:List[str]=True,      **snake_case	:Optional[int],      ):



          """simple docstring"""

          _lowercase              =vocab_size
          _lowercase              =block_sizes
          _lowercase              =[1] * len(snake_case) if block_repeats is None else block_repeats
          assert len(snake_case) == len(
              self.block_repeats), "`block_sizes` and `block_repeats` should have the same length."
          _lowercase              =num_decoder_layers
          _lowercase              =d_model
          _lowercase              =n_head
          _lowercase              =d_head
          _lowercase              =d_inner
          _lowercase              =hidden_act
          _lowercase              =hidden_dropout
          _lowercase              =attention_dropout
          _lowercase              =activation_dropout
          _lowercase              =initializer_range
          _lowercase              =initializer_std
          _lowercase              =layer_norm_eps
          assert pooling_type in [
              "mean",
              "max",
          ], f'''Got {pooling_type} for `pooling_type` but only \'mean\' and \'max\' are supported.'''
          _lowercase              =pooling_type
          assert attention_type in [
              "relative_shift",
              "factorized",
          ], f'''Got {attention_type} for `attention_type` but only \'relative_shift\' and \'factorized\' are supported.'''
          _lowercase              =attention_type
          _lowercase              =separate_cls
          _lowercase              =truncate_seq
          _lowercase              =pool_q_only

          super().__init__(**snake_case)





       @property
       def 				UpperCamelCase__						(				self	:Optional[Any]):



          """simple docstring"""

          return sum(self.block_sizes)





       @num_hidden_layers.setter
       def 				UpperCamelCase__						(				self	:Union[str, Any],      snake_case	:List[Any]):



          """simple docstring"""

          raise NotImplementedError(
              'This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.')





       @property
       def 				UpperCamelCase__						(				self	:Any):



          """simple docstring"""

          return len(self.block_sizes)





       @num_blocks.setter
       def 				UpperCamelCase__						(				self	:str,      snake_case	:List[str]):



          """simple docstring"""

          raise NotImplementedError('This model does not support the setting of `num_blocks`. Please set `block_sizes`.')










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


_SCREAMING_SNAKE_CASE   =  logging.get_logger(__name__)

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






class 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		Tuple					='''layoutlmv3'''





       def __init__(				self	:Optional[int],      snake_case	:int=5_0265,      snake_case	:int=768,      snake_case	:Any=12,      snake_case	:Union[str, Any]=12,      snake_case	:List[str]=3072,      snake_case	:List[str]="gelu",      snake_case	:List[str]=0.1,      snake_case	:Optional[int]=0.1,      snake_case	:Optional[int]=512,      snake_case	:Tuple=2,      snake_case	:Optional[Any]=0.0_2,      snake_case	:Optional[int]=1e-5,      snake_case	:Union[str, Any]=1,      snake_case	:Dict=0,      snake_case	:Tuple=2,      snake_case	:Tuple=1024,      snake_case	:Optional[Any]=128,      snake_case	:Optional[Any]=128,      snake_case	:List[str]=True,      snake_case	:str=32,      snake_case	:Optional[int]=128,      snake_case	:Dict=64,      snake_case	:List[str]=256,      snake_case	:Optional[Any]=True,      snake_case	:Optional[Any]=True,      snake_case	:Dict=True,      snake_case	:Optional[Any]=224,      snake_case	:int=3,      snake_case	:int=16,      snake_case	:str=None,      **snake_case	:Dict,      ):



          """simple docstring"""

          super().__init__(
              vocab_size=snake_case,      hidden_size=snake_case,      num_hidden_layers=snake_case,      num_attention_heads=snake_case,      intermediate_size=snake_case,      hidden_act=snake_case,      hidden_dropout_prob=snake_case,      attention_probs_dropout_prob=snake_case,      max_position_embeddings=snake_case,      type_vocab_size=snake_case,      initializer_range=snake_case,      layer_norm_eps=snake_case,      pad_token_id=snake_case,      bos_token_id=snake_case,      eos_token_id=snake_case,      **snake_case,      )
          _lowercase              =max_ad_position_embeddings
          _lowercase              =coordinate_size
          _lowercase              =shape_size
          _lowercase              =has_relative_attention_bias
          _lowercase              =rel_pos_bins
          _lowercase              =max_rel_pos
          _lowercase              =has_spatial_attention_bias
          _lowercase              =rel_ad_pos_bins
          _lowercase              =max_rel_ad_pos
          _lowercase              =text_embed
          _lowercase              =visual_embed
          _lowercase              =input_size
          _lowercase              =num_channels
          _lowercase              =patch_size
          _lowercase              =classifier_dropout






class 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		Optional[Any]					=version.parse('''1.12''' )





       @property
       def 				UpperCamelCase__						(				self	:Any):



          """simple docstring"""

          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	:Union[str, Any]):



          """simple docstring"""

          return 1e-5





       @property
       def 				UpperCamelCase__						(				self	:Union[str, Any]):



          """simple docstring"""

          return 12





       def 				UpperCamelCase__						(				self	:List[Any],      snake_case	:"ProcessorMixin",      snake_case	:int = -1,      snake_case	:int = -1,      snake_case	:bool = False,      snake_case	:Optional["TensorType"] = None,      snake_case	:int = 3,      snake_case	:int = 40,      snake_case	:int = 40,      ):



          """simple docstring"""

          setattr(processor.image_processor,      'apply_ocr',      snake_case)

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

          # Generate dummy bounding boxes
          _lowercase              =[[[48, 84, 73, 128]]] * 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)
          _lowercase              =self._generate_dummy_images(snake_case,      snake_case,      snake_case,      snake_case)

          _lowercase              =dict(
              processor(
                  snake_case,      text=snake_case,      boxes=snake_case,      return_tensors=snake_case,      ))

          return inputs


