


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import CLIPImageProcessor


class 		_SCREAMING_SNAKE_CASE    (	unittest.TestCase    ):


     def __init__(     self       ,				A_       ,				A_=7       ,				A_=3       ,				A_=18       ,				A_=30       ,				A_=4_00       ,				A_=True       ,				A_=None       ,				A_=True       ,				A_=None       ,				A_=True       ,				A_=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]       ,				A_=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]       ,				A_=True       ,				):
       _UpperCAmelCase		:       int       =    size if size is not None else {"""shortest_edge""": 20}
       _UpperCAmelCase		:       Dict       =    crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
       _UpperCAmelCase		:       List[str]       =    parent
       _UpperCAmelCase		:       Optional[int]       =    batch_size
       _UpperCAmelCase		:       Tuple       =    num_channels
       _UpperCAmelCase		:       List[Any]       =    image_size
       _UpperCAmelCase		:       Union[str, Any]       =    min_resolution
       _UpperCAmelCase		:       Optional[Any]       =    max_resolution
       _UpperCAmelCase		:       List[Any]       =    do_resize
       _UpperCAmelCase		:       Any       =    size
       _UpperCAmelCase		:       Dict       =    do_center_crop
       _UpperCAmelCase		:       Any       =    crop_size
       _UpperCAmelCase		:       str       =    do_normalize
       _UpperCAmelCase		:       Any       =    image_mean
       _UpperCAmelCase		:       Optional[int]       =    image_std
       _UpperCAmelCase		:       Dict       =    do_convert_rgb


     def 					__snake_case(     self						):
       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_convert_rgb": self.do_convert_rgb,
       }




     def 					__snake_case(     self       ,				A_=False       ,				A_=False       ,				A_=False						):
       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       if equal_resolution:
         _UpperCAmelCase		:       Optional[int]       =    []
         for i in range(self.batch_size						):
           image_inputs.append(
               np.random.randint(
                   2_55       ,				size=(self.num_channels, self.max_resolution, self.max_resolution)       ,				dtype=np.uinta						)						)
       else:
         _UpperCAmelCase		:       Union[str, Any]       =    []
         for i in range(self.batch_size						):
           _UpperCAmelCase,_UpperCAmelCase		:       str       =    np.random.choice(np.arange(self.min_resolution       ,				self.max_resolution						)       ,				2						)
           image_inputs.append(np.random.randint(2_55       ,				size=(self.num_channels, width, height)       ,				dtype=np.uinta						)						)

       if not numpify and not torchify:
         # PIL expects the channel dimension as last dimension
         _UpperCAmelCase		:       int       =    [Image.fromarray(np.moveaxis(A_       ,				0       ,				-1						)						) for x in image_inputs]

       if torchify:
         _UpperCAmelCase		:       Union[str, Any]       =    [torch.from_numpy(A_						) for x in image_inputs]

       return image_inputs


