


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


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

UpperCamelCase :				List[Any]						    =       {
    '''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							(      _UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:					Union[str, Any] 				= "layoutlmv2"
					def __init__(	self					:	Optional[int]  ,			_lowerCAmelCase					:	Union[str, Any]=3_0_5_2_2  ,			_lowerCAmelCase					:	Union[str, Any]=7_6_8  ,			_lowerCAmelCase					:	Any=1_2  ,			_lowerCAmelCase					:	int=1_2  ,			_lowerCAmelCase					:	Dict=3_0_7_2  ,			_lowerCAmelCase					:	List[str]="gelu"  ,			_lowerCAmelCase					:	Optional[Any]=0.1  ,			_lowerCAmelCase					:	int=0.1  ,			_lowerCAmelCase					:	Optional[int]=5_1_2  ,			_lowerCAmelCase					:	Optional[Any]=2  ,			_lowerCAmelCase					:	Tuple=0.02  ,			_lowerCAmelCase					:	Optional[int]=1E-1_2  ,			_lowerCAmelCase					:	Union[str, Any]=0  ,			_lowerCAmelCase					:	Union[str, Any]=1_0_2_4  ,			_lowerCAmelCase					:	List[Any]=1_2_8  ,			_lowerCAmelCase					:	List[Any]=3_2  ,			_lowerCAmelCase					:	Optional[Any]=True  ,			_lowerCAmelCase					:	Dict=2_5_6  ,			_lowerCAmelCase					:	Union[str, Any]=6_4  ,			_lowerCAmelCase					:	Optional[int]=True  ,			_lowerCAmelCase					:	Optional[Any]=[7, 7, 2_5_6]  ,			_lowerCAmelCase					:	str=1_2_8  ,			_lowerCAmelCase					:	Union[str, Any]=1_2_8  ,			_lowerCAmelCase					:	Optional[Any]=True  ,			_lowerCAmelCase					:	Dict=True  ,			_lowerCAmelCase					:	str=False  ,			_lowerCAmelCase					:	Union[str, Any]=None  ,			**_lowerCAmelCase					:	Union[str, Any]  ,			)       ->				List[str]:



											'''simple docstring'''





											super().__init__(
											    vocab_size=_lowerCAmelCase  ,			hidden_size=_lowerCAmelCase  ,			num_hidden_layers=_lowerCAmelCase  ,			num_attention_heads=_lowerCAmelCase  ,			intermediate_size=_lowerCAmelCase  ,			hidden_act=_lowerCAmelCase  ,			hidden_dropout_prob=_lowerCAmelCase  ,			attention_probs_dropout_prob=_lowerCAmelCase  ,			max_position_embeddings=_lowerCAmelCase  ,			type_vocab_size=_lowerCAmelCase  ,			initializer_range=_lowerCAmelCase  ,			layer_norm_eps=_lowerCAmelCase  ,			pad_token_id=_lowerCAmelCase  ,			**_lowerCAmelCase  ,			)
											__magic_name__ 		=			max_ad_position_embeddings
											__magic_name__ 		=			max_rel_pos
											__magic_name__ 		=			rel_pos_bins
											__magic_name__ 		=			fast_qkv
											__magic_name__ 		=			max_rel_ad_pos
											__magic_name__ 		=			rel_ad_pos_bins
											__magic_name__ 		=			convert_sync_batchnorm
											__magic_name__ 		=			image_feature_pool_shape
											__magic_name__ 		=			coordinate_size
											__magic_name__ 		=			shape_size
											__magic_name__ 		=			has_relative_attention_bias
											__magic_name__ 		=			has_spatial_attention_bias
											__magic_name__ 		=			has_visual_segment_embedding
											__magic_name__ 		=			(
											    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
											)
					@classmethod
					def   a (	self					:	Union[str, Any]     )       ->				int:



											'''simple docstring'''





											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   a (	self					:	Any     )       ->				Dict:



											'''simple docstring'''





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

											return detectrona_config





import os
import tempfile
import unittest
from typing import List

from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
from transformers.testing_utils import require_tokenizers
from transformers.tokenization_utils import PreTrainedTokenizer
from transformers.tokenization_utils_base import PreTrainedTokenizerBase

@require_tokenizers
class     __snake_case							(      unittest.TestCase):
					SCREAMING_SNAKE_CASE_		:					Tuple 				= EsmTokenizer
					def   a (	self					:	List[Any]     )       ->				Dict:



											'''simple docstring'''





											super().setUp()
											__magic_name__ 		=			tempfile.mkdtemp()
											# fmt: off
											__magic_name__ 		=			["<cls>", "<pad>", "<eos>", "<unk>", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "<null_1>", "<mask>"]  # noqa: E501
											# fmt: on
											__magic_name__ 		=			os.path.join(self.tmpdirname  ,			VOCAB_FILES_NAMES['vocab_file']     )
											with open(self.vocab_file  ,			'w'  ,			encoding='utf-8'     ) as vocab_writer:
																	vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]     )     )
					def   a (	self					:	Optional[int]  ,			**_lowerCAmelCase					:	int     )       ->				List[PreTrainedTokenizerBase]:



											'''simple docstring'''





											return [self.get_tokenizer(**_lowerCAmelCase     )]
					def   a (	self					:	List[str]  ,			**_lowerCAmelCase					:	int     )       ->				PreTrainedTokenizer:



											'''simple docstring'''





											return self.tokenizer_class.from_pretrained(self.tmpdirname  ,			**_lowerCAmelCase     )
					def   a (	self					:	int     )       ->				int:



											'''simple docstring'''





											__magic_name__ 		=			self.tokenizer_class(self.vocab_file     )

											__magic_name__ 		=			tokenizer.tokenize('LAGVS'     )
											self.assertListEqual(_lowerCAmelCase  ,			['L', 'A', 'G', 'V', 'S']     )
											self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCAmelCase     )  ,			[4, 5, 6, 7, 8]     )
					def   a (	self					:	str     )       ->				str:



											'''simple docstring'''





											__magic_name__ 		=			self.tokenizer_class(self.vocab_file     )

											__magic_name__ 		=			'LAGVS'
											self.assertListEqual(tokenizer.encode(_lowerCAmelCase     )  ,			[0, 4, 5, 6, 7, 8, 2]     )
					def   a (	self					:	int     )       ->				List[Any]:



											'''simple docstring'''





											__magic_name__ 		=			self.tokenizer_class(self.vocab_file     )

											__magic_name__ 		=			['LAGVS', 'WCB']
											__magic_name__ 		=			tokenizer(_lowerCAmelCase  ,			padding=_lowerCAmelCase     )['input_ids']

											self.assertListEqual(_lowerCAmelCase  ,			[[0, 4, 5, 6, 7, 8, 2], [0, 2_2, 2_3, 2_5, 2]]     )
					def   a (	self					:	Dict     )       ->				List[Any]:



											'''simple docstring'''





											__magic_name__ 		=			self.tokenizer_class(self.vocab_file     )

											__magic_name__ 		=			['LAGVS', 'WCB']
											__magic_name__ 		=			tokenizer(_lowerCAmelCase  ,			padding=_lowerCAmelCase     )['input_ids']

											self.assertListEqual(_lowerCAmelCase  ,			[[0, 4, 5, 6, 7, 8, 2], [0, 2_2, 2_3, 2_5, 2, 1, 1]]     )







					def   a (	self					:	Optional[int]     )       ->				str:



											'''simple docstring'''





											__magic_name__ 		=			self.get_tokenizers(fast=_lowerCAmelCase     )
											for tokenizer in tokenizers:
																	with self.subTest(F'''{tokenizer.__class__.__name__}'''     ):
																							__magic_name__ 		=			'<unk>'
																							__magic_name__ 		=			'<mask>'

																							__magic_name__ 		=			tokenizer.tokenize(_lowerCAmelCase     )
																							__magic_name__ 		=			tokenizer.tokenize(_lowerCAmelCase     )

																							self.assertEqual(len(_lowerCAmelCase     )  ,			1     )
																							self.assertEqual(len(_lowerCAmelCase     )  ,			1     )
																							self.assertEqual(token_a[0]  ,			_lowerCAmelCase     )
																							self.assertEqual(token_a[0]  ,			_lowerCAmelCase     )

