




"""simple docstring"""

import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
		import torch
		from torch import nn

		from transformers import (
		    MODEL_MAPPING,
		    DataaVecVisionForImageClassification,
		    DataaVecVisionForSemanticSegmentation,
		    DataaVecVisionModel,
		)
		from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import BeitImageProcessor

class     lowercase :







				def __init__(							self				:   int ,       _lowerCamelCase				:   Tuple ,       _lowerCamelCase				:   List[str]=1_00 ,       _lowerCamelCase				:   int=13 ,       _lowerCamelCase				:   List[str]=30 ,       _lowerCamelCase				:   List[str]=2 ,       _lowerCamelCase				:   Union[str, Any]=3 ,       _lowerCamelCase				:   Union[str, Any]=True ,       _lowerCamelCase				:   List[str]=True ,       _lowerCamelCase				:   int=32 ,       _lowerCamelCase				:   Dict=4 ,       _lowerCamelCase				:   Optional[int]=4 ,       _lowerCamelCase				:   Any=37 ,       _lowerCamelCase				:   List[Any]="gelu" ,       _lowerCamelCase				:   Tuple=0.1 ,       _lowerCamelCase				:   str=0.1 ,       _lowerCamelCase				:   Union[str, Any]=10 ,       _lowerCamelCase				:   str=0.02 ,       _lowerCamelCase				:   str=3 ,       _lowerCamelCase				:   Optional[int]=None ,       _lowerCamelCase				:   Optional[int]=[0, 1, 2, 3] ,       ):



					"""simple docstring"""

					A_					:			str						=						parent
					A_					:			Dict						=						1_00
					A_					:			List[str]						=						batch_size
					A_					:			int						=						image_size
					A_					:			Optional[int]						=						patch_size
					A_					:			Optional[Any]						=						num_channels
					A_					:			List[Any]						=						is_training
					A_					:			Tuple						=						use_labels
					A_					:			Optional[Any]						=						hidden_size
					A_					:			Any						=						num_hidden_layers
					A_					:			List[str]						=						num_attention_heads
					A_					:			Optional[Any]						=						intermediate_size
					A_					:			Dict						=						hidden_act
					A_					:			List[str]						=						hidden_dropout_prob
					A_					:			Optional[Any]						=						attention_probs_dropout_prob
					A_					:			Optional[Any]						=						type_sequence_label_size
					A_					:			List[Any]						=						initializer_range
					A_					:			Union[str, Any]						=						scope
					A_					:			Dict						=						out_indices
					A_					:			Optional[Any]						=						num_labels

					# in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
					A_					:			str						=						(image_size // patch_size) ** 2
					A_					:			str						=						num_patches + 1







				def    a_					(							self				:   List[Any]    ):



					"""simple docstring"""

					A_					:			int						=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

					A_					:			Dict						=						None
					A_					:			Any						=						None
					if self.use_labels:
						A_					:			Dict						=						ids_tensor([self.batch_size] ,       self.type_sequence_label_size    )
						A_					:			Optional[int]						=						ids_tensor([self.batch_size, self.image_size, self.image_size] ,       self.num_labels    )

					A_					:			Optional[Any]						=						self.get_config()

					return config, pixel_values, labels, pixel_labels







				def    a_					(							self				:   Dict    ):



					"""simple docstring"""

					return DataaVecVisionConfig(
					    vocab_size=self.vocab_size ,       image_size=self.image_size ,       patch_size=self.patch_size ,       num_channels=self.num_channels ,       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 ,       is_decoder=lowercase__ ,       initializer_range=self.initializer_range ,       out_indices=self.out_indices ,       )







				def    a_					(							self				:   int ,       _lowerCamelCase				:   List[str] ,       _lowerCamelCase				:   Union[str, Any] ,       _lowerCamelCase				:   List[Any] ,       _lowerCamelCase				:   List[Any]    ):



					"""simple docstring"""

					A_					:			Optional[Any]						=						DataaVecVisionModel(config=lowercase__    )
					model.to(lowercase__    )
					model.eval()
					A_					:			int						=						model(lowercase__    )
					# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
					A_					:			int						=						(self.image_size // self.patch_size) ** 2
					self.parent.assertEqual(result.last_hidden_state.shape ,       (self.batch_size, num_patches + 1, self.hidden_size)    )







				def    a_					(							self				:   List[Any] ,       _lowerCamelCase				:   Optional[int] ,       _lowerCamelCase				:   List[Any] ,       _lowerCamelCase				:   Tuple ,       _lowerCamelCase				:   Optional[int]    ):



					"""simple docstring"""

					A_					:			List[Any]						=						self.type_sequence_label_size
					A_					:			Optional[int]						=						DataaVecVisionForImageClassification(lowercase__    )
					model.to(lowercase__    )
					model.eval()
					A_					:			Optional[Any]						=						model(lowercase__ ,       labels=lowercase__    )
					self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.type_sequence_label_size)    )







				def    a_					(							self				:   List[str] ,       _lowerCamelCase				:   str ,       _lowerCamelCase				:   List[Any] ,       _lowerCamelCase				:   List[str] ,       _lowerCamelCase				:   List[Any]    ):



					"""simple docstring"""

					A_					:			Optional[int]						=						self.num_labels
					A_					:			List[str]						=						DataaVecVisionForSemanticSegmentation(lowercase__    )
					model.to(lowercase__    )
					model.eval()
					A_					:			Tuple						=						model(lowercase__    )
					self.parent.assertEqual(
					    result.logits.shape ,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)    )
					A_					:			List[Any]						=						model(lowercase__ ,       labels=lowercase__    )
					self.parent.assertEqual(
					    result.logits.shape ,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)    )







				def    a_					(							self				:   int    ):



					"""simple docstring"""

					A_					:			List[str]						=						self.prepare_config_and_inputs()
					A_				,	A_				,	A_				,	A_					:			Dict						=						config_and_inputs
					A_					:			Any						=						{'''pixel_values''': pixel_values}
					return config, inputs_dict