@require_torch
@require_vision
class 		_SCREAMING_SNAKE_CASE    (	A       ,  unittest.TestCase    ):
     __SCREAMING_SNAKE_CASE    				=						CLIPImageProcessor if is_vision_available() else None


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       str       =    CLIPImageProcessingTester(self						)


     @property
     def 					__snake_case(     self						):
       return self.image_processor_tester.prepare_image_processor_dict()


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       List[str]       =    self.image_processing_class(**self.image_processor_dict						)
       self.assertTrue(hasattr(A_       ,				"""do_resize"""						)						)
       self.assertTrue(hasattr(A_       ,				"""size"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_center_crop"""						)						)
       self.assertTrue(hasattr(A_       ,				"""center_crop"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_normalize"""						)						)
       self.assertTrue(hasattr(A_       ,				"""image_mean"""						)						)
       self.assertTrue(hasattr(A_       ,				"""image_std"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_convert_rgb"""						)						)


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Tuple       =    self.image_processing_class.from_dict(self.image_processor_dict						)
       self.assertEqual(image_processor.size       ,				{"""shortest_edge""": 20}						)
       self.assertEqual(image_processor.crop_size       ,				{"""height""": 18, """width""": 18}						)

       _UpperCAmelCase		:       List[str]       =    self.image_processing_class.from_dict(self.image_processor_dict       ,				size=42       ,				crop_size=84						)
       self.assertEqual(image_processor.size       ,				{"""shortest_edge""": 42}						)
       self.assertEqual(image_processor.crop_size       ,				{"""height""": 84, """width""": 84}						)


     def 					__snake_case(     self						):
       pass


     def 					__snake_case(     self						):
       # Initialize image_processing
       _UpperCAmelCase		:       str       =    self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       _UpperCAmelCase		:       List[str]       =    self.image_processor_tester.prepare_inputs(equal_resolution=A_						)
       for image in image_inputs:
         self.assertIsInstance(A_       ,				Image.Image						)

       # Test not batched input
       _UpperCAmelCase		:       int       =    image_processing(image_inputs[0]       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)

       # Test batched
       _UpperCAmelCase		:       Optional[int]       =    image_processing(A_       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)


     def 					__snake_case(     self						):
       # Initialize image_processing
       _UpperCAmelCase		:       List[str]       =    self.image_processing_class(**self.image_processor_dict						)
       # create random numpy tensors
       _UpperCAmelCase		:       Optional[int]       =    self.image_processor_tester.prepare_inputs(equal_resolution=A_       ,				numpify=A_						)
       for image in image_inputs:
         self.assertIsInstance(A_       ,				np.ndarray						)

       # Test not batched input
       _UpperCAmelCase		:       Optional[int]       =    image_processing(image_inputs[0]       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)

       # Test batched
       _UpperCAmelCase		:       int       =    image_processing(A_       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)




     def 					__snake_case(     self						):
       # Initialize image_processing
       _UpperCAmelCase		:       Union[str, Any]       =    self.image_processing_class(**self.image_processor_dict						)
       # create random PyTorch tensors
       _UpperCAmelCase		:       Optional[Any]       =    self.image_processor_tester.prepare_inputs(equal_resolution=A_       ,				torchify=A_						)
       for image in image_inputs:
         self.assertIsInstance(A_       ,				torch.Tensor						)

       # Test not batched input
       _UpperCAmelCase		:       Optional[Any]       =    image_processing(image_inputs[0]       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)

       # Test batched
       _UpperCAmelCase		:       Dict       =    image_processing(A_       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)


