
from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PretrainedConfig, PreTrainedTokenizer
from ...onnx import OnnxConfig, PatchingSpec
from ...utils import TensorType, is_torch_available, logging


lowerCamelCase__        =						logging.get_logger(__name__)

lowerCamelCase__        =						{
    """microsoft/layoutlm-base-uncased""": (
        """https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/config.json"""
    ),
    """microsoft/layoutlm-large-uncased""": (
        """https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/config.json"""
    ),
}







class 	A__				(	lowerCAmelCase_      ):
				lowercase            =    "layoutlm"






				def __init__(		self   : int       ,	a   : Optional[Any]=30_522       ,	a   : Optional[Any]=768       ,	a   : Dict=12       ,	a   : Tuple=12       ,	a   : Union[str, Any]=3_072       ,	a   : Dict="gelu"       ,	a   : Optional[int]=0.1       ,	a   : Tuple=0.1       ,	a   : int=512       ,	a   : int=2       ,	a   : Any=0.0_2       ,	a   : Union[str, Any]=1E-12       ,	a   : List[Any]=0       ,	a   : Tuple="absolute"       ,	a   : str=True       ,	a   : Optional[Any]=1_024       ,	**a   : Union[str, Any]       ,	):






							'''simple docstring'''







							super().__init__(pad_token_id=lowerCamelCase__       ,	**lowerCamelCase__  )
							lowerCAmelCase__ : Optional[Any]   =						vocab_size
							lowerCAmelCase__ : int   =						hidden_size
							lowerCAmelCase__ : str   =						num_hidden_layers
							lowerCAmelCase__ : List[Any]   =						num_attention_heads
							lowerCAmelCase__ : Dict   =						hidden_act
							lowerCAmelCase__ : Union[str, Any]   =						intermediate_size
							lowerCAmelCase__ : Optional[Any]   =						hidden_dropout_prob
							lowerCAmelCase__ : Union[str, Any]   =						attention_probs_dropout_prob
							lowerCAmelCase__ : str   =						max_position_embeddings
							lowerCAmelCase__ : Dict   =						type_vocab_size
							lowerCAmelCase__ : List[str]   =						initializer_range
							lowerCAmelCase__ : str   =						layer_norm_eps
							lowerCAmelCase__ : List[Any]   =						position_embedding_type
							lowerCAmelCase__ : List[str]   =						use_cache
							lowerCAmelCase__ : Optional[Any]   =						max_ad_position_embeddings







class 	A__				(	lowerCAmelCase_      ):






				def __init__(		self   : int       ,	a   : PretrainedConfig       ,	a   : str = "default"       ,	a   : List[PatchingSpec] = None       ,	):






							'''simple docstring'''







							super().__init__(lowerCamelCase__       ,	task=lowerCamelCase__       ,	patching_specs=lowerCamelCase__  )
							lowerCAmelCase__ : Optional[Any]   =						config.max_ad_position_embeddings - 1






				@property
				def 				_lowerCamelCase						(		self   : Dict  ):






							'''simple docstring'''







							return OrderedDict(
							    [
							        ('input_ids', {0: 'batch', 1: 'sequence'}),
							        ('bbox', {0: 'batch', 1: 'sequence'}),
							        ('attention_mask', {0: 'batch', 1: 'sequence'}),
							        ('token_type_ids', {0: 'batch', 1: 'sequence'}),
							    ]  )






				def 				_lowerCamelCase						(		self   : List[str]       ,	a   : PreTrainedTokenizer       ,	a   : int = -1       ,	a   : int = -1       ,	a   : bool = False       ,	a   : Optional[TensorType] = None       ,	):






							'''simple docstring'''







							lowerCAmelCase__ : List[str]   =						super().generate_dummy_inputs(
							    lowerCamelCase__       ,	batch_size=lowerCamelCase__       ,	seq_length=lowerCamelCase__       ,	is_pair=lowerCamelCase__       ,	framework=lowerCamelCase__  )

							# Generate a dummy bbox
							lowerCAmelCase__ : Dict   =						[48, 84, 73, 128]

							if not framework == TensorType.PYTORCH:
										raise NotImplementedError('Exporting LayoutLM to ONNX is currently only supported for PyTorch.'  )

							if not is_torch_available():
										raise ValueError('Cannot generate dummy inputs without PyTorch installed.'  )
							import torch

							lowerCAmelCase__ ,							lowerCAmelCase__ : str   =						input_dict['input_ids'].shape
							lowerCAmelCase__ : Optional[Any]   =						torch.tensor([*[box] * seq_length]  ).tile(lowerCamelCase__       ,	1       ,	1  )
							return input_dict






import copy

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


