






import unittest

from transformers import MarkupLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MarkupLMForQuestionAnswering,
		    MarkupLMForSequenceClassification,
		    MarkupLMForTokenClassification,
		    MarkupLMModel,
		)

# TODO check dependencies
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer



class  __UpperCAmelCase						:







			def __init__(      self:    Tuple ,      UpperCAmelCase_:    Tuple ,      UpperCAmelCase_:    str=13 ,      UpperCAmelCase_:    Dict=7 ,      UpperCAmelCase_:    Tuple=True ,      UpperCAmelCase_:    int=True ,      UpperCAmelCase_:    str=True ,      UpperCAmelCase_:    Optional[int]=True ,      UpperCAmelCase_:    Dict=99 ,      UpperCAmelCase_:    List[Any]=32 ,      UpperCAmelCase_:    Dict=5 ,      UpperCAmelCase_:    Dict=4 ,      UpperCAmelCase_:    List[Any]=37 ,      UpperCAmelCase_:    Optional[int]="gelu" ,      UpperCAmelCase_:    List[Any]=0.1 ,      UpperCAmelCase_:    Tuple=0.1 ,      UpperCAmelCase_:    Tuple=512 ,      UpperCAmelCase_:    Tuple=16 ,      UpperCAmelCase_:    Optional[int]=2 ,      UpperCAmelCase_:    Optional[Any]=0.02 ,      UpperCAmelCase_:    Dict=3 ,      UpperCAmelCase_:    str=None ,      UpperCAmelCase_:    List[Any]=20 ,      UpperCAmelCase_:    Dict=30 ,      UpperCAmelCase_:    List[str]=2 ,      UpperCAmelCase_:    Optional[Any]=2 ,      UpperCAmelCase_:    List[Any]=10 ,      ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    parent
									_SCREAMING_SNAKE_CASE       =    batch_size
									_SCREAMING_SNAKE_CASE       =    seq_length
									_SCREAMING_SNAKE_CASE       =    is_training
									_SCREAMING_SNAKE_CASE       =    use_input_mask
									_SCREAMING_SNAKE_CASE       =    use_token_type_ids
									_SCREAMING_SNAKE_CASE       =    use_labels
									_SCREAMING_SNAKE_CASE       =    vocab_size
									_SCREAMING_SNAKE_CASE       =    hidden_size
									_SCREAMING_SNAKE_CASE       =    num_hidden_layers
									_SCREAMING_SNAKE_CASE       =    num_attention_heads
									_SCREAMING_SNAKE_CASE       =    intermediate_size
									_SCREAMING_SNAKE_CASE       =    hidden_act
									_SCREAMING_SNAKE_CASE       =    hidden_dropout_prob
									_SCREAMING_SNAKE_CASE       =    attention_probs_dropout_prob
									_SCREAMING_SNAKE_CASE       =    max_position_embeddings
									_SCREAMING_SNAKE_CASE       =    type_vocab_size
									_SCREAMING_SNAKE_CASE       =    type_sequence_label_size
									_SCREAMING_SNAKE_CASE       =    initializer_range
									_SCREAMING_SNAKE_CASE       =    num_labels
									_SCREAMING_SNAKE_CASE       =    scope
									_SCREAMING_SNAKE_CASE       =    max_xpath_tag_unit_embeddings
									_SCREAMING_SNAKE_CASE       =    max_xpath_subs_unit_embeddings
									_SCREAMING_SNAKE_CASE       =    tag_pad_id
									_SCREAMING_SNAKE_CASE       =    subs_pad_id
									_SCREAMING_SNAKE_CASE       =    max_depth







			def 				UpperCamelCase (      self:    Union[str, Any]	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    ids_tensor([self.batch_size, self.seq_length] ,      self.vocab_size	)

									_SCREAMING_SNAKE_CASE       =    ids_tensor(
									    [self.batch_size, self.seq_length, self.max_depth] ,      self.max_xpath_tag_unit_embeddings	)

									_SCREAMING_SNAKE_CASE       =    ids_tensor(
									    [self.batch_size, self.seq_length, self.max_depth] ,      self.max_xpath_subs_unit_embeddings	)

									_SCREAMING_SNAKE_CASE       =    None
									if self.use_input_mask:
															_SCREAMING_SNAKE_CASE       =    ids_tensor([self.batch_size, self.seq_length] ,      vocab_size=2	)

									_SCREAMING_SNAKE_CASE       =    None
									if self.use_token_type_ids:
															_SCREAMING_SNAKE_CASE       =    ids_tensor([self.batch_size, self.seq_length] ,      self.type_vocab_size	)

									_SCREAMING_SNAKE_CASE       =    None
									_SCREAMING_SNAKE_CASE       =    None
									if self.use_labels:
															_SCREAMING_SNAKE_CASE       =    ids_tensor([self.batch_size] ,      self.type_sequence_label_size	)
															_SCREAMING_SNAKE_CASE       =    ids_tensor([self.batch_size, self.seq_length] ,      self.num_labels	)

									_SCREAMING_SNAKE_CASE       =    self.get_config()

									return (
									    config,
									    input_ids,
									    xpath_tags_seq,
									    xpath_subs_seq,
									    token_type_ids,
									    input_mask,
									    sequence_labels,
									    token_labels,
									)







			def 				UpperCamelCase (      self:    Optional[int]	):







									'''simple docstring'''




									return MarkupLMConfig(
									    vocab_size=self.vocab_size ,      hidden_size=self.hidden_size ,      num_hidden_layers=self.num_hidden_layers ,      num_attention_heads=self.num_attention_heads ,      intermediate_size=self.intermediate_size ,      hidden_act=self.hidden_act ,      hidden_dropout_prob=self.hidden_dropout_prob ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob ,      max_position_embeddings=self.max_position_embeddings ,      type_vocab_size=self.type_vocab_size ,      initializer_range=self.initializer_range ,      max_xpath_tag_unit_embeddings=self.max_xpath_tag_unit_embeddings ,      max_xpath_subs_unit_embeddings=self.max_xpath_subs_unit_embeddings ,      tag_pad_id=self.tag_pad_id ,      subs_pad_id=self.subs_pad_id ,      max_depth=self.max_depth ,      )







			def 				UpperCamelCase (      self:    List[Any] ,      UpperCAmelCase_:    Any ,      UpperCAmelCase_:    Tuple ,      UpperCAmelCase_:    Tuple ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    List[Any] ,      UpperCAmelCase_:    int ,      UpperCAmelCase_:    Dict ,      UpperCAmelCase_:    Union[str, Any] ,      ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    MarkupLMModel(config=_lowerCamelCase	)
									model.to(_lowerCamelCase	)
									model.eval()
									print("""Configs:""" ,      model.config.tag_pad_id ,      model.config.subs_pad_id	)
									_SCREAMING_SNAKE_CASE       =    model(_lowerCamelCase ,      attention_mask=_lowerCamelCase ,      token_type_ids=_lowerCamelCase	)
									_SCREAMING_SNAKE_CASE       =    model(_lowerCamelCase ,      token_type_ids=_lowerCamelCase	)
									_SCREAMING_SNAKE_CASE       =    model(_lowerCamelCase	)
									self.parent.assertEqual(result.last_hidden_state.shape ,      (self.batch_size, self.seq_length, self.hidden_size)	)
									self.parent.assertEqual(result.pooler_output.shape ,      (self.batch_size, self.hidden_size)	)







			def 				UpperCamelCase (      self:    List[str] ,      UpperCAmelCase_:    Dict ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    Any ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    str ,      UpperCAmelCase_:    str ,      UpperCAmelCase_:    int ,      UpperCAmelCase_:    List[str] ,      ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.num_labels
									_SCREAMING_SNAKE_CASE       =    MarkupLMForSequenceClassification(_lowerCamelCase	)
									model.to(_lowerCamelCase	)
									model.eval()
									_SCREAMING_SNAKE_CASE       =    model(
									    _lowerCamelCase ,      xpath_tags_seq=_lowerCamelCase ,      xpath_subs_seq=_lowerCamelCase ,      attention_mask=_lowerCamelCase ,      token_type_ids=_lowerCamelCase ,      labels=_lowerCamelCase ,      )
									self.parent.assertEqual(result.logits.shape ,      (self.batch_size, self.num_labels)	)







			def 				UpperCamelCase (      self:    Tuple ,      UpperCAmelCase_:    int ,      UpperCAmelCase_:    Tuple ,      UpperCAmelCase_:    Optional[Any] ,      UpperCAmelCase_:    List[Any] ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    List[Any] ,      UpperCAmelCase_:    Tuple ,      UpperCAmelCase_:    Optional[Any] ,      ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.num_labels
									_SCREAMING_SNAKE_CASE       =    MarkupLMForTokenClassification(config=_lowerCamelCase	)
									model.to(_lowerCamelCase	)
									model.eval()
									_SCREAMING_SNAKE_CASE       =    model(
									    _lowerCamelCase ,      xpath_tags_seq=_lowerCamelCase ,      xpath_subs_seq=_lowerCamelCase ,      attention_mask=_lowerCamelCase ,      token_type_ids=_lowerCamelCase ,      labels=_lowerCamelCase ,      )
									self.parent.assertEqual(result.logits.shape ,      (self.batch_size, self.seq_length, self.num_labels)	)







			def 				UpperCamelCase (      self:    str ,      UpperCAmelCase_:    str ,      UpperCAmelCase_:    Any ,      UpperCAmelCase_:    Union[str, Any] ,      UpperCAmelCase_:    Union[str, Any] ,      UpperCAmelCase_:    List[Any] ,      UpperCAmelCase_:    List[Any] ,      UpperCAmelCase_:    List[str] ,      UpperCAmelCase_:    Union[str, Any] ,      ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    MarkupLMForQuestionAnswering(config=_lowerCamelCase	)
									model.to(_lowerCamelCase	)
									model.eval()
									_SCREAMING_SNAKE_CASE       =    model(
									    _lowerCamelCase ,      xpath_tags_seq=_lowerCamelCase ,      xpath_subs_seq=_lowerCamelCase ,      attention_mask=_lowerCamelCase ,      token_type_ids=_lowerCamelCase ,      start_positions=_lowerCamelCase ,      end_positions=_lowerCamelCase ,      )
									self.parent.assertEqual(result.start_logits.shape ,      (self.batch_size, self.seq_length)	)
									self.parent.assertEqual(result.end_logits.shape ,      (self.batch_size, self.seq_length)	)







			def 				UpperCamelCase (      self:    Dict	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.prepare_config_and_inputs()
									(
									    _SCREAMING_SNAKE_CASE  
									)       =    config_and_inputs
									_SCREAMING_SNAKE_CASE       =    {
									    """input_ids""": input_ids,
									    """xpath_tags_seq""": xpath_tags_seq,
									    """xpath_subs_seq""": xpath_subs_seq,
									    """token_type_ids""": token_type_ids,
									    """attention_mask""": input_mask,
									}
									return config, inputs_dict



@require_torch
class  __UpperCAmelCase						(__A			,__A			,unittest.TestCase       ):
			__snake_case							: List[Any]							=				(
			    (
			        MarkupLMModel,
			        MarkupLMForSequenceClassification,
			        MarkupLMForTokenClassification,
			        MarkupLMForQuestionAnswering,
			    )
			    if is_torch_available()
			    else None
			)
			__snake_case							: Dict							=				(
			    {
			        "feature-extraction": MarkupLMModel,
			        "question-answering": MarkupLMForQuestionAnswering,
			        "text-classification": MarkupLMForSequenceClassification,
			        "token-classification": MarkupLMForTokenClassification,
			        "zero-shot": MarkupLMForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)







			def 				UpperCamelCase (      self:    Optional[Any] ,      UpperCAmelCase_:    List[str] ,      UpperCAmelCase_:    Any ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    Optional[int] ,      UpperCAmelCase_:    str	):







									'''simple docstring'''




									return True







			def 				UpperCamelCase (      self:    int	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    MarkupLMModelTester(self	)
									_SCREAMING_SNAKE_CASE       =    ConfigTester(self ,      config_class=_lowerCamelCase ,      hidden_size=37	)







			def 				UpperCamelCase (      self:    Tuple	):







									'''simple docstring'''




									self.config_tester.run_common_tests()







			def 				UpperCamelCase (      self:    Dict	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_lowerCamelCase	)







			def 				UpperCamelCase (      self:    Dict	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_lowerCamelCase	)







			def 				UpperCamelCase (      self:    Union[str, Any]	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_lowerCamelCase	)







			def 				UpperCamelCase (      self:    Any	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_lowerCamelCase	)

def 			__lowerCamelCase     (						)				->    Optional[int]:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    """
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>

    </body>
    </html>
    """

						return html_string




@require_torch
class  __UpperCAmelCase						(unittest.TestCase       ):







			@cached_property
			def 				UpperCamelCase (      self:    Any	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    MarkupLMFeatureExtractor()
									_SCREAMING_SNAKE_CASE       =    MarkupLMTokenizer.from_pretrained("""microsoft/markuplm-base"""	)

									return MarkupLMProcessor(_lowerCamelCase ,      _lowerCamelCase	)







			@slow
			def 				UpperCamelCase (      self:    Union[str, Any]	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    MarkupLMModel.from_pretrained("""microsoft/markuplm-base"""	).to(_lowerCamelCase	)

									_SCREAMING_SNAKE_CASE       =    self.default_processor

									_SCREAMING_SNAKE_CASE       =    processor(prepare_html_string() ,      return_tensors="""pt"""	)
									_SCREAMING_SNAKE_CASE       =    inputs.to(_lowerCamelCase	)

									# forward pass
									with torch.no_grad():
															_SCREAMING_SNAKE_CASE       =    model(**_lowerCamelCase	)

									# verify the last hidden states
									_SCREAMING_SNAKE_CASE       =    torch.Size([1, 14, 768]	)
									self.assertEqual(outputs.last_hidden_state.shape ,      _lowerCamelCase	)

									_SCREAMING_SNAKE_CASE       =    torch.tensor(
									    [[0.06_75, -0.00_52, 0.50_01], [-0.22_81, 0.08_02, 0.21_92], [-0.05_83, -0.33_11, 0.11_85]]	).to(_lowerCamelCase	)

									self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3] ,      _lowerCamelCase ,      atol=1E-4	)	)






'''simple docstring'''





def     UpperCAmelCase     (    a_ = 9_9_8_0_0_1		)   ->       int:



   """simple docstring"""






   for number in range(n - 1      ,		9_9_9_9      ,		-1		):
      A_  :		Optional[Any]						=					str(a_		)

      # checks whether 'str_number' is a palindrome.
      if str_number == str_number[::-1]:
         A_  :		int						=					9_9_9

         # if 'number' is a product of two 3-digit numbers
         # then number is the answer otherwise fetch next number.
         while divisor != 9_9:
            if (number % divisor == 0) and (len(str(number // divisor		)		) == 3.0):
               return number
            divisor -= 1
   raise ValueError("""That number is larger than our acceptable range."""		)


if __name__ == "__main__":
  print(f'{solution() = }')
