






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


UpperCamelCase												=      logging.get_logger(__name__)

UpperCamelCase												=      {
    '''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  __UpperCAmelCase						(_UpperCAmelCase       ):
			__snake_case							: int							=				"layoutlmv2"







			def __init__(      self:    Tuple ,      UpperCAmelCase_:    int=30_522 ,      UpperCAmelCase_:    List[Any]=768 ,      UpperCAmelCase_:    List[str]=12 ,      UpperCAmelCase_:    Optional[Any]=12 ,      UpperCAmelCase_:    Dict=3_072 ,      UpperCAmelCase_:    Union[str, Any]="gelu" ,      UpperCAmelCase_:    Union[str, Any]=0.1 ,      UpperCAmelCase_:    Union[str, Any]=0.1 ,      UpperCAmelCase_:    str=512 ,      UpperCAmelCase_:    List[str]=2 ,      UpperCAmelCase_:    str=0.02 ,      UpperCAmelCase_:    str=1E-12 ,      UpperCAmelCase_:    Any=0 ,      UpperCAmelCase_:    Any=1_024 ,      UpperCAmelCase_:    List[str]=128 ,      UpperCAmelCase_:    str=32 ,      UpperCAmelCase_:    Optional[int]=True ,      UpperCAmelCase_:    Tuple=256 ,      UpperCAmelCase_:    Dict=64 ,      UpperCAmelCase_:    Optional[Any]=True ,      UpperCAmelCase_:    Union[str, Any]=[7, 7, 256] ,      UpperCAmelCase_:    str=128 ,      UpperCAmelCase_:    Tuple=128 ,      UpperCAmelCase_:    Dict=True ,      UpperCAmelCase_:    List[Any]=True ,      UpperCAmelCase_:    Dict=False ,      UpperCAmelCase_:    Tuple=None ,      **UpperCAmelCase_:    Any ,      ):







									'''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       =    max_ad_position_embeddings
									_SCREAMING_SNAKE_CASE       =    max_rel_pos
									_SCREAMING_SNAKE_CASE       =    rel_pos_bins
									_SCREAMING_SNAKE_CASE       =    fast_qkv
									_SCREAMING_SNAKE_CASE       =    max_rel_ad_pos
									_SCREAMING_SNAKE_CASE       =    rel_ad_pos_bins
									_SCREAMING_SNAKE_CASE       =    convert_sync_batchnorm
									_SCREAMING_SNAKE_CASE       =    image_feature_pool_shape
									_SCREAMING_SNAKE_CASE       =    coordinate_size
									_SCREAMING_SNAKE_CASE       =    shape_size
									_SCREAMING_SNAKE_CASE       =    has_relative_attention_bias
									_SCREAMING_SNAKE_CASE       =    has_spatial_attention_bias
									_SCREAMING_SNAKE_CASE       =    has_visual_segment_embedding
									_SCREAMING_SNAKE_CASE       =    (
									    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
									)







			@classmethod
			def 				UpperCamelCase (      self:    List[Any]	):







									'''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": [[32], [64], [128], [256], [512]],
									    "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
									    "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2_000,
									    "MODEL.RPN.PRE_NMS_TOPK_TEST": 1_000,
									    "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1_000,
									    "MODEL.POST_NMS_TOPK_TEST": 1_000,
									    "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": 14,
									    "MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
									    "MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
									    "MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
									    "MODEL.RESNETS.DEPTH": 101,
									    "MODEL.RESNETS.SIZES": [[32], [64], [128], [256], [512]],
									    "MODEL.RESNETS.ASPECT_RATIOS": [[0.5, 1.0, 2.0]],
									    "MODEL.RESNETS.OUT_FEATURES": ["res2", "res3", "res4", "res5"],
									    "MODEL.RESNETS.NUM_GROUPS": 32,
									    "MODEL.RESNETS.WIDTH_PER_GROUP": 8,
									    "MODEL.RESNETS.STRIDE_IN_1X1": False,
									}







			def 				UpperCamelCase (      self:    str	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    detectrona.config.get_cfg()
									for k, v in self.detectrona_config_args.items():
															_SCREAMING_SNAKE_CASE       =    k.split("""."""	)
															_SCREAMING_SNAKE_CASE       =    detectrona_config
															for attribute in attributes[:-1]:
																					_SCREAMING_SNAKE_CASE       =    getattr(UpperCAmelCase_ ,      UpperCAmelCase_	)
															setattr(UpperCAmelCase_ ,      attributes[-1] ,      UpperCAmelCase_	)

									return detectrona_config









import math
from timeit import timeit

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    0
						_SCREAMING_SNAKE_CASE       =    abs(snake_case__						)
						while True:
												_SCREAMING_SNAKE_CASE       =    n // 10
												digits += 1
												if n == 0:
																		break
						return digits

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						return 1 if n == 0 else math.floor(math.log(abs(snake_case__						)			,10						) + 1						)

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						return len(str(abs(snake_case__						)						)						)

def 			__lowerCamelCase     (						)				->    None:






						"""simple docstring"""





						from collections.abc import Callable

						def benchmark_a_function(snake_case__			,snake_case__						) -> None:
												_SCREAMING_SNAKE_CASE       =    F'{func.__name__}({value})'
												_SCREAMING_SNAKE_CASE       =    timeit(F'__main__.{call}'			,setup="""import __main__"""						)
												print(F'{call}: {func(snake_case__						)} -- {timing} seconds'						)

						for value in (26_21_44, 11_25_89_99_06_84_26_24, 1_26_76_50_60_02_28_22_94_01_49_67_03_20_53_76):
												for func in (num_digits, num_digits_fast, num_digits_faster):
																		benchmark_a_function(snake_case__			,snake_case__						)
												print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()

