
"""simple docstring"""


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


A_						       =				logging.get_logger(__name__)

A_						       =				{
    """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    __lowerCamelCase     (   __SCREAMING_SNAKE_CASE ):
				a__:			int									=						'layoutlmv2'




				def __init__(							self       ,	UpperCAmelCase=3_0522       ,	UpperCAmelCase=768       ,	UpperCAmelCase=12       ,	UpperCAmelCase=12       ,	UpperCAmelCase=3072       ,	UpperCAmelCase="gelu"       ,	UpperCAmelCase=0.1       ,	UpperCAmelCase=0.1       ,	UpperCAmelCase=512       ,	UpperCAmelCase=2       ,	UpperCAmelCase=0.0_2       ,	UpperCAmelCase=1e-1_2       ,	UpperCAmelCase=0       ,	UpperCAmelCase=1024       ,	UpperCAmelCase=128       ,	UpperCAmelCase=32       ,	UpperCAmelCase=True       ,	UpperCAmelCase=256       ,	UpperCAmelCase=64       ,	UpperCAmelCase=True       ,	UpperCAmelCase=[7, 7, 256]       ,	UpperCAmelCase=128       ,	UpperCAmelCase=128       ,	UpperCAmelCase=True       ,	UpperCAmelCase=True       ,	UpperCAmelCase=False       ,	UpperCAmelCase=None       ,	**UpperCAmelCase       ,	):
							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_ 		=     max_ad_position_embeddings
							lowerCamelCase_ 		=     max_rel_pos
							lowerCamelCase_ 		=     rel_pos_bins
							lowerCamelCase_ 		=     fast_qkv
							lowerCamelCase_ 		=     max_rel_ad_pos
							lowerCamelCase_ 		=     rel_ad_pos_bins
							lowerCamelCase_ 		=     convert_sync_batchnorm
							lowerCamelCase_ 		=     image_feature_pool_shape
							lowerCamelCase_ 		=     coordinate_size
							lowerCamelCase_ 		=     shape_size
							lowerCamelCase_ 		=     has_relative_attention_bias
							lowerCamelCase_ 		=     has_spatial_attention_bias
							lowerCamelCase_ 		=     has_visual_segment_embedding
							lowerCamelCase_ 		=     (
							    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
							)




				@classmethod
				def 					UpperCAmelCase__	(							self      ):
							return {
							    "MODEL.MASK_ON": True,
							    "MODEL.PIXEL_STD": [5_7.3_7_5, 5_7.1_2_0, 5_8.3_9_5],
							    "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": 2000,
							    "MODEL.RPN.PRE_NMS_TOPK_TEST": 1000,
							    "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1000,
							    "MODEL.POST_NMS_TOPK_TEST": 1000,
							    "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      ):
							lowerCamelCase_ 		=     detectrona.config.get_cfg()
							for k, v in self.detectrona_config_args.items():
										lowerCamelCase_ 		=     k.split('''.'''      )
										lowerCamelCase_ 		=     detectrona_config
										for attribute in attributes[:-1]:
													lowerCamelCase_ 		=     getattr(UpperCamelCase__       ,	UpperCamelCase__      )
										setattr(UpperCamelCase__       ,	attributes[-1]       ,	UpperCamelCase__      )

							return detectrona_config





"""simple docstring"""


import copy

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


A_						       =				logging.get_logger(__name__)




class    __lowerCamelCase     (   lowerCAmelCase ):
				a__:			List[str]									=						'hybrid-clip'
				a__:			List[Any]									=						True




				def __init__(							self       ,	UpperCAmelCase=512       ,	**UpperCAmelCase      ):
							super().__init__(**UpperCAmelCase      )

							if "text_config" not in kwargs:
										raise ValueError('''`text_config` can not be `None`.'''      )

							if "vision_config" not in kwargs:
										raise ValueError('''`vision_config` can not be `None`.'''      )

							lowerCamelCase_ 		=     kwargs.pop('''text_config'''      )
							lowerCamelCase_ 		=     kwargs.pop('''vision_config'''      )

							lowerCamelCase_ 		=     text_config.pop('''model_type'''      )
							lowerCamelCase_ 		=     vision_config.pop('''model_type'''      )

							from transformers import AutoConfig

							lowerCamelCase_ 		=     AutoConfig.for_model(UpperCAmelCase       ,	**UpperCAmelCase      )

							if vision_model_type == "clip":
										lowerCamelCase_ 		=     AutoConfig.for_model(UpperCAmelCase       ,	**UpperCAmelCase      ).vision_config
							elif vision_model_type == "clip_vision_model":
										from transformers import CLIPVisionConfig

										lowerCamelCase_ 		=     CLIPVisionConfig(**UpperCAmelCase      )
							else:
										lowerCamelCase_ 		=     AutoConfig.for_model(UpperCAmelCase       ,	**UpperCAmelCase      )

							lowerCamelCase_ 		=     projection_dim
							lowerCamelCase_ 		=     1.0




				@classmethod
				def 					UpperCAmelCase__	(							cls       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	**UpperCAmelCase      ):
							return cls(text_config=text_config.to_dict()       ,	vision_config=vision_config.to_dict()       ,	**UpperCAmelCase      )





				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     copy.deepcopy(self.__dict__      )
							lowerCamelCase_ 		=     self.text_config.to_dict()
							lowerCamelCase_ 		=     self.vision_config.to_dict()
							lowerCamelCase_ 		=     self.__class__.model_type
							return output



