

from ...configuration_utils import PretrainedConfig
from ...utils import is_detectrona_available, logging


UpperCAmelCase__	:       int			      =      logging.get_logger(__name__)

UpperCAmelCase__	:       List[Any]			      =      {
    """layoutlmv2-base-uncased""": """https://huggingface.co/microsoft/layoutlmv2-base-uncased/resolve/main/config.json""",
    """layoutlmv2-large-uncased""": """https://huggingface.co/microsoft/layoutlmv2-large-uncased/resolve/main/config.json""",
    # See all LayoutLMv2 models at https://huggingface.co/models?filter=layoutlmv2
}

# soft dependency
if is_detectrona_available():
  import detectrona







class     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  UpperCAmelCase__ :	List[Any]         ="""layoutlmv2"""


  def __init__(     self      :	str			,			UpperCAmelCase__      :	Optional[Any]=3_0_5_2_2			,			UpperCAmelCase__      :	Union[str, Any]=7_6_8			,			UpperCAmelCase__      :	str=1_2			,			UpperCAmelCase__      :	str=1_2			,			UpperCAmelCase__      :	List[Any]=3_0_7_2			,			UpperCAmelCase__      :	Optional[int]="gelu"			,			UpperCAmelCase__      :	List[Any]=0.1			,			UpperCAmelCase__      :	List[str]=0.1			,			UpperCAmelCase__      :	int=5_1_2			,			UpperCAmelCase__      :	Any=2			,			UpperCAmelCase__      :	int=0.02			,			UpperCAmelCase__      :	Dict=1e-12			,			UpperCAmelCase__      :	Optional[int]=0			,			UpperCAmelCase__      :	int=1_0_2_4			,			UpperCAmelCase__      :	List[str]=1_2_8			,			UpperCAmelCase__      :	List[str]=3_2			,			UpperCAmelCase__      :	int=True			,			UpperCAmelCase__      :	List[str]=2_5_6			,			UpperCAmelCase__      :	List[Any]=6_4			,			UpperCAmelCase__      :	Any=True			,			UpperCAmelCase__      :	List[str]=[7, 7, 2_5_6]			,			UpperCAmelCase__      :	int=1_2_8			,			UpperCAmelCase__      :	Union[str, Any]=1_2_8			,			UpperCAmelCase__      :	Any=True			,			UpperCAmelCase__      :	Optional[int]=True			,			UpperCAmelCase__      :	Union[str, Any]=False			,			UpperCAmelCase__      :	Any=None			,			**UpperCAmelCase__      :	Any			,			)   ->List[str]:
        """simple docstring"""







        super().__init__(
            vocab_size=UpperCAmelCase__			,			hidden_size=UpperCAmelCase__			,			num_hidden_layers=UpperCAmelCase__			,			num_attention_heads=UpperCAmelCase__			,			intermediate_size=UpperCAmelCase__			,			hidden_act=UpperCAmelCase__			,			hidden_dropout_prob=UpperCAmelCase__			,			attention_probs_dropout_prob=UpperCAmelCase__			,			max_position_embeddings=UpperCAmelCase__			,			type_vocab_size=UpperCAmelCase__			,			initializer_range=UpperCAmelCase__			,			layer_norm_eps=UpperCAmelCase__			,			pad_token_id=UpperCAmelCase__			,			**UpperCAmelCase__			,			)
        SCREAMING_SNAKE_CASE	: str					       =				max_ad_position_embeddings
        SCREAMING_SNAKE_CASE	: Dict					       =				max_rel_pos
        SCREAMING_SNAKE_CASE	: int					       =				rel_pos_bins
        SCREAMING_SNAKE_CASE	: str					       =				fast_qkv
        SCREAMING_SNAKE_CASE	: Tuple					       =				max_rel_ad_pos
        SCREAMING_SNAKE_CASE	: int					       =				rel_ad_pos_bins
        SCREAMING_SNAKE_CASE	: Any					       =				convert_sync_batchnorm
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				image_feature_pool_shape
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				coordinate_size
        SCREAMING_SNAKE_CASE	: List[Any]					       =				shape_size
        SCREAMING_SNAKE_CASE	: Dict					       =				has_relative_attention_bias
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				has_spatial_attention_bias
        SCREAMING_SNAKE_CASE	: int					       =				has_visual_segment_embedding
        SCREAMING_SNAKE_CASE	: Tuple					       =				(
            detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
        )


  @classmethod
  def 	_lowercase (     self      :	int						)   ->List[str]:
        """simple docstring"""







        return {
            "MODEL.MASK_ON": True,
            "MODEL.PIXEL_STD": [57.3_75, 57.1_20, 58.3_95],
            "MODEL.BACKBONE.NAME": "build_resnet_fpn_backbone",
            "MODEL.FPN.IN_FEATURES": ["res2", "res3", "res4", "res5"],
            "MODEL.ANCHOR_GENERATOR.SIZES": [[3_2], [6_4], [1_2_8], [2_5_6], [5_1_2]],
            "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
            "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2_0_0_0,
            "MODEL.RPN.PRE_NMS_TOPK_TEST": 1_0_0_0,
            "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1_0_0_0,
            "MODEL.POST_NMS_TOPK_TEST": 1_0_0_0,
            "MODEL.ROI_HEADS.NAME": "StandardROIHeads",
            "MODEL.ROI_HEADS.NUM_CLASSES": 5,
            "MODEL.ROI_HEADS.IN_FEATURES": ["p2", "p3", "p4", "p5"],
            "MODEL.ROI_BOX_HEAD.NAME": "FastRCNNConvFCHead",
            "MODEL.ROI_BOX_HEAD.NUM_FC": 2,
            "MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION": 1_4,
            "MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
            "MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
            "MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
            "MODEL.RESNETS.DEPTH": 1_0_1,
            "MODEL.RESNETS.SIZES": [[3_2], [6_4], [1_2_8], [2_5_6], [5_1_2]],
            "MODEL.RESNETS.ASPECT_RATIOS": [[0.5, 1.0, 2.0]],
            "MODEL.RESNETS.OUT_FEATURES": ["res2", "res3", "res4", "res5"],
            "MODEL.RESNETS.NUM_GROUPS": 3_2,
            "MODEL.RESNETS.WIDTH_PER_GROUP": 8,
            "MODEL.RESNETS.STRIDE_IN_1X1": False,
        }




  def 	_lowercase (     self      :	Union[str, Any]						)   ->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				detectrona.config.get_cfg()
        for k, v in self.detectrona_config_args.items():
              SCREAMING_SNAKE_CASE	: List[Any]					       =				k.split("""."""						)
              SCREAMING_SNAKE_CASE	: Any					       =				detectrona_config
              for attribute in attributes[:-1]:
                    SCREAMING_SNAKE_CASE	: Tuple					       =				getattr(UpperCAmelCase__			,			UpperCAmelCase__						)
              setattr(UpperCAmelCase__			,			attributes[-1]			,			UpperCAmelCase__						)

        return detectrona_config







