




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 ):

      """simple docstring"""

      lowerCAmelCase__      :			str     =       "layoutlmv2"







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







      @classmethod
      def    snake_case						(  self       :			Dict					):
          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": 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    snake_case						(  self       :			Optional[Any]					):
          __UpperCamelCase			=    detectrona.config.get_cfg()
          for k, v in self.detectrona_config_args.items():
              __UpperCamelCase			=    k.split('''.'''					)
              __UpperCamelCase			=    detectrona_config
              for attribute in attributes[:-1]:
                  __UpperCamelCase			=    getattr(snake_case			,							snake_case					)
              setattr(snake_case			,							attributes[-1]			,							snake_case					)

          return detectrona_config








"""simple docstring"""
import os
import shutil
import unittest
from unittest.mock import patch

from transformers.testing_utils import CaptureStd, is_pt_tf_cross_test, require_torch




class  _snake_case	(    unittest.TestCase							):






							@patch("""sys.argv"""    ,			["""fakeprogrampath""", """env"""]     )
							def 				__lowercase	(       self    :      Tuple     ):






												"""simple docstring"""



												import transformers.commands.transformers_cli

												with CaptureStd() as cs:
																	transformers.commands.transformers_cli.main()
												self.assertIn("""Python version"""    ,			cs.out     )
												self.assertIn("""Platform"""    ,			cs.out     )
												self.assertIn("""Using distributed or parallel set-up in script?"""    ,			cs.out     )






							@is_pt_tf_cross_test
							@patch(
							    """sys.argv"""    ,			["""fakeprogrampath""", """pt-to-tf""", """--model-name""", """hf-internal-testing/tiny-random-gptj""", """--no-pr"""]     )
							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												import transformers.commands.transformers_cli

												shutil.rmtree("""/tmp/hf-internal-testing/tiny-random-gptj"""    ,			ignore_errors=snake_case__     )  # cleans potential past runs
												transformers.commands.transformers_cli.main()

												# The original repo has no TF weights -- if they exist, they were created by the CLI
												self.assertTrue(os.path.exists("""/tmp/hf-internal-testing/tiny-random-gptj/tf_model.h5"""     )     )






							@require_torch
							@patch("""sys.argv"""    ,			["""fakeprogrampath""", """download""", """hf-internal-testing/tiny-random-gptj""", """--cache-dir""", """/tmp"""]     )
							def 				__lowercase	(       self    :      Optional[Any]     ):






												"""simple docstring"""



												import transformers.commands.transformers_cli

												# # remove any previously downloaded model to start clean
												shutil.rmtree("""/tmp/models--hf-internal-testing--tiny-random-gptj"""    ,			ignore_errors=snake_case__     )

												# run the command
												transformers.commands.transformers_cli.main()

												# check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--tiny-random-gptj
												self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/blobs"""     )     )
												self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/refs"""     )     )
												self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/snapshots"""     )     )






							@require_torch
							@patch(
							    """sys.argv"""    ,			[
							        """fakeprogrampath""",
							        """download""",
							        """hf-internal-testing/test_dynamic_model_with_tokenizer""",
							        """--trust-remote-code""",
							        """--cache-dir""",
							        """/tmp""",
							    ]    ,			)
							def 				__lowercase	(       self    :      Union[str, Any]     ):






												"""simple docstring"""



												import transformers.commands.transformers_cli

												# # remove any previously downloaded model to start clean
												shutil.rmtree("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer"""    ,			ignore_errors=snake_case__     )

												# run the command
												transformers.commands.transformers_cli.main()

												# check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer
												self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/blobs"""     )     )
												self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/refs"""     )     )
												self.assertTrue(
												    os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/snapshots"""     )     )
