


import os
import re
import shutil
import sys
import tempfile
import unittest

import black


__UpperCamelCase       :       Optional[Any]						       =				os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If BertLMPredictionHead is changed in modeling_bert.py, this code needs to be manually updated.
__UpperCamelCase       :       int						       =				"""    def __init__(self, config):
        super().__init__()
        self.transform = BertPredictionHeadTransform(config)

        # The output weights are the same as the input embeddings, but there is
        # an output-only bias for each token.
        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)

        self.bias = nn.Parameter(torch.zeros(config.vocab_size))

        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
        self.decoder.bias = self.bias

    def forward(self, hidden_states):
        hidden_states = self.transform(hidden_states)
        hidden_states = self.decoder(hidden_states)
        return hidden_states
"""

class       __magic_name__	(     unittest.TestCase):


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





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   tempfile.mkdtemp()
      os.makedirs(os.path.join(self.transformer_dir							,	'''models/bert/'''			)			)
      UpperCamelCase__					:    List[Any]          =   self.transformer_dir
      shutil.copy(
          os.path.join(_lowerCAmelCase							,	'''src/transformers/models/bert/modeling_bert.py'''			)							,	os.path.join(self.transformer_dir							,	'''models/bert/modeling_bert.py'''			)							,	)


     def      UpperCAmelCase__	(      self							:     Any			)  ->      List[str]:





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   '''src/transformers'''
      shutil.rmtree(self.transformer_dir			)


     def      UpperCAmelCase__	(      self							:     List[Any]							,	lowerCamelCase__							:     str							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     Tuple							,	lowerCamelCase__							:     Optional[Any]=None			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    int          =   comment + F"\nclass {class_name}(nn.Module):\n" + class_code
      if overwrite_result is not None:
       UpperCamelCase__					:    Optional[Any]          =   comment + F"\nclass {class_name}(nn.Module):\n" + overwrite_result
      UpperCamelCase__					:    List[str]          =   black.Mode(target_versions={black.TargetVersion.PYaa}							,	line_length=119			)
      UpperCamelCase__					:    Union[str, Any]          =   black.format_str(_lowerCAmelCase							,	mode=_lowerCAmelCase			)
      UpperCamelCase__					:    Union[str, Any]          =   os.path.join(self.transformer_dir							,	'''new_code.py'''			)
      with open(_lowerCAmelCase							,	'''w'''							,	newline='''\n'''			) as f:
       f.write(_lowerCAmelCase			)
      if overwrite_result is None:
       self.assertTrue(len(check_copies.is_copy_consistent(_lowerCAmelCase			)			) == 0			)
      else:
       check_copies.is_copy_consistent(f.name							,	overwrite=_lowerCAmelCase			)
       with open(_lowerCAmelCase							,	'''r'''			) as f:
        self.assertTrue(f.read()							,	_lowerCAmelCase			)


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





      '''simple docstring'''






      UpperCamelCase__					:    int          =   check_copies.find_code_in_transformers('''models.bert.modeling_bert.BertLMPredictionHead'''			)
      self.assertEqual(_lowerCAmelCase							,	_lowerCAmelCase			)


     def      UpperCAmelCase__	(      self							:     List[str]			)  ->      List[str]:





      '''simple docstring'''






      self.check_copy_consistency(
          '''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead'''							,	'''BertLMPredictionHead'''							,	REFERENCE_CODE + '''\n'''							,	)

      # With no empty line at the end
      self.check_copy_consistency(
          '''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead'''							,	'''BertLMPredictionHead'''							,	_lowerCAmelCase							,	)

      # Copy consistency with rename
      self.check_copy_consistency(
          '''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel'''							,	'''TestModelLMPredictionHead'''							,	re.sub('''Bert'''							,	'''TestModel'''							,	_lowerCAmelCase			)							,	)

      # Copy consistency with a really long name
      UpperCamelCase__					:    int          =   '''TestModelWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason'''
      self.check_copy_consistency(
          F"# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->{long_class_name}"							,	F"{long_class_name}LMPredictionHead"							,	re.sub('''Bert'''							,	_lowerCAmelCase							,	_lowerCAmelCase			)							,	)

      # Copy consistency with overwrite
      self.check_copy_consistency(
          '''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel'''							,	'''TestModelLMPredictionHead'''							,	_lowerCAmelCase							,	overwrite_result=re.sub('''Bert'''							,	'''TestModel'''							,	_lowerCAmelCase			)							,	)


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      List[str]:





      '''simple docstring'''






      UpperCamelCase__					:    int          =   check_copies.LOCALIZED_READMES['''README_zh-hans.md''']

      UpperCamelCase__					:    Tuple          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the'''
          ''' Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for'''
          ''' Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong'''
          ''' Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.\n1.'''
          ''' **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (from HuggingFace),'''
          ''' released together with the paper [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and'''
          ''' lighter](https://arxiv.org/abs/1910.01108) by Victor Sanh, Lysandre Debut and Thomas Wolf. The same'''
          ''' method has been applied to compress GPT2 into'''
          ''' [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into'''
          ''' [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),'''
          ''' Multilingual BERT into'''
          ''' [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German'''
          ''' version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)**'''
          ''' (from Google Research/Stanford University) released with the paper [ELECTRA: Pre-training text encoders'''
          ''' as discriminators rather than generators](https://arxiv.org/abs/2003.10555) by Kevin Clark, Minh-Thang'''
          ''' Luong, Quoc V. Le, Christopher D. Manning.'''
      )
      UpperCamelCase__					:    Union[str, Any]          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the'''
          ''' Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of'''
          ''' Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian'''
          ''' Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n'''
      )
      UpperCamelCase__					:    Optional[int]          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the'''
          ''' Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of'''
          ''' Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian'''
          ''' Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n1.'''
          ''' **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (来自 HuggingFace) 伴随论文'''
          ''' [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and'''
          ''' lighter](https://arxiv.org/abs/1910.01108) 由 Victor Sanh, Lysandre Debut and Thomas Wolf 发布。 The same'''
          ''' method has been applied to compress GPT2 into'''
          ''' [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into'''
          ''' [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),'''
          ''' Multilingual BERT into'''
          ''' [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German'''
          ''' version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)** (来自'''
          ''' Google Research/Stanford University) 伴随论文 [ELECTRA: Pre-training text encoders as discriminators rather'''
          ''' than generators](https://arxiv.org/abs/2003.10555) 由 Kevin Clark, Minh-Thang Luong, Quoc V. Le,'''
          ''' Christopher D. Manning 发布。\n'''
      )

      UpperCamelCase__       ,				UpperCamelCase__					:    Any          =   check_copies.convert_to_localized_md(
          _lowerCAmelCase							,	_lowerCAmelCase							,	localized_readme['''format_model_list''']			)

      self.assertFalse(_lowerCAmelCase			)
      self.assertEqual(_lowerCAmelCase							,	_lowerCAmelCase			)

      UpperCamelCase__       ,				UpperCamelCase__					:    Union[str, Any]          =   check_copies.convert_to_localized_md(
          _lowerCAmelCase							,	_lowerCAmelCase							,	localized_readme['''format_model_list''']			)

      # Check whether the number of models is equal to README.md after conversion.
      self.assertTrue(_lowerCAmelCase			)

      UpperCamelCase__					:    List[str]          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the'''
          ''' Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for'''
          ''' Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong'''
          ''' Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.'''
      )
      UpperCamelCase__					:    Union[str, Any]          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/main/model_doc/albert.html)** (来自 Google Research and'''
          ''' the Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of'''
          ''' Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian'''
          ''' Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n'''
      )
      UpperCamelCase__					:    Dict          =   (
          '''1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the'''
          ''' Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of'''
          ''' Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian'''
          ''' Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n'''
      )

      UpperCamelCase__       ,				UpperCamelCase__					:    Dict          =   check_copies.convert_to_localized_md(
          _lowerCAmelCase							,	_lowerCAmelCase							,	localized_readme['''format_model_list''']			)

      # Check if the model link is synchronized.
      self.assertEqual(_lowerCAmelCase							,	_lowerCAmelCase			)






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


__UpperCamelCase       :       Optional[int]						       =				logging.get_logger(__name__)

__UpperCamelCase       :       Optional[int]						       =				{
    "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       __magic_name__	(     __lowerCAmelCase):
     A:		Optional[Any]			=      "markuplm"


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





      '''simple docstring'''






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