import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

UpperCAmelCase__	:       Dict			      =      [(1,)]






def    __lowercase (       )       ->  Tuple:
      SCREAMING_SNAKE_CASE	: Optional[Any]					       =				bool(os.getenv("""RUN_SLOW"""  ,      0     )     )
      if run_slow:
            assert True
      else:
            assert False, "should have been skipped"






def    __lowercase (       )       ->  Optional[Any]:
      SCREAMING_SNAKE_CASE	: Dict					       =				bool(os.getenv("""RUN_SLOW"""  ,      0     )     )
      if run_slow and torch_device == "cuda":
            assert True
      else:
            assert False, "should have been skipped"







@require_torch
class     a__    (				unittest.TestCase    ):







  """simple docstring"""




  @slow
  @require_torch_gpu
  def 	_lowercase (     self      :	Any						)   ->Optional[Any]:
        """simple docstring"""







        check_slow_torch_cuda()


  @require_torch_gpu
  @slow
  def 	_lowercase (     self      :	Optional[Any]						)   ->Any:
        """simple docstring"""







        check_slow_torch_cuda()




  @parameterized.expand(UpperCAmelCase__						)
  @slow
  def 	_lowercase (     self      :	Optional[int]			,			UpperCAmelCase__      :	Dict=None						)   ->Optional[Any]:
        """simple docstring"""







        check_slow()






@slow
@require_torch_gpu
def    __lowercase (       )       ->  Optional[int]:
      check_slow_torch_cuda()






@require_torch_gpu
@slow
def    __lowercase (       )       ->  int:
      check_slow_torch_cuda()






@slow
@pytest.mark.parametrize("""param"""  ,      [1]     )
def    __lowercase (       _A     )       ->  Optional[int]:
      check_slow()







@pytest.mark.parametrize("""param"""  ,      [1]     )
@slow
def    __lowercase (       _A     )       ->  str:
      check_slow()