SCREAMING_SNAKE_CASE_		  =			logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_		  =			{
    """facebook/sam-vit-huge""": """https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json""",
    """facebook/sam-vit-large""": """https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json""",
    """facebook/sam-vit-base""": """https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json""",
}

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       List[str]		,lowerCamelCase__		:       int=256		,lowerCamelCase__		:       List[Any]=1024		,lowerCamelCase__		:       Any=16		,lowerCamelCase__		:       Union[str, Any]=16		,lowerCamelCase__		:       int=4		,lowerCamelCase__		:       Tuple="gelu"		,lowerCamelCase__		:       Dict=1e-6		,**lowerCamelCase__		:       int		,)	->						List[str]:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		hidden_size
           SCREAMING_SNAKE_CASE						=		image_size
           SCREAMING_SNAKE_CASE						=		patch_size
           SCREAMING_SNAKE_CASE						=		image_size // patch_size
           SCREAMING_SNAKE_CASE						=		mask_input_channels
           SCREAMING_SNAKE_CASE						=		num_point_embeddings
           SCREAMING_SNAKE_CASE						=		hidden_act
           SCREAMING_SNAKE_CASE						=		layer_norm_eps

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       str		,lowerCamelCase__		:       str=256		,lowerCamelCase__		:       Optional[Any]="relu"		,lowerCamelCase__		:       str=2048		,lowerCamelCase__		:       Union[str, Any]=2		,lowerCamelCase__		:       int=8		,lowerCamelCase__		:       Union[str, Any]=2		,lowerCamelCase__		:       List[Any]=3		,lowerCamelCase__		:       int=3		,lowerCamelCase__		:       Optional[Any]=256		,lowerCamelCase__		:       Tuple=1e-6		,**lowerCamelCase__		:       List[str]		,)	->						Dict:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		hidden_size
           SCREAMING_SNAKE_CASE						=		hidden_act
           SCREAMING_SNAKE_CASE						=		mlp_dim
           SCREAMING_SNAKE_CASE						=		num_hidden_layers
           SCREAMING_SNAKE_CASE						=		num_attention_heads
           SCREAMING_SNAKE_CASE						=		attention_downsample_rate
           SCREAMING_SNAKE_CASE						=		num_multimask_outputs
           SCREAMING_SNAKE_CASE						=		iou_head_depth
           SCREAMING_SNAKE_CASE						=		iou_head_hidden_dim
           SCREAMING_SNAKE_CASE						=		layer_norm_eps

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       Union[str, Any]		,lowerCamelCase__		:       Optional[Any]=768		,lowerCamelCase__		:       Union[str, Any]=256		,lowerCamelCase__		:       Optional[int]=12		,lowerCamelCase__		:       str=12		,lowerCamelCase__		:       Tuple=3		,lowerCamelCase__		:       Optional[Any]=1024		,lowerCamelCase__		:       Optional[int]=16		,lowerCamelCase__		:       Optional[Any]="gelu"		,lowerCamelCase__		:       int=1e-0_6		,lowerCamelCase__		:       Optional[Any]=0.0		,lowerCamelCase__		:       Tuple=1e-1_0		,lowerCamelCase__		:       Any=True		,lowerCamelCase__		:       List[Any]=4.0		,lowerCamelCase__		:       Optional[int]=True		,lowerCamelCase__		:       Union[str, Any]=True		,lowerCamelCase__		:       List[str]=14		,lowerCamelCase__		:       List[str]=[2, 5, 8, 11]		,lowerCamelCase__		:       Tuple=128		,lowerCamelCase__		:       Dict=None		,**lowerCamelCase__		:       Optional[Any]		,)	->						str:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)

           SCREAMING_SNAKE_CASE						=		hidden_size
           SCREAMING_SNAKE_CASE						=		output_channels
           SCREAMING_SNAKE_CASE						=		num_hidden_layers
           SCREAMING_SNAKE_CASE						=		num_attention_heads
           SCREAMING_SNAKE_CASE						=		num_channels
           SCREAMING_SNAKE_CASE						=		image_size
           SCREAMING_SNAKE_CASE						=		patch_size
           SCREAMING_SNAKE_CASE						=		hidden_act
           SCREAMING_SNAKE_CASE						=		layer_norm_eps
           SCREAMING_SNAKE_CASE						=		attention_dropout
           SCREAMING_SNAKE_CASE						=		initializer_range
           SCREAMING_SNAKE_CASE						=		qkv_bias
           SCREAMING_SNAKE_CASE						=		mlp_ratio
           SCREAMING_SNAKE_CASE						=		use_abs_pos
           SCREAMING_SNAKE_CASE						=		use_rel_pos
           SCREAMING_SNAKE_CASE						=		window_size
           SCREAMING_SNAKE_CASE						=		global_attn_indexes
           SCREAMING_SNAKE_CASE						=		num_pos_feats
           SCREAMING_SNAKE_CASE						=		int(hidden_size * mlp_ratio			) if mlp_dim is None else mlp_dim

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     __snake_case       :      Any						      =     "sam"
     __snake_case       :      Optional[Any]						      =     True






     def __init__(				self		:       Union[str, Any]		,lowerCamelCase__		:       List[Any]=None		,lowerCamelCase__		:       int=None		,lowerCamelCase__		:       int=None		,lowerCamelCase__		:       int=0.02		,**lowerCamelCase__		:       int		,)	->						str:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		vision_config if vision_config is not None else {}
           SCREAMING_SNAKE_CASE						=		prompt_encoder_config if prompt_encoder_config is not None else {}
           SCREAMING_SNAKE_CASE						=		mask_decoder_config if mask_decoder_config is not None else {}

           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		vision_config.to_dict()
           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		prompt_encoder_config.to_dict()
           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		mask_decoder_config.to_dict()

           SCREAMING_SNAKE_CASE						=		SamVisionConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		SamPromptEncoderConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		SamMaskDecoderConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		initializer_range






     def 							SCREAMING_SNAKE_CASE__    (				self		:       Union[str, Any]			)	->						Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		copy.deepcopy(self.__dict__			)
           SCREAMING_SNAKE_CASE						=		self.vision_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.prompt_encoder_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.mask_decoder_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.__class__.model_type
           return output


