


import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
    from ... import PreTrainedTokenizerBase, TensorType

__UpperCamelCase    :						Tuple     =							logging.get_logger(__name__)



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							Dict    = "vision-encoder-decoder"
   a_				:							Tuple    = True

   def __init__(  self  : List[Any]       ,  **_lowerCamelCase  : List[str]							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         if "encoder" not in kwargs or "decoder" not in kwargs:
               raise ValueError(
                   F"""A configuraton of type {self.model_type} cannot be instantiated because """
                   F"""not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}"""							)

         __lowerCamelCase     :      Union[str, Any]       						=						kwargs.pop("""encoder"""							)
         __lowerCamelCase     :      Union[str, Any]       						=						encoder_config.pop("""model_type"""							)
         __lowerCamelCase     :      Optional[int]       						=						kwargs.pop("""decoder"""							)
         __lowerCamelCase     :      str       						=						decoder_config.pop("""model_type"""							)

         __lowerCamelCase     :      str       						=						AutoConfig.for_model(_lowerCamelCase       ,  **_lowerCamelCase							)
         __lowerCamelCase     :      Tuple       						=						AutoConfig.for_model(_lowerCamelCase       ,  **_lowerCamelCase							)
         __lowerCamelCase     :      Union[str, Any]       						=						True

   @classmethod
   def   _snake_case    (  cls  : int       ,  _lowerCamelCase  : PretrainedConfig       ,  _lowerCamelCase  : PretrainedConfig       ,  **_lowerCamelCase  : str							):






         '''simple docstring'''



         logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""							)
         __lowerCamelCase     :      Optional[int]       						=						True
         __lowerCamelCase     :      Tuple       						=						True

         return cls(encoder=encoder_config.to_dict()       ,  decoder=decoder_config.to_dict()       ,  **_lowerCamelCase							)


   def   _snake_case    (  self  : Optional[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						copy.deepcopy(self.__dict__							)
         __lowerCamelCase     :      List[Any]       						=						self.encoder.to_dict()
         __lowerCamelCase     :      int       						=						self.decoder.to_dict()
         __lowerCamelCase     :      List[str]       						=						self.__class__.model_type
         return output



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							Optional[Any]    = version.parse("1.11"						)

   @property
   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         return OrderedDict(
             [
                 ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
             ]							)

   @property
   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         return 1E-4


   @property
   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         return OrderedDict({"""last_hidden_state""": {0: """batch""", 1: """encoder_sequence"""}}							)



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   @property
   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						OrderedDict()
         __lowerCamelCase     :      Any       						=						{0: """batch""", 1: """past_decoder_sequence + sequence"""}
         __lowerCamelCase     :      int       						=						{0: """batch""", 1: """past_decoder_sequence + sequence"""}
         __lowerCamelCase     :      Optional[int]       						=						{0: """batch""", 1: """encoder_sequence"""}

         return common_inputs


   def   _snake_case    (  self  : Optional[int]       ,  _lowerCamelCase  : "PreTrainedTokenizerBase"       ,  _lowerCamelCase  : int = -1       ,  _lowerCamelCase  : int = -1       ,  _lowerCamelCase  : bool = False       ,  _lowerCamelCase  : Optional["TensorType"] = None       ,  ):






         '''simple docstring'''



         import torch

         __lowerCamelCase     :      List[str]       						=						OrderedDict()

         __lowerCamelCase     :      List[str]       						=						super().generate_dummy_inputs(
             _lowerCamelCase       ,  batch_size=_lowerCamelCase       ,  seq_length=_lowerCamelCase       ,  is_pair=_lowerCamelCase       ,  framework=_lowerCamelCase							)

         __lowerCamelCase						, __lowerCamelCase     :      List[Any]       						=						dummy_input["""input_ids"""].shape
         __lowerCamelCase     :      Optional[Any]       						=						(batch, encoder_sequence, self._config.encoder_hidden_size)
         __lowerCamelCase     :      Any       						=						dummy_input.pop("""input_ids"""							)
         __lowerCamelCase     :      Dict       						=						dummy_input.pop("""attention_mask"""							)
         __lowerCamelCase     :      int       						=						torch.zeros(_lowerCamelCase							)

         return common_inputs



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   @property
   def   _snake_case    (  self  : Any							):






         '''simple docstring'''



         pass

   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : PretrainedConfig							):






         '''simple docstring'''



         return VisionEncoderDecoderEncoderOnnxConfig(_lowerCamelCase							)


   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : PretrainedConfig       ,  _lowerCamelCase  : PretrainedConfig       ,  _lowerCamelCase  : str = "default"							):






         '''simple docstring'''



         __lowerCamelCase     :      List[Any]       						=						encoder_config.hidden_size
         return VisionEncoderDecoderDecoderOnnxConfig(_lowerCamelCase       ,  _lowerCamelCase							)







from typing import TYPE_CHECKING

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


__UpperCamelCase    :						Union[str, Any]     =							{
    'configuration_layoutlmv2': ['LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LayoutLMv2Config'],
    'processing_layoutlmv2': ['LayoutLMv2Processor'],
    'tokenization_layoutlmv2': ['LayoutLMv2Tokenizer'],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __UpperCamelCase    :						List[str]     =							['LayoutLMv2TokenizerFast']

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __UpperCamelCase    :						List[str]     =							['LayoutLMv2FeatureExtractor']
    __UpperCamelCase    :						Union[str, Any]     =							['LayoutLMv2ImageProcessor']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __UpperCamelCase    :						Dict     =							[
        'LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST',
        'LayoutLMv2ForQuestionAnswering',
        'LayoutLMv2ForSequenceClassification',
        'LayoutLMv2ForTokenClassification',
        'LayoutLMv2Layer',
        'LayoutLMv2Model',
        'LayoutLMv2PreTrainedModel',
    ]

if TYPE_CHECKING:
    from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
    from .processing_layoutlmva import LayoutLMvaProcessor
    from .tokenization_layoutlmva import LayoutLMvaTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_layoutlmva import (
            LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
            LayoutLMvaForQuestionAnswering,
            LayoutLMvaForSequenceClassification,
            LayoutLMvaForTokenClassification,
            LayoutLMvaLayer,
            LayoutLMvaModel,
            LayoutLMvaPreTrainedModel,
        )
else:
    import sys

    __UpperCamelCase    :						Optional[Any]     =							_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



