


"""simple docstring"""





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


snake_case__		:  str     					=					logging.get_logger(__name__)

snake_case__		:  Dict     					=					{
    '''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 		snake_case_(							a__      ):
     __UpperCamelCase	=       '''layoutlmv2'''






     def __init__(						self	:       str       ,					UpperCamelCase_	:       Any=3_0_5_2_2       ,					UpperCamelCase_	:       List[Any]=7_6_8       ,					UpperCamelCase_	:       Any=1_2       ,					UpperCamelCase_	:       Optional[int]=1_2       ,					UpperCamelCase_	:       Tuple=3_0_7_2       ,					UpperCamelCase_	:       List[str]="gelu"       ,					UpperCamelCase_	:       Optional[int]=0.1       ,					UpperCamelCase_	:       Optional[int]=0.1       ,					UpperCamelCase_	:       str=5_1_2       ,					UpperCamelCase_	:       Any=2       ,					UpperCamelCase_	:       int=0.02       ,					UpperCamelCase_	:       Optional[int]=1E-12       ,					UpperCamelCase_	:       str=0       ,					UpperCamelCase_	:       Optional[int]=1_0_2_4       ,					UpperCamelCase_	:       Any=1_2_8       ,					UpperCamelCase_	:       Optional[int]=3_2       ,					UpperCamelCase_	:       Union[str, Any]=True       ,					UpperCamelCase_	:       Any=2_5_6       ,					UpperCamelCase_	:       Tuple=6_4       ,					UpperCamelCase_	:       int=True       ,					UpperCamelCase_	:       Dict=[7, 7, 2_5_6]       ,					UpperCamelCase_	:       int=1_2_8       ,					UpperCamelCase_	:       str=1_2_8       ,					UpperCamelCase_	:       Any=True       ,					UpperCamelCase_	:       Dict=True       ,					UpperCamelCase_	:       Optional[Any]=False       ,					UpperCamelCase_	:       Optional[Any]=None       ,					**UpperCamelCase_	:       List[Any]       ,					):
           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_       ,					)
           lowerCAmelCase       :						Optional[int]							= max_ad_position_embeddings
           lowerCAmelCase       :						int							= max_rel_pos
           lowerCAmelCase       :						Optional[Any]							= rel_pos_bins
           lowerCAmelCase       :						Union[str, Any]							= fast_qkv
           lowerCAmelCase       :						str							= max_rel_ad_pos
           lowerCAmelCase       :						List[str]							= rel_ad_pos_bins
           lowerCAmelCase       :						str							= convert_sync_batchnorm
           lowerCAmelCase       :						Optional[Any]							= image_feature_pool_shape
           lowerCAmelCase       :						Any							= coordinate_size
           lowerCAmelCase       :						Optional[int]							= shape_size
           lowerCAmelCase       :						int							= has_relative_attention_bias
           lowerCAmelCase       :						Optional[Any]							= has_spatial_attention_bias
           lowerCAmelCase       :						Any							= has_visual_segment_embedding
           lowerCAmelCase       :						Tuple							= (
               detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
           )






     @classmethod
     def   lowerCamelCase__  (						self	:       Tuple					):
           return {
               "MODEL.MASK_ON": True,
               "MODEL.PIXEL_STD": [57.375, 57.120, 58.395],
               "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   lowerCamelCase__  (						self	:       List[Any]					):
           lowerCAmelCase       :						int							= detectrona.config.get_cfg()
           for k, v in self.detectrona_config_args.items():
                 lowerCAmelCase       :						int							= k.split('''.'''					)
                 lowerCAmelCase       :						Tuple							= detectrona_config
                 for attribute in attributes[:-1]:
                       lowerCAmelCase       :						str							= getattr(UpperCamelCase_       ,					UpperCamelCase_					)
                 setattr(UpperCamelCase_       ,					attributes[-1]       ,					UpperCamelCase_					)

           return detectrona_config






"""simple docstring"""





from typing import Callable, Optional, Union

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


snake_case__		:  Optional[Any]     					=					logging.get_logger(__name__)

snake_case__		:  str     					=					{
    '''microsoft/prophetnet-large-uncased''': (
        '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
    ),
}



class 		snake_case_(							a__      ):
     __UpperCamelCase	=       '''prophetnet'''
     __UpperCamelCase	=       ['''past_key_values''']
     __UpperCamelCase	=       {
         '''num_attention_heads''': '''num_encoder_attention_heads''',
     }






     def __init__(						self	:       Union[str, Any]       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[Union[str, Callable]] = "gelu"       ,					UpperCamelCase_	:       Optional[int] = 3_0_5_2_2       ,					UpperCamelCase_	:       Optional[int] = 1_0_2_4       ,					UpperCamelCase_	:       Optional[int] = 4_0_9_6       ,					UpperCamelCase_	:       Optional[int] = 1_2       ,					UpperCamelCase_	:       Optional[int] = 1_6       ,					UpperCamelCase_	:       Optional[int] = 4_0_9_6       ,					UpperCamelCase_	:       Optional[int] = 1_2       ,					UpperCamelCase_	:       Optional[int] = 1_6       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[float] = 0.1       ,					UpperCamelCase_	:       Optional[int] = 5_1_2       ,					UpperCamelCase_	:       Optional[float] = 0.02       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[int] = 0       ,					UpperCamelCase_	:       Optional[int] = 2       ,					UpperCamelCase_	:       Optional[int] = 3_2       ,					UpperCamelCase_	:       Optional[int] = 1_2_8       ,					UpperCamelCase_	:       Optional[bool] = False       ,					UpperCamelCase_	:       Optional[float] = 0.0       ,					UpperCamelCase_	:       Optional[bool] = True       ,					UpperCamelCase_	:       Optional[int] = 0       ,					UpperCamelCase_	:       Optional[int] = 1       ,					UpperCamelCase_	:       Optional[int] = 2       ,					**UpperCamelCase_	:       List[Any]       ,					):
           lowerCAmelCase       :						Union[str, Any]							= vocab_size
           lowerCAmelCase       :						Any							= hidden_size
           lowerCAmelCase       :						Tuple							= encoder_ffn_dim
           lowerCAmelCase       :						str							= num_encoder_layers
           lowerCAmelCase       :						int							= num_encoder_attention_heads
           lowerCAmelCase       :						Optional[Any]							= decoder_ffn_dim
           lowerCAmelCase       :						Union[str, Any]							= num_decoder_layers
           lowerCAmelCase       :						Union[str, Any]							= num_decoder_attention_heads
           lowerCAmelCase       :						List[Any]							= max_position_embeddings
           lowerCAmelCase       :						Dict							= init_std  # Normal(0, this parameter)
           lowerCAmelCase       :						Optional[int]							= activation_function

           # parameters for prophetnet
           lowerCAmelCase       :						Tuple							= ngram
           lowerCAmelCase       :						List[Any]							= num_buckets
           lowerCAmelCase       :						Optional[Any]							= relative_max_distance
           lowerCAmelCase       :						Dict							= disable_ngram_loss
           lowerCAmelCase       :						Optional[int]							= eps

           # 3 Types of Dropout
           lowerCAmelCase       :						Any							= attention_dropout
           lowerCAmelCase       :						List[Any]							= activation_dropout
           lowerCAmelCase       :						Tuple							= dropout

           lowerCAmelCase       :						Optional[int]							= use_cache

           super().__init__(
               pad_token_id=UpperCamelCase_       ,					bos_token_id=UpperCamelCase_       ,					eos_token_id=UpperCamelCase_       ,					is_encoder_decoder=UpperCamelCase_       ,					add_cross_attention=UpperCamelCase_       ,					decoder_start_token_id=UpperCamelCase_       ,					**UpperCamelCase_       ,					)






     @property
     def   lowerCamelCase__  (						self	:       str					):
           return self.num_encoder_layers + self.num_decoder_layers






     @num_hidden_layers.setter
     def   lowerCamelCase__  (						self	:       Optional[Any]       ,					UpperCamelCase_	:       int					):
           raise NotImplementedError(
               '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
               ''' `num_decoder_layers`.'''					)


