


import copy
import os
from typing import Union

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


__UpperCamelCase    :						Any     =							logging.get_logger(__name__)

__UpperCamelCase    :						Optional[Any]     =							{
    'BridgeTower/bridgetower-base': 'https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json',
    'BridgeTower/bridgetower-base-itm-mlm': (
        'https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json'
    ),
}



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							Dict    = "bridgetower_vision_model"

   def __init__(  self  : Any       ,  _lowerCamelCase  : int=7_6_8       ,  _lowerCamelCase  : Optional[int]=1_2       ,  _lowerCamelCase  : Optional[Any]=3       ,  _lowerCamelCase  : Tuple=1_6       ,  _lowerCamelCase  : int=2_8_8       ,  _lowerCamelCase  : Tuple=1       ,  _lowerCamelCase  : Dict=1E-05       ,  _lowerCamelCase  : List[Any]=False       ,  _lowerCamelCase  : str=True       ,  _lowerCamelCase  : Union[str, Any]=False       ,  **_lowerCamelCase  : Dict       ,  ):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      Optional[int]       						=						hidden_size
         __lowerCamelCase     :      List[str]       						=						num_hidden_layers
         __lowerCamelCase     :      Optional[int]       						=						num_channels
         __lowerCamelCase     :      int       						=						patch_size
         __lowerCamelCase     :      Union[str, Any]       						=						image_size
         __lowerCamelCase     :      int       						=						initializer_factor
         __lowerCamelCase     :      List[str]       						=						layer_norm_eps
         __lowerCamelCase     :      Optional[int]       						=						stop_gradient
         __lowerCamelCase     :      Dict       						=						share_layernorm
         __lowerCamelCase     :      List[str]       						=						remove_last_layer


   @classmethod
   def   _snake_case    (  cls  : Dict       ,  _lowerCamelCase  : Union[str, os.PathLike]       ,  **_lowerCamelCase  : Union[str, Any]							):






         '''simple docstring'''



         __lowerCamelCase						, __lowerCamelCase     :      Union[str, Any]       						=						cls.get_config_dict(_lowerCamelCase       ,  **_lowerCamelCase							)

         if config_dict.get("""model_type"""							) == "bridgetower":
               __lowerCamelCase     :      Optional[int]       						=						config_dict["""text_config"""]

         if "model_type" in config_dict and hasattr(cls       ,  """model_type"""							) and config_dict["model_type"] != cls.model_type:
               logger.warning(
                   F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
                   F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

         return cls.from_dict(_lowerCamelCase       ,  **_lowerCamelCase							)



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							Optional[Any]    = "bridgetower_text_model"

   def __init__(  self  : Optional[Any]       ,  _lowerCamelCase  : List[Any]=5_0_2_6_5       ,  _lowerCamelCase  : Tuple=7_6_8       ,  _lowerCamelCase  : Dict=1_2       ,  _lowerCamelCase  : Union[str, Any]=1_2       ,  _lowerCamelCase  : List[Any]=1       ,  _lowerCamelCase  : Optional[int]=3_0_7_2       ,  _lowerCamelCase  : List[str]="gelu"       ,  _lowerCamelCase  : Union[str, Any]=0.1       ,  _lowerCamelCase  : List[str]=0.1       ,  _lowerCamelCase  : Dict=5_1_4       ,  _lowerCamelCase  : Union[str, Any]=1       ,  _lowerCamelCase  : Tuple=1E-05       ,  _lowerCamelCase  : Union[str, Any]=1       ,  _lowerCamelCase  : str=0       ,  _lowerCamelCase  : Optional[Any]=2       ,  _lowerCamelCase  : Any="absolute"       ,  _lowerCamelCase  : List[str]=True       ,  **_lowerCamelCase  : Optional[int]       ,  ):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)

         __lowerCamelCase     :      str       						=						vocab_size
         __lowerCamelCase     :      Optional[Any]       						=						hidden_size
         __lowerCamelCase     :      Tuple       						=						num_hidden_layers
         __lowerCamelCase     :      List[Any]       						=						num_attention_heads
         __lowerCamelCase     :      int       						=						hidden_act
         __lowerCamelCase     :      int       						=						initializer_factor
         __lowerCamelCase     :      List[Any]       						=						intermediate_size
         __lowerCamelCase     :      List[Any]       						=						hidden_dropout_prob
         __lowerCamelCase     :      str       						=						attention_probs_dropout_prob
         __lowerCamelCase     :      Tuple       						=						max_position_embeddings
         __lowerCamelCase     :      Any       						=						type_vocab_size
         __lowerCamelCase     :      Optional[Any]       						=						layer_norm_eps
         __lowerCamelCase     :      Optional[Any]       						=						position_embedding_type
         __lowerCamelCase     :      Any       						=						use_cache
         __lowerCamelCase     :      int       						=						pad_token_id
         __lowerCamelCase     :      Dict       						=						bos_token_id
         __lowerCamelCase     :      Optional[Any]       						=						eos_token_id


   @classmethod
   def   _snake_case    (  cls  : List[str]       ,  _lowerCamelCase  : Union[str, os.PathLike]       ,  **_lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase						, __lowerCamelCase     :      Dict       						=						cls.get_config_dict(_lowerCamelCase       ,  **_lowerCamelCase							)

         if config_dict.get("""model_type"""							) == "bridgetower":
               __lowerCamelCase     :      int       						=						config_dict["""text_config"""]

         if "model_type" in config_dict and hasattr(cls       ,  """model_type"""							) and config_dict["model_type"] != cls.model_type:
               logger.warning(
                   F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
                   F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

         return cls.from_dict(_lowerCamelCase       ,  **_lowerCamelCase							)



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							List[Any]    = "bridgetower"

   def __init__(  self  : List[str]       ,  _lowerCamelCase  : Optional[int]=True       ,  _lowerCamelCase  : str="gelu"       ,  _lowerCamelCase  : List[Any]=7_6_8       ,  _lowerCamelCase  : Any=1       ,  _lowerCamelCase  : Optional[int]=1E-05       ,  _lowerCamelCase  : Optional[int]=False       ,  _lowerCamelCase  : List[str]="add"       ,  _lowerCamelCase  : Any=1_2       ,  _lowerCamelCase  : Union[str, Any]=6       ,  _lowerCamelCase  : int=False       ,  _lowerCamelCase  : List[Any]=False       ,  _lowerCamelCase  : List[str]=None       ,  _lowerCamelCase  : Optional[Any]=None       ,  **_lowerCamelCase  : List[str]       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      Any       						=						kwargs.pop("""text_config_dict"""       ,  _lowerCamelCase							)
         __lowerCamelCase     :      int       						=						kwargs.pop("""vision_config_dict"""       ,  _lowerCamelCase							)

         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      Any       						=						share_cross_modal_transformer_layers
         __lowerCamelCase     :      Optional[int]       						=						hidden_act
         __lowerCamelCase     :      List[str]       						=						hidden_size
         __lowerCamelCase     :      Dict       						=						initializer_factor
         __lowerCamelCase     :      List[str]       						=						layer_norm_eps
         __lowerCamelCase     :      List[Any]       						=						share_link_tower_layers
         __lowerCamelCase     :      Dict       						=						link_tower_type
         __lowerCamelCase     :      str       						=						num_attention_heads
         __lowerCamelCase     :      Any       						=						num_hidden_layers
         __lowerCamelCase     :      List[str]       						=						tie_word_embeddings
         __lowerCamelCase     :      Any       						=						init_layernorm_from_vision_encoder

         if text_config is None:
               __lowerCamelCase     :      str       						=						{}
               logger.info("""`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values."""							)

         if vision_config is None:
               __lowerCamelCase     :      Any       						=						{}
               logger.info("""`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values."""							)

         __lowerCamelCase     :      Union[str, Any]       						=						BridgeTowerTextConfig(**_lowerCamelCase							)
         __lowerCamelCase     :      Optional[Any]       						=						BridgeTowerVisionConfig(**_lowerCamelCase							)

   @classmethod
   def   _snake_case    (  cls  : Union[str, Any]       ,  _lowerCamelCase  : BridgeTowerTextConfig       ,  _lowerCamelCase  : BridgeTowerVisionConfig       ,  **_lowerCamelCase  : Optional[Any]							):






         '''simple docstring'''



         return cls(text_config=text_config.to_dict()       ,  vision_config=vision_config.to_dict()       ,  **_lowerCamelCase							)


   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      str       						=						copy.deepcopy(self.__dict__							)
         __lowerCamelCase     :      Union[str, Any]       						=						self.text_config.to_dict()
         __lowerCamelCase     :      List[Any]       						=						self.vision_config.to_dict()
         __lowerCamelCase     :      List[Any]       						=						self.__class__.model_type
         return output







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__)



