





'''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


__lowercase  :   List[str]						      =logging.get_logger(__name__)

__lowercase  :   List[Any]						      ={
    """microsoft/layoutlmv3-base""": """https://huggingface.co/microsoft/layoutlmv3-base/resolve/main/config.json""",
}

class      A       (	__lowercase						):
      _snake_case							     ='''layoutlmv3'''



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

         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		,  )
         UpperCAmelCase_											=max_ad_position_embeddings
         UpperCAmelCase_											=coordinate_size
         UpperCAmelCase_											=shape_size
         UpperCAmelCase_											=has_relative_attention_bias
         UpperCAmelCase_											=rel_pos_bins
         UpperCAmelCase_											=max_rel_pos
         UpperCAmelCase_											=has_spatial_attention_bias
         UpperCAmelCase_											=rel_ad_pos_bins
         UpperCAmelCase_											=max_rel_ad_pos
         UpperCAmelCase_											=text_embed
         UpperCAmelCase_											=visual_embed
         UpperCAmelCase_											=input_size
         UpperCAmelCase_											=num_channels
         UpperCAmelCase_											=patch_size
         UpperCAmelCase_											=classifier_dropout

class      A       (	__lowercase						):
      _snake_case							     =version.parse('''1.12'''						)



      @property
      def 	lowerCAmelCase__    (	self:						List[Any]       )						->    Mapping[str, Mapping[int, str]]:
         '''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 	lowerCAmelCase__    (	self:						Optional[Any]       )						->    float:
         '''simple docstring'''

         return 1e-5



      @property
      def 	lowerCAmelCase__    (	self:						int       )						->    int:
         '''simple docstring'''

         return 12






      def 	lowerCAmelCase__    (	self:						List[Any]		,  _lowerCAmelCase:						"ProcessorMixin"		,  _lowerCAmelCase:						int = -1		,  _lowerCAmelCase:						int = -1		,  _lowerCAmelCase:						bool = False		,  _lowerCAmelCase:						Optional["TensorType"] = None		,  _lowerCAmelCase:						int = 3		,  _lowerCAmelCase:						int = 40		,  _lowerCAmelCase:						int = 40		,  )						->    Mapping[str, Any]:
         '''simple docstring'''

         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
         UpperCAmelCase_											=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
         UpperCAmelCase_											=processor.tokenizer.num_special_tokens_to_add(_lowerCAmelCase       )
         UpperCAmelCase_											=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
         UpperCAmelCase_											=[[" ".join([processor.tokenizer.unk_token]       ) * seq_length]] * batch_size

         # Generate dummy bounding boxes
         UpperCAmelCase_											=[[[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)
         UpperCAmelCase_											=self._generate_dummy_images(_lowerCAmelCase		,  _lowerCAmelCase		,  _lowerCAmelCase		,  _lowerCAmelCase       )

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

         return inputs











__lowercase  :   Dict						      ="""0.21.0"""

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
     from .utils import rich




