



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


__snake_case						:Any      		=     logging.get_logger(__name__)

__snake_case						:Tuple      		=     {
    '''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       (	__UpperCAmelCase    ):
       UpperCamelCase__  :    Optional[int]											=						'''markuplm'''



       def __init__(		self							:     str     ,		__SCREAMING_SNAKE_CASE							:     List[str]=30_522     ,		__SCREAMING_SNAKE_CASE							:     Optional[Any]=768     ,		__SCREAMING_SNAKE_CASE							:     List[Any]=12     ,		__SCREAMING_SNAKE_CASE							:     Dict=12     ,		__SCREAMING_SNAKE_CASE							:     List[Any]=3_072     ,		__SCREAMING_SNAKE_CASE							:     Optional[Any]="gelu"     ,		__SCREAMING_SNAKE_CASE							:     List[Any]=0.1     ,		__SCREAMING_SNAKE_CASE							:     int=0.1     ,		__SCREAMING_SNAKE_CASE							:     Union[str, Any]=512     ,		__SCREAMING_SNAKE_CASE							:     Tuple=2     ,		__SCREAMING_SNAKE_CASE							:     Optional[Any]=0.02     ,		__SCREAMING_SNAKE_CASE							:     Any=1E-12     ,		__SCREAMING_SNAKE_CASE							:     List[str]=0     ,		__SCREAMING_SNAKE_CASE							:     Tuple=0     ,		__SCREAMING_SNAKE_CASE							:     str=2     ,		__SCREAMING_SNAKE_CASE							:     Any=256     ,		__SCREAMING_SNAKE_CASE							:     List[str]=1_024     ,		__SCREAMING_SNAKE_CASE							:     int=216     ,		__SCREAMING_SNAKE_CASE							:     Any=1_001     ,		__SCREAMING_SNAKE_CASE							:     str=32     ,		__SCREAMING_SNAKE_CASE							:     Union[str, Any]=50     ,		__SCREAMING_SNAKE_CASE							:     Optional[int]="absolute"     ,		__SCREAMING_SNAKE_CASE							:     List[Any]=True     ,		__SCREAMING_SNAKE_CASE							:     List[Any]=None     ,		**__SCREAMING_SNAKE_CASE							:     Optional[Any]     ,		):


           '''simple docstring'''

           super().__init__(
               pad_token_id=__SCREAMING_SNAKE_CASE     ,		bos_token_id=__SCREAMING_SNAKE_CASE     ,		eos_token_id=__SCREAMING_SNAKE_CASE     ,		**__SCREAMING_SNAKE_CASE     ,		)
           __a						       =				vocab_size
           __a						       =				hidden_size
           __a						       =				num_hidden_layers
           __a						       =				num_attention_heads
           __a						       =				hidden_act
           __a						       =				intermediate_size
           __a						       =				hidden_dropout_prob
           __a						       =				attention_probs_dropout_prob
           __a						       =				max_position_embeddings
           __a						       =				type_vocab_size
           __a						       =				initializer_range
           __a						       =				layer_norm_eps
           __a						       =				position_embedding_type
           __a						       =				use_cache
           __a						       =				classifier_dropout
           # additional properties
           __a						       =				max_depth
           __a						       =				max_xpath_tag_unit_embeddings
           __a						       =				max_xpath_subs_unit_embeddings
           __a						       =				tag_pad_id
           __a						       =				subs_pad_id
           __a						       =				xpath_unit_hidden_size













from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch






@require_torch
@require_tf
class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      def       __lowerCAmelCase					(      self      :						str  )    ->int:




       """simple docstring"""


       a		  =      SMALL_MODEL_IDENTIFIER
       a		  =      '''pt'''
       a		  =      '''tf'''







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




       """simple docstring"""


       a		  =      AutoModel.from_pretrained(self.test_model  )
       model_pt.save_pretrained(__UpperCAmelCase  )







      def       __lowerCAmelCase					(      self      :						Any ,					__UpperCAmelCase      :						Union[str, Any]  )    ->List[str]:




       """simple docstring"""


       a		  =      TFAutoModel.from_pretrained(self.test_model ,					from_pt=__UpperCAmelCase  )
       model_tf.save_pretrained(__UpperCAmelCase  )







      def       __lowerCAmelCase					(      self      :						Any  )    ->int:




       """simple docstring"""


       a		  =      '''mock_framework'''

       # Framework provided - return whatever the user provides
       a		  =      FeaturesManager.determine_framework(self.test_model ,					__UpperCAmelCase  )
       self.assertEqual(__UpperCAmelCase ,					__UpperCAmelCase  )

       # Local checkpoint and framework provided - return provided framework
       # PyTorch checkpoint
       with TemporaryDirectory() as local_pt_ckpt:
        self._setup_pt_ckpt(__UpperCAmelCase  )
        a		  =      FeaturesManager.determine_framework(__UpperCAmelCase ,					__UpperCAmelCase  )
        self.assertEqual(__UpperCAmelCase ,					__UpperCAmelCase  )

       # TensorFlow checkpoint
       with TemporaryDirectory() as local_tf_ckpt:
        self._setup_tf_ckpt(__UpperCAmelCase  )
        a		  =      FeaturesManager.determine_framework(__UpperCAmelCase ,					__UpperCAmelCase  )
        self.assertEqual(__UpperCAmelCase ,					__UpperCAmelCase  )







      def       __lowerCAmelCase					(      self      :						str  )    ->int:




       """simple docstring"""


       with TemporaryDirectory() as local_pt_ckpt:
        self._setup_pt_ckpt(__UpperCAmelCase  )
        a		  =      FeaturesManager.determine_framework(__UpperCAmelCase  )
        self.assertEqual(__UpperCAmelCase ,					self.framework_pt  )

       # TensorFlow checkpoint
       with TemporaryDirectory() as local_tf_ckpt:
        self._setup_tf_ckpt(__UpperCAmelCase  )
        a		  =      FeaturesManager.determine_framework(__UpperCAmelCase  )
        self.assertEqual(__UpperCAmelCase ,					self.framework_tf  )

       # Invalid local checkpoint
       with TemporaryDirectory() as local_invalid_ckpt:
        with self.assertRaises(__UpperCAmelCase  ):
         a		  =      FeaturesManager.determine_framework(__UpperCAmelCase  )







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




       """simple docstring"""


       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       with patch('''transformers.onnx.features.is_tf_available''' ,					__UpperCAmelCase  ):
        a		  =      FeaturesManager.determine_framework(self.test_model  )
        self.assertEqual(__UpperCAmelCase ,					self.framework_pt  )

       # PyTorch not in environment -> use TensorFlow
       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       with patch('''transformers.onnx.features.is_torch_available''' ,					__UpperCAmelCase  ):
        a		  =      FeaturesManager.determine_framework(self.test_model  )
        self.assertEqual(__UpperCAmelCase ,					self.framework_tf  )

       # Both in environment -> use PyTorch
       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       with patch('''transformers.onnx.features.is_tf_available''' ,					__UpperCAmelCase  ), patch(
           '''transformers.onnx.features.is_torch_available''' ,					__UpperCAmelCase  ):
        a		  =      FeaturesManager.determine_framework(self.test_model  )
        self.assertEqual(__UpperCAmelCase ,					self.framework_pt  )

       # Both not in environment -> raise error
       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       a		  =      MagicMock(return_value=__UpperCAmelCase  )
       with patch('''transformers.onnx.features.is_tf_available''' ,					__UpperCAmelCase  ), patch(
           '''transformers.onnx.features.is_torch_available''' ,					__UpperCAmelCase  ):
        with self.assertRaises(__UpperCAmelCase  ):
         a		  =      FeaturesManager.determine_framework(self.test_model  )