@require_torch
class     lowercase (      __UpperCAmelCase       ,		__UpperCAmelCase       ,		unittest.TestCase):
				__lowerCAmelCase					    =				(
				    (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
				    if is_torch_available()
				    else ()
				)
				__lowerCAmelCase					    =				(
				    {
				        "feature-extraction": DataaVecVisionModel,
				        "image-classification": DataaVecVisionForImageClassification,
				        "image-segmentation": DataaVecVisionForSemanticSegmentation,
				    }
				    if is_torch_available()
				    else {}
				)

				__lowerCAmelCase					    =				False
				__lowerCAmelCase					    =				False
				__lowerCAmelCase					    =				False







				def    a_					(							self				:   Optional[Any]    ):



					"""simple docstring"""

					A_					:			Optional[int]						=						DataaVecVisionModelTester(self    )
					A_					:			List[str]						=						ConfigTester(
					    self ,       config_class=lowercase__ ,       has_text_modality=lowercase__ ,       hidden_size=37    )







				def    a_					(							self				:   Tuple    ):



					"""simple docstring"""

					self.config_tester.run_common_tests()







				def    a_					(							self				:   Optional[int]    ):



					"""simple docstring"""

					pass







				@require_torch_multi_gpu
				@unittest.skip(
				    reason='''Data2VecVision has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''    )
				def    a_					(							self				:   Optional[int]    ):



					"""simple docstring"""

					pass







				def    a_					(							self				:   Dict    ):



					"""simple docstring"""

					A_				,	A_					:			str						=						self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						A_					:			Tuple						=						model_class(lowercase__    )
						self.assertIsInstance(model.get_input_embeddings() ,       (nn.Module)    )
						A_					:			Optional[Any]						=						model.get_output_embeddings()
						self.assertTrue(x is None or isinstance(lowercase__ ,       nn.Linear    )    )







				def    a_					(							self				:   List[Any]    ):



					"""simple docstring"""

					A_				,	A_					:			str						=						self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						A_					:			List[str]						=						model_class(lowercase__    )
						A_					:			Any						=						inspect.signature(model.forward    )
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						A_					:			Optional[Any]						=						[*signature.parameters.keys()]

						A_					:			Optional[Any]						=						['''pixel_values''']
						self.assertListEqual(arg_names[:1] ,       lowercase__    )







				def    a_					(							self				:   Optional[Any]    ):



					"""simple docstring"""

					A_					:			Any						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowercase__    )







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



					"""simple docstring"""

					A_					:			Tuple						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_segmentation(*lowercase__    )







				def    a_					(							self				:   Optional[int]    ):



					"""simple docstring"""

					if not self.model_tester.is_training:
						return

					A_				,	A_					:			List[Any]						=						self.model_tester.prepare_config_and_inputs_for_common()
					A_					:			int						=						True

					for model_class in self.all_model_classes:
						if model_class in [*get_values(lowercase__    )]:
							continue

						A_					:			List[Any]						=						model_class(lowercase__    )
						model.to(lowercase__    )
						model.train()
						A_					:			Dict						=						self._prepare_for_class(lowercase__ ,       lowercase__ ,       return_labels=lowercase__    )
						A_					:			Union[str, Any]						=						model(**lowercase__    ).loss
						loss.backward()







				def    a_					(							self				:   Optional[Any]    ):



					"""simple docstring"""

					A_				,	A_					:			str						=						self.model_tester.prepare_config_and_inputs_for_common()
					if not self.model_tester.is_training:
						return

					A_					:			Tuple						=						False
					A_					:			Optional[Any]						=						True

					for model_class in self.all_model_classes:
						if model_class in [*get_values(lowercase__    )] or not model_class.supports_gradient_checkpointing:
							continue
						# TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
						# this can then be incorporated into _prepare_for_class in test_modeling_common.py
						elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
							A_				,	A_				,	A_				,	A_					:			Any						=						inputs_dict['''pixel_values'''].shape
							A_					:			List[Any]						=						torch.zeros(
							    [self.model_tester.batch_size, height, width] ,       device=lowercase__    ).long()
						A_					:			Any						=						model_class(lowercase__    )
						model.gradient_checkpointing_enable()
						model.to(lowercase__    )
						model.train()
						A_					:			Any						=						self._prepare_for_class(lowercase__ ,       lowercase__ ,       return_labels=lowercase__    )
						A_					:			int						=						model(**lowercase__    ).loss
						loss.backward()







				def    a_					(							self				:   Optional[int]    ):



					"""simple docstring"""

					A_				,	A_					:			Tuple						=						self.model_tester.prepare_config_and_inputs_for_common()

					A_					:			str						=						_config_zero_init(lowercase__    )
					for model_class in self.all_model_classes:
						A_					:			List[Any]						=						model_class(config=lowercase__    )
						for name, param in model.named_parameters():
							# we skip lambda parameters as these require special initial values
							# determined by config.layer_scale_init_value
							if "lambda" in name:
								continue
							if param.requires_grad:
								self.assertIn(
								    ((param.data.mean() * 1E9).round() / 1E9).item() ,       [0.0, 1.0] ,       msg=F"""Parameter {name} of model {model_class} seems not properly initialized""" ,       )







				def    a_					(							self				:   int ,       _lowerCamelCase				:   Any ,       _lowerCamelCase				:   Optional[Any] ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   List[Any]=2E-4 ,       _lowerCamelCase				:   str="outputs" ,       _lowerCamelCase				:   Dict=None    ):



					"""simple docstring"""

					super().check_pt_tf_outputs(lowercase__ ,       lowercase__ ,       lowercase__ ,       lowercase__ ,       lowercase__ ,       lowercase__    )







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



					"""simple docstring"""

					A_					:			Any						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*lowercase__    )







				@slow
				def    a_					(							self				:   Dict    ):



					"""simple docstring"""

					for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						A_					:			List[Any]						=						DataaVecVisionModel.from_pretrained(lowercase__    )
						self.assertIsNotNone(lowercase__    )

def 						lowercase_ (						):




	"""simple docstring"""






	A_					:			List[str]						=						Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
	return image

@require_torch
@require_vision
class     lowercase (      unittest.TestCase):







				@cached_property
				def    a_					(							self				:   Dict    ):



					"""simple docstring"""

					return (
					    BeitImageProcessor.from_pretrained('''facebook/data2vec-vision-base-ft1k'''    ) if is_vision_available() else None
					)







				@slow
				def    a_					(							self				:   int    ):



					"""simple docstring"""

					A_					:			List[Any]						=						DataaVecVisionForImageClassification.from_pretrained('''facebook/data2vec-vision-base-ft1k'''    ).to(
					    lowercase__    )

					A_					:			List[Any]						=						self.default_image_processor
					A_					:			str						=						prepare_img()
					A_					:			Tuple						=						image_processor(images=lowercase__ ,       return_tensors='''pt'''    ).to(lowercase__    )

					# forward pass
					with torch.no_grad():
						A_					:			str						=						model(**lowercase__    )
					A_					:			Any						=						outputs.logits

					# verify the logits
					A_					:			str						=						torch.Size((1, 10_00)    )
					self.assertEqual(logits.shape ,       lowercase__    )

					A_					:			str						=						torch.tensor([0.3277, -0.1395, 0.0911]    ).to(lowercase__    )

					self.assertTrue(torch.allclose(logits[0, :3] ,       lowercase__ ,       atol=1E-4    )    )

					A_					:			Any						=						[model.config.labelaid[i] for i in ['''remote control, remote''', '''tabby, tabby cat''']]
					self.assertEqual(logits[0].topk(2    ).indices.cpu().tolist() ,       lowercase__    )











"""simple docstring"""

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







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



					"""simple docstring"""

					A_					:			Dict						=						parent
					A_					:			Tuple						=						batch_size
					A_					:			Dict						=						seq_length
					A_					:			Any						=						is_training
					A_					:			List[str]						=						use_input_mask
					A_					:			Union[str, Any]						=						use_token_type_ids
					A_					:			int						=						use_labels
					A_					:			List[Any]						=						vocab_size
					A_					:			Dict						=						hidden_size
					A_					:			List[Any]						=						num_hidden_layers
					A_					:			str						=						num_attention_heads
					A_					:			str						=						intermediate_size
					A_					:			Tuple						=						hidden_act
					A_					:			List[str]						=						hidden_dropout_prob
					A_					:			Any						=						attention_probs_dropout_prob
					A_					:			Union[str, Any]						=						max_position_embeddings
					A_					:			Any						=						type_vocab_size
					A_					:			List[Any]						=						type_sequence_label_size
					A_					:			str						=						initializer_range
					A_					:			str						=						num_labels
					A_					:			Tuple						=						scope
					A_					:			Optional[int]						=						max_xpath_tag_unit_embeddings
					A_					:			List[Any]						=						max_xpath_subs_unit_embeddings
					A_					:			List[str]						=						tag_pad_id
					A_					:			Tuple						=						subs_pad_id
					A_					:			int						=						max_depth







				def    a_					(							self				:   int    ):



					"""simple docstring"""

					A_					:			Optional[int]						=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size    )

					A_					:			Union[str, Any]						=						ids_tensor(
					    [self.batch_size, self.seq_length, self.max_depth] ,       self.max_xpath_tag_unit_embeddings    )

					A_					:			Optional[Any]						=						ids_tensor(
					    [self.batch_size, self.seq_length, self.max_depth] ,       self.max_xpath_subs_unit_embeddings    )

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

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

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

					A_					:			int						=						self.get_config()

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







				def    a_					(							self				:   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    a_					(							self				:   int ,       _lowerCamelCase				:   List[Any] ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   List[Any] ,       _lowerCamelCase				:   Optional[int] ,       _lowerCamelCase				:   Optional[Any] ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   Optional[int] ,       ):



					"""simple docstring"""

					A_					:			Tuple						=						MarkupLMModel(config=_lowerCamelCase    )
					model.to(_lowerCamelCase    )
					model.eval()
					print('''Configs:''' ,       model.config.tag_pad_id ,       model.config.subs_pad_id    )
					A_					:			List[str]						=						model(_lowerCamelCase ,       attention_mask=_lowerCamelCase ,       token_type_ids=_lowerCamelCase    )
					A_					:			List[str]						=						model(_lowerCamelCase ,       token_type_ids=_lowerCamelCase    )
					A_					:			Dict						=						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    a_					(							self				:   Optional[Any] ,       _lowerCamelCase				:   Optional[Any] ,       _lowerCamelCase				:   Union[str, Any] ,       _lowerCamelCase				:   List[str] ,       _lowerCamelCase				:   Union[str, Any] ,       _lowerCamelCase				:   str ,       _lowerCamelCase				:   Dict ,       _lowerCamelCase				:   Dict ,       _lowerCamelCase				:   List[Any] ,       ):



					"""simple docstring"""

					A_					:			Any						=						self.num_labels
					A_					:			str						=						MarkupLMForSequenceClassification(_lowerCamelCase    )
					model.to(_lowerCamelCase    )
					model.eval()
					A_					:			str						=						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    a_					(							self				:   Union[str, Any] ,       _lowerCamelCase				:   Any ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   str ,       _lowerCamelCase				:   str ,       _lowerCamelCase				:   Tuple ,       _lowerCamelCase				:   Optional[int] ,       _lowerCamelCase				:   List[str] ,       _lowerCamelCase				:   List[Any] ,       ):



					"""simple docstring"""

					A_					:			str						=						self.num_labels
					A_					:			int						=						MarkupLMForTokenClassification(config=_lowerCamelCase    )
					model.to(_lowerCamelCase    )
					model.eval()
					A_					:			List[Any]						=						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    a_					(							self				:   Any ,       _lowerCamelCase				:   Union[str, Any] ,       _lowerCamelCase				:   str ,       _lowerCamelCase				:   Union[str, Any] ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   int ,       _lowerCamelCase				:   Dict ,       _lowerCamelCase				:   Tuple ,       _lowerCamelCase				:   Optional[Any] ,       ):



					"""simple docstring"""

					A_					:			Dict						=						MarkupLMForQuestionAnswering(config=_lowerCamelCase    )
					model.to(_lowerCamelCase    )
					model.eval()
					A_					:			List[Any]						=						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    a_					(							self				:   List[str]    ):



					"""simple docstring"""

					A_					:			str						=						self.prepare_config_and_inputs()
					(
					    (
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	(
					    A_
					)				,	
					)					:			List[Any]						=						config_and_inputs
					A_					:			Tuple						=						{
					    '''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     lowercase (      __UpperCAmelCase       ,		__UpperCAmelCase       ,		unittest.TestCase):
				__lowerCAmelCase      :      Union[str, Any]					    =				(
				    (
				        MarkupLMModel,
				        MarkupLMForSequenceClassification,
				        MarkupLMForTokenClassification,
				        MarkupLMForQuestionAnswering,
				    )
				    if is_torch_available()
				    else None
				)
				__lowerCAmelCase      :      Optional[int]					    =				(
				    {
				        """feature-extraction""": MarkupLMModel,
				        """question-answering""": MarkupLMForQuestionAnswering,
				        """text-classification""": MarkupLMForSequenceClassification,
				        """token-classification""": MarkupLMForTokenClassification,
				        """zero-shot""": MarkupLMForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)







				def    a_					(							self				:   List[str] ,       _lowerCamelCase				:   Optional[int] ,       _lowerCamelCase				:   Dict ,       _lowerCamelCase				:   Optional[int] ,       _lowerCamelCase				:   Optional[Any] ,       _lowerCamelCase				:   Any    ):



					"""simple docstring"""

					return True







				def    a_					(							self				:   int    ):



					"""simple docstring"""

					A_					:			Tuple						=						MarkupLMModelTester(self    )
					A_					:			List[str]						=						ConfigTester(self ,       config_class=_lowerCamelCase ,       hidden_size=37    )







				def    a_					(							self				:   List[str]    ):



					"""simple docstring"""

					self.config_tester.run_common_tests()







				def    a_					(							self				:   str    ):



					"""simple docstring"""

					A_					:			str						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*_lowerCamelCase    )







				def    a_					(							self				:   Tuple    ):



					"""simple docstring"""

					A_					:			Tuple						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*_lowerCamelCase    )







				def    a_					(							self				:   Optional[Any]    ):



					"""simple docstring"""

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







				def    a_					(							self				:   Optional[int]    ):



					"""simple docstring"""

					A_					:			Tuple						=						self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*_lowerCamelCase    )

def 						lowercase_ (						):




	"""simple docstring"""






	A_					:			Dict						=						'''
    <!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     lowercase (      unittest.TestCase):







				@cached_property
				def    a_					(							self				:   Tuple    ):



					"""simple docstring"""

					A_					:			int						=						MarkupLMFeatureExtractor()
					A_					:			Optional[int]						=						MarkupLMTokenizer.from_pretrained('''microsoft/markuplm-base'''    )

					return MarkupLMProcessor(_lowerCamelCase ,       _lowerCamelCase    )







				@slow
				def    a_					(							self				:   Optional[Any]    ):



					"""simple docstring"""

					A_					:			List[Any]						=						MarkupLMModel.from_pretrained('''microsoft/markuplm-base'''    ).to(_lowerCamelCase    )

					A_					:			List[Any]						=						self.default_processor

					A_					:			List[Any]						=						processor(prepare_html_string() ,       return_tensors='''pt'''    )
					A_					:			Tuple						=						inputs.to(_lowerCamelCase    )

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

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

					A_					:			Dict						=						torch.tensor(
					    [[0.0675, -0.0052, 0.5001], [-0.2281, 0.0802, 0.2192], [-0.0583, -0.3311, 0.1185]]    ).to(_lowerCamelCase    )

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





