






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


snake_case_   :	List[str]							      =logging.get_logger(__name__)

snake_case_   :	List[str]							      ={
    '''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__      (	lowerCAmelCase__		):
		UpperCAmelCase_							:       Dict 					= 'layoutlmv2'






		def __init__(      self							, lowercase__=30522							, lowercase__=768							, lowercase__=12							, lowercase__=12							, lowercase__=3072							, lowercase__="gelu"							, lowercase__=0.1							, lowercase__=0.1							, lowercase__=512							, lowercase__=2							, lowercase__=0.02							, lowercase__=1e-12							, lowercase__=0							, lowercase__=1024							, lowercase__=128							, lowercase__=32							, lowercase__=True							, lowercase__=256							, lowercase__=64							, lowercase__=True							, lowercase__=[7, 7, 256]							, lowercase__=128							, lowercase__=128							, lowercase__=True							, lowercase__=True							, lowercase__=False							, lowercase__=None							, **lowercase__							, )				->				Tuple:
				super().__init__(
				    vocab_size=lowercase__							, hidden_size=lowercase__							, num_hidden_layers=lowercase__							, num_attention_heads=lowercase__							, intermediate_size=lowercase__							, hidden_act=lowercase__							, hidden_dropout_prob=lowercase__							, attention_probs_dropout_prob=lowercase__							, max_position_embeddings=lowercase__							, type_vocab_size=lowercase__							, initializer_range=lowercase__							, layer_norm_eps=lowercase__							, pad_token_id=lowercase__							, **lowercase__							, )
				__A    =							max_ad_position_embeddings
				__A    =							max_rel_pos
				__A    =							rel_pos_bins
				__A    =							fast_qkv
				__A    =							max_rel_ad_pos
				__A    =							rel_ad_pos_bins
				__A    =							convert_sync_batchnorm
				__A    =							image_feature_pool_shape
				__A    =							coordinate_size
				__A    =							shape_size
				__A    =							has_relative_attention_bias
				__A    =							has_spatial_attention_bias
				__A    =							has_visual_segment_embedding
				__A    =							(
				    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
				)






		@classmethod
		def 					_lowerCamelCase					(      self						)				->				str:
				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": [[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 					_lowerCamelCase					(      self						)				->				List[str]:
				__A    =							detectrona.config.get_cfg()
				for k, v in self.detectrona_config_args.items():
						__A    =							k.split("."						)
						__A    =							detectrona_config
						for attribute in attributes[:-1]:
								__A    =							getattr(lowercase__							, lowercase__						)
						setattr(lowercase__							, attributes[-1]							, lowercase__						)

				return detectrona_config







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


SCREAMING_SNAKE_CASE_    :       int       =							{
    '''agents''': ['''Agent''', '''AzureOpenAiAgent''', '''HfAgent''', '''LocalAgent''', '''OpenAiAgent'''],
    '''base''': ['''PipelineTool''', '''RemoteTool''', '''Tool''', '''launch_gradio_demo''', '''load_tool'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE_    :       int       =							['''DocumentQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       List[Any]       =							['''ImageCaptioningTool''']
 SCREAMING_SNAKE_CASE_    :       Union[str, Any]       =							['''ImageQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       str       =							['''ImageSegmentationTool''']
 SCREAMING_SNAKE_CASE_    :       Any       =							['''SpeechToTextTool''']
 SCREAMING_SNAKE_CASE_    :       Union[str, Any]       =							['''TextClassificationTool''']
 SCREAMING_SNAKE_CASE_    :       List[Any]       =							['''TextQuestionAnsweringTool''']
 SCREAMING_SNAKE_CASE_    :       Dict       =							['''TextSummarizationTool''']
 SCREAMING_SNAKE_CASE_    :       Optional[int]       =							['''TextToSpeechTool''']
 SCREAMING_SNAKE_CASE_    :       Dict       =							['''TranslationTool''']

if TYPE_CHECKING:
 from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
 from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .document_question_answering import DocumentQuestionAnsweringTool
  from .image_captioning import ImageCaptioningTool
  from .image_question_answering import ImageQuestionAnsweringTool
  from .image_segmentation import ImageSegmentationTool
  from .speech_to_text import SpeechToTextTool
  from .text_classification import TextClassificationTool
  from .text_question_answering import TextQuestionAnsweringTool
  from .text_summarization import TextSummarizationTool
  from .text_to_speech import TextToSpeechTool
  from .translation import TranslationTool
else:
 import sys

 SCREAMING_SNAKE_CASE_    :       Optional[Any]       =							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