@require_torch
@require_vision
class 		_SCREAMING_SNAKE_CASE    (	A       ,  unittest.TestCase    ):
     __SCREAMING_SNAKE_CASE    				=						CLIPImageProcessor if is_vision_available() else None


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       List[str]       =    CLIPImageProcessingTester(self       ,				num_channels=4						)
       _UpperCAmelCase		:       Optional[int]       =    3


     @property
     def 					__snake_case(     self						):
       return self.image_processor_tester.prepare_image_processor_dict()


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Any       =    self.image_processing_class(**self.image_processor_dict						)
       self.assertTrue(hasattr(A_       ,				"""do_resize"""						)						)
       self.assertTrue(hasattr(A_       ,				"""size"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_center_crop"""						)						)
       self.assertTrue(hasattr(A_       ,				"""center_crop"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_normalize"""						)						)
       self.assertTrue(hasattr(A_       ,				"""image_mean"""						)						)
       self.assertTrue(hasattr(A_       ,				"""image_std"""						)						)
       self.assertTrue(hasattr(A_       ,				"""do_convert_rgb"""						)						)


     def 					__snake_case(     self						):
       pass




     def 					__snake_case(     self						):
       # Initialize image_processing
       _UpperCAmelCase		:       Union[str, Any]       =    self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       _UpperCAmelCase		:       str       =    self.image_processor_tester.prepare_inputs(equal_resolution=A_						)
       for image in image_inputs:
         self.assertIsInstance(A_       ,				Image.Image						)

       # Test not batched input
       _UpperCAmelCase		:       List[str]       =    image_processing(image_inputs[0]       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               1,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)

       # Test batched
       _UpperCAmelCase		:       Optional[int]       =    image_processing(A_       ,				return_tensors="""pt"""						).pixel_values
       self.assertEqual(
           encoded_images.shape       ,				(
               self.image_processor_tester.batch_size,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["""height"""],
               self.image_processor_tester.crop_size["""width"""],
           )       ,				)









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 		_SCREAMING_SNAKE_CASE    :


     def __init__(     self       ,				A_       ,				A_=13       ,				A_=7       ,				A_=True       ,				A_=True       ,				A_=True       ,				A_=True       ,				A_=99       ,				A_=32       ,				A_=5       ,				A_=4       ,				A_=37       ,				A_="gelu"       ,				A_=0.1       ,				A_=0.1       ,				A_=5_12       ,				A_=16       ,				A_=2       ,				A_=0.0_2       ,				A_=3       ,				A_=None       ,				A_=20       ,				A_=30       ,				A_=2       ,				A_=2       ,				A_=10       ,				):
       _UpperCAmelCase		:       str       =    parent
       _UpperCAmelCase		:       Dict       =    batch_size
       _UpperCAmelCase		:       Optional[int]       =    seq_length
       _UpperCAmelCase		:       Union[str, Any]       =    is_training
       _UpperCAmelCase		:       Tuple       =    use_input_mask
       _UpperCAmelCase		:       Dict       =    use_token_type_ids
       _UpperCAmelCase		:       Dict       =    use_labels
       _UpperCAmelCase		:       Optional[int]       =    vocab_size
       _UpperCAmelCase		:       List[str]       =    hidden_size
       _UpperCAmelCase		:       Tuple       =    num_hidden_layers
       _UpperCAmelCase		:       Tuple       =    num_attention_heads
       _UpperCAmelCase		:       Optional[int]       =    intermediate_size
       _UpperCAmelCase		:       str       =    hidden_act
       _UpperCAmelCase		:       Optional[Any]       =    hidden_dropout_prob
       _UpperCAmelCase		:       List[str]       =    attention_probs_dropout_prob
       _UpperCAmelCase		:       Union[str, Any]       =    max_position_embeddings
       _UpperCAmelCase		:       List[Any]       =    type_vocab_size
       _UpperCAmelCase		:       Union[str, Any]       =    type_sequence_label_size
       _UpperCAmelCase		:       List[Any]       =    initializer_range
       _UpperCAmelCase		:       Union[str, Any]       =    num_labels
       _UpperCAmelCase		:       Any       =    scope
       _UpperCAmelCase		:       List[str]       =    max_xpath_tag_unit_embeddings
       _UpperCAmelCase		:       Tuple       =    max_xpath_subs_unit_embeddings
       _UpperCAmelCase		:       Optional[Any]       =    tag_pad_id
       _UpperCAmelCase		:       Union[str, Any]       =    subs_pad_id
       _UpperCAmelCase		:       Optional[int]       =    max_depth


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Dict       =    ids_tensor([self.batch_size, self.seq_length]       ,				self.vocab_size						)

       _UpperCAmelCase		:       List[str]       =    ids_tensor(
           [self.batch_size, self.seq_length, self.max_depth]       ,				self.max_xpath_tag_unit_embeddings						)

       _UpperCAmelCase		:       Tuple       =    ids_tensor(
           [self.batch_size, self.seq_length, self.max_depth]       ,				self.max_xpath_subs_unit_embeddings						)

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

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

       _UpperCAmelCase		:       str       =    None
       _UpperCAmelCase		:       Union[str, Any]       =    None
       if self.use_labels:
         _UpperCAmelCase		:       int       =    ids_tensor([self.batch_size]       ,				self.type_sequence_label_size						)
         _UpperCAmelCase		:       int       =    ids_tensor([self.batch_size, self.seq_length]       ,				self.num_labels						)

       _UpperCAmelCase		:       List[Any]       =    self.get_config()

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


     def 					__snake_case(     self						):
       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 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
       _UpperCAmelCase		:       Tuple       =    MarkupLMModel(config=A_						)
       model.to(A_						)
       model.eval()
       print("""Configs:"""       ,				model.config.tag_pad_id       ,				model.config.subs_pad_id						)
       _UpperCAmelCase		:       List[Any]       =    model(A_       ,				attention_mask=A_       ,				token_type_ids=A_						)
       _UpperCAmelCase		:       Tuple       =    model(A_       ,				token_type_ids=A_						)
       _UpperCAmelCase		:       Union[str, Any]       =    model(A_						)
       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 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
       _UpperCAmelCase		:       Optional[int]       =    self.num_labels
       _UpperCAmelCase		:       List[Any]       =    MarkupLMForSequenceClassification(A_						)
       model.to(A_						)
       model.eval()
       _UpperCAmelCase		:       Any       =    model(
           A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				labels=A_       ,				)
       self.parent.assertEqual(result.logits.shape       ,				(self.batch_size, self.num_labels)						)


     def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
       _UpperCAmelCase		:       List[Any]       =    self.num_labels
       _UpperCAmelCase		:       Any       =    MarkupLMForTokenClassification(config=A_						)
       model.to(A_						)
       model.eval()
       _UpperCAmelCase		:       Tuple       =    model(
           A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				labels=A_       ,				)
       self.parent.assertEqual(result.logits.shape       ,				(self.batch_size, self.seq_length, self.num_labels)						)


     def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
       _UpperCAmelCase		:       List[Any]       =    MarkupLMForQuestionAnswering(config=A_						)
       model.to(A_						)
       model.eval()
       _UpperCAmelCase		:       List[Any]       =    model(
           A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				start_positions=A_       ,				end_positions=A_       ,				)
       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 					__snake_case(     self						):
       _UpperCAmelCase		:       Union[str, Any]       =    self.prepare_config_and_inputs()
       (
           (
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),(
           _UpperCAmelCase
       ),
       )		:       List[str]       =    config_and_inputs
       _UpperCAmelCase		:       Optional[Any]       =    {
           """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 		_SCREAMING_SNAKE_CASE    (	A       ,  A       ,  unittest.TestCase    ):
     __SCREAMING_SNAKE_CASE    				=						(
         (
             MarkupLMModel,
             MarkupLMForSequenceClassification,
             MarkupLMForTokenClassification,
             MarkupLMForQuestionAnswering,
         )
         if is_torch_available()
         else None
     )
     __SCREAMING_SNAKE_CASE    				=						(
         {
             '''feature-extraction''': MarkupLMModel,
             '''question-answering''': MarkupLMForQuestionAnswering,
             '''text-classification''': MarkupLMForSequenceClassification,
             '''token-classification''': MarkupLMForTokenClassification,
             '''zero-shot''': MarkupLMForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )


     def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_						):
       # ValueError: Nodes must be of type `List[str]` (single pretokenized example), or `List[List[str]]`
       # (batch of pretokenized examples).
       return True


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Union[str, Any]       =    MarkupLMModelTester(self						)
       _UpperCAmelCase		:       str       =    ConfigTester(self       ,				config_class=A_       ,				hidden_size=37						)


     def 					__snake_case(     self						):
       self.config_tester.run_common_tests()


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       List[Any]       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*A_						)


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Optional[int]       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*A_						)


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Union[str, Any]       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*A_						)




     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Any       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*A_						)




def       a__						(		):
  _UpperCAmelCase		:       Any       =    """
    <!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 		_SCREAMING_SNAKE_CASE    (	unittest.TestCase    ):


     @cached_property
     def 					__snake_case(     self						):
       # TODO use from_pretrained here
       _UpperCAmelCase		:       int       =    MarkupLMFeatureExtractor()
       _UpperCAmelCase		:       int       =    MarkupLMTokenizer.from_pretrained("""microsoft/markuplm-base"""						)

       return MarkupLMProcessor(A_       ,				A_						)




     @slow
     def 					__snake_case(     self						):
       _UpperCAmelCase		:       List[Any]       =    MarkupLMModel.from_pretrained("""microsoft/markuplm-base"""						).to(A_						)

       _UpperCAmelCase		:       Optional[Any]       =    self.default_processor

       _UpperCAmelCase		:       str       =    processor(prepare_html_string()       ,				return_tensors="""pt"""						)
       _UpperCAmelCase		:       List[str]       =    inputs.to(A_						)

       # forward pass
       with torch.no_grad():
         _UpperCAmelCase		:       Optional[Any]       =    model(**A_						)

       # verify the last hidden states
       _UpperCAmelCase		:       Tuple       =    torch.Size([1, 14, 7_68]						)
       self.assertEqual(outputs.last_hidden_state.shape       ,				A_						)

       _UpperCAmelCase		:       List[Any]       =    torch.tensor(
           [[0.0_6_7_5, -0.0_0_5_2, 0.5_0_0_1], [-0.2_2_8_1, 0.0_8_0_2, 0.2_1_9_2], [-0.0_5_8_3, -0.3_3_1_1, 0.1_1_8_5]]						).to(A_						)

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





