



'''simple docstring'''

from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
					import torch

if is_torch_tpu_available(check_device=False):
					import torch_xla.core.xla_model as xm


snake_case_			=     logging.get_logger(__name__)


@dataclass
class 	a__     (				a__	):
	__magic_name__		:    Any	    =     [
	    """no_inference""",
	    """no_cuda""",
	    """no_tpu""",
	    """no_speed""",
	    """no_memory""",
	    """no_env_print""",
	    """no_multi_process""",
	]


	def __init__(self : Optional[int],					**__UpperCAmelCase : int      )     ->			List[Any]:

					"""simple docstring"""

					for deprecated_arg in self.deprecated_args:
									if deprecated_arg in kwargs:
													SCREAMING_SNAKE_CASE  :						Optional[int]      					= deprecated_arg[3:]
													setattr(self,					lowercase__,					not kwargs.pop(lowercase__      )      )
													logger.warning(
													    F'''{deprecated_arg} is depreciated. Please use --no_{positive_arg} or'''
													    F''' {positive_arg}={kwargs[positive_arg]}'''      )

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= kwargs.pop('''torchscript''',					self.torchscript      )
					SCREAMING_SNAKE_CASE  :						Dict      					= kwargs.pop('''torch_xla_tpu_print_metrics''',					self.torch_xla_tpu_print_metrics      )
					SCREAMING_SNAKE_CASE  :						Tuple      					= kwargs.pop('''fp16_opt_level''',					self.fpaa_opt_level      )
					super().__init__(**lowercase__      )

	__magic_name__		:    bool	    =     field(default=a__,			metadata={"help": "Trace the models using torchscript"}	)
	__magic_name__		:    bool	    =     field(default=a__,			metadata={"help": "Print Xla/PyTorch tpu metrics"}	)
	__magic_name__		:    str	    =     field(
	    default="O1",			metadata={
	        "help": (
	            "For fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. "
	            "See details at https://nvidia.github.io/apex/amp.html"
	        )
	    },			)


	@cached_property
	def 				lowercase__  (self : Tuple      )     ->			Tuple["torch.device", int]:

					"""simple docstring"""

					requires_backends(self,					['''torch''']      )
					logger.info('''PyTorch: setting up devices'''      )
					if not self.cuda:
									SCREAMING_SNAKE_CASE  :						List[str]      					= torch.device('''cpu'''      )
									SCREAMING_SNAKE_CASE  :						int      					= 0
					elif is_torch_tpu_available():
									SCREAMING_SNAKE_CASE  :						Tuple      					= xm.xla_device()
									SCREAMING_SNAKE_CASE  :						int      					= 0
					else:
									SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= torch.device('''cuda''' if torch.cuda.is_available() else '''cpu'''      )
									SCREAMING_SNAKE_CASE  :						Optional[Any]      					= torch.cuda.device_count()
					return device, n_gpu


	@property
	def 				lowercase__  (self : Any      )     ->			List[Any]:

					"""simple docstring"""

					return is_torch_tpu_available() and self.tpu


	@property
	def 				lowercase__  (self : Dict      )     ->			int:

					"""simple docstring"""

					requires_backends(self,					['''torch''']      )
					# TODO(PVP): currently only single GPU is supported
					return torch.cuda.current_device()


	@property
	def 				lowercase__  (self : List[str]      )     ->			"torch.device":

					"""simple docstring"""

					requires_backends(self,					['''torch''']      )
					return self._setup_devices[0]


	@property
	def 				lowercase__  (self : Dict      )     ->			Dict:

					"""simple docstring"""

					requires_backends(self,					['''torch''']      )
					return self._setup_devices[1]






	@property
	def 				lowercase__  (self : List[Any]      )     ->			Dict:

					"""simple docstring"""

					return self.n_gpu > 0









'''simple docstring'''

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


snake_case_			=     logging.get_logger(__name__)

snake_case_			=     {
    """microsoft/markuplm-base""": """https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json""",
    """microsoft/markuplm-large""": """https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json""",
}


class 	a__     (				_lowercase	):
	__magic_name__		:    List[Any]	    =     "markuplm"


	def __init__(self : List[Any],					__UpperCAmelCase : int=30522,					__UpperCAmelCase : Tuple=768,					__UpperCAmelCase : str=12,					__UpperCAmelCase : List[Any]=12,					__UpperCAmelCase : Tuple=3072,					__UpperCAmelCase : Union[str, Any]="gelu",					__UpperCAmelCase : Union[str, Any]=0.1,					__UpperCAmelCase : str=0.1,					__UpperCAmelCase : Union[str, Any]=512,					__UpperCAmelCase : Dict=2,					__UpperCAmelCase : int=0.02,					__UpperCAmelCase : Optional[Any]=1e-12,					__UpperCAmelCase : Union[str, Any]=0,					__UpperCAmelCase : Optional[Any]=0,					__UpperCAmelCase : Union[str, Any]=2,					__UpperCAmelCase : int=256,					__UpperCAmelCase : Tuple=1024,					__UpperCAmelCase : Optional[Any]=216,					__UpperCAmelCase : str=1001,					__UpperCAmelCase : Optional[Any]=32,					__UpperCAmelCase : Dict=50,					__UpperCAmelCase : Union[str, Any]="absolute",					__UpperCAmelCase : Tuple=True,					__UpperCAmelCase : List[str]=None,					**__UpperCAmelCase : Union[str, Any],					)     ->			Union[str, Any]:

					"""simple docstring"""

					super().__init__(
					    pad_token_id=__UpperCAmelCase,					bos_token_id=__UpperCAmelCase,					eos_token_id=__UpperCAmelCase,					**__UpperCAmelCase,					)
					SCREAMING_SNAKE_CASE  :						List[Any]      					= vocab_size
					SCREAMING_SNAKE_CASE  :						Dict      					= hidden_size
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= num_hidden_layers
					SCREAMING_SNAKE_CASE  :						Dict      					= num_attention_heads
					SCREAMING_SNAKE_CASE  :						Any      					= hidden_act
					SCREAMING_SNAKE_CASE  :						Tuple      					= intermediate_size
					SCREAMING_SNAKE_CASE  :						Tuple      					= hidden_dropout_prob
					SCREAMING_SNAKE_CASE  :						List[str]      					= attention_probs_dropout_prob
					SCREAMING_SNAKE_CASE  :						List[str]      					= max_position_embeddings
					SCREAMING_SNAKE_CASE  :						Dict      					= type_vocab_size
					SCREAMING_SNAKE_CASE  :						Tuple      					= initializer_range
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= layer_norm_eps
					SCREAMING_SNAKE_CASE  :						int      					= position_embedding_type
					SCREAMING_SNAKE_CASE  :						List[Any]      					= use_cache
					SCREAMING_SNAKE_CASE  :						int      					= classifier_dropout
					# additional properties
					SCREAMING_SNAKE_CASE  :						List[Any]      					= max_depth
					SCREAMING_SNAKE_CASE  :						Any      					= max_xpath_tag_unit_embeddings
					SCREAMING_SNAKE_CASE  :						int      					= max_xpath_subs_unit_embeddings
					SCREAMING_SNAKE_CASE  :						Dict      					= tag_pad_id
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= subs_pad_id
					SCREAMING_SNAKE_CASE  :						int      					= xpath_unit_hidden_size




