


"""simple docstring"""
import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizerFast

from diffusers import DDIMScheduler, KandinskyPipeline, KandinskyPriorPipeline, UNetaDConditionModel, VQModel
from diffusers.pipelines.kandinsky.text_encoder import MCLIPConfig, MultilingualCLIP
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()





class   __A  (lowercase__    ,		unittest.TestCase):





							'''simple docstring'''

							__lowercase:		Dict				   =     KandinskyPipeline
							__lowercase:		Any				   =     [
							    """prompt""",
							    """image_embeds""",
							    """negative_image_embeds""",
							]
							__lowercase:		Union[str, Any]				   =     ["""prompt""", """negative_prompt""", """image_embeds""", """negative_image_embeds"""]
							__lowercase:		str				   =     [
							    """generator""",
							    """height""",
							    """width""",
							    """latents""",
							    """guidance_scale""",
							    """negative_prompt""",
							    """num_inference_steps""",
							    """return_dict""",
							    """guidance_scale""",
							    """num_images_per_prompt""",
							    """output_type""",
							    """return_dict""",
							]
							__lowercase:		List[Any]				   =     False



							@property
							def 		lowerCAmelCase							(					self				:   Optional[int]							)       ->Any:



														"""simple docstring"""



														return 32



							@property
							def 		lowerCAmelCase							(					self				:   Tuple							)       ->Any:



														"""simple docstring"""



														return 32



							@property
							def 		lowerCAmelCase							(					self				:   List[Any]							)       ->Optional[Any]:



														"""simple docstring"""



														return self.time_input_dim



							@property
							def 		lowerCAmelCase							(					self				:   int							)       ->Optional[int]:



														"""simple docstring"""



														return self.time_input_dim * 4



							@property
							def 		lowerCAmelCase							(					self				:   Optional[int]							)       ->Tuple:



														"""simple docstring"""



														return 100



							@property
							def 		lowerCAmelCase							(					self				:   List[str]							)       ->Dict:



														"""simple docstring"""



														snake_case_     							=		XLMRobertaTokenizerFast.from_pretrained("""YiYiXu/tiny-random-mclip-base"""							)
														return tokenizer



							@property
							def 		lowerCAmelCase							(					self				:   List[Any]							)       ->Union[str, Any]:



														"""simple docstring"""



														torch.manual_seed(0							)
														snake_case_     							=		MCLIPConfig(
														    numDims=self.cross_attention_dim		,							transformerDimensions=self.text_embedder_hidden_size		,							hidden_size=self.text_embedder_hidden_size		,							intermediate_size=37		,							num_attention_heads=4		,							num_hidden_layers=5		,							vocab_size=1_005		,							)

														snake_case_     							=		MultilingualCLIP(__lowerCamelCase							)
														snake_case_     							=		text_encoder.eval()

														return text_encoder



							@property
							def 		lowerCAmelCase							(					self				:   List[Any]							)       ->List[Any]:



														"""simple docstring"""



														torch.manual_seed(0							)

														snake_case_     							=		{
														    "in_channels": 4,
														    # Out channels is double in channels because predicts mean and variance
														    "out_channels": 8,
														    "addition_embed_type": "text_image",
														    "down_block_types": ("ResnetDownsampleBlock2D", "SimpleCrossAttnDownBlock2D"),
														    "up_block_types": ("SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"),
														    "mid_block_type": "UNetMidBlock2DSimpleCrossAttn",
														    "block_out_channels": (self.block_out_channels_a, self.block_out_channels_a * 2),
														    "layers_per_block": 1,
														    "encoder_hid_dim": self.text_embedder_hidden_size,
														    "encoder_hid_dim_type": "text_image_proj",
														    "cross_attention_dim": self.cross_attention_dim,
														    "attention_head_dim": 4,
														    "resnet_time_scale_shift": "scale_shift",
														    "class_embed_type": None,
														}

														snake_case_     							=		UNetaDConditionModel(**__lowerCamelCase							)
														return model



							@property
							def 		lowerCAmelCase							(					self				:   str							)       ->Optional[Any]:



														"""simple docstring"""



														return {
														    "block_out_channels": [32, 64],
														    "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
														    "in_channels": 3,
														    "latent_channels": 4,
														    "layers_per_block": 1,
														    "norm_num_groups": 8,
														    "norm_type": "spatial",
														    "num_vq_embeddings": 12,
														    "out_channels": 3,
														    "up_block_types": [
														        "AttnUpDecoderBlock2D",
														        "UpDecoderBlock2D",
														    ],
														    "vq_embed_dim": 4,
														}



							@property
							def 		lowerCAmelCase							(					self				:   List[Any]							)       ->Tuple:



														"""simple docstring"""



														torch.manual_seed(0							)
														snake_case_     							=		VQModel(**self.dummy_movq_kwargs							)
														return model



							def 		lowerCAmelCase							(					self				:   List[Any]							)       ->List[Any]:



														"""simple docstring"""



														snake_case_     							=		self.dummy_text_encoder
														snake_case_     							=		self.dummy_tokenizer
														snake_case_     							=		self.dummy_unet
														snake_case_     							=		self.dummy_movq

														snake_case_     							=		DDIMScheduler(
														    num_train_timesteps=1_000		,							beta_schedule="""linear"""		,							beta_start=0.00_085		,							beta_end=0.012		,							clip_sample=__lowerCamelCase		,							set_alpha_to_one=__lowerCamelCase		,							steps_offset=1		,							prediction_type="""epsilon"""		,							thresholding=__lowerCamelCase		,							)

														snake_case_     							=		{
														    "text_encoder": text_encoder,
														    "tokenizer": tokenizer,
														    "unet": unet,
														    "scheduler": scheduler,
														    "movq": movq,
														}
														return components



							def 		lowerCAmelCase							(					self				:   Dict		,							UpperCAmelCase_				:   List[str]		,							UpperCAmelCase_				:   str=0							)       ->Union[str, Any]:



														"""simple docstring"""



														snake_case_     							=		floats_tensor((1, self.cross_attention_dim)		,							rng=random.Random(__lowerCamelCase							)							).to(__lowerCamelCase							)
														snake_case_     							=		floats_tensor((1, self.cross_attention_dim)		,							rng=random.Random(seed + 1							)							).to(__lowerCamelCase							)
														if str(__lowerCamelCase							).startswith("""mps"""							):
																					snake_case_     							=		torch.manual_seed(__lowerCamelCase							)
														else:
																					snake_case_     							=		torch.Generator(device=__lowerCamelCase							).manual_seed(__lowerCamelCase							)
														snake_case_     							=		{
														    "prompt": "horse",
														    "image_embeds": image_embeds,
														    "negative_image_embeds": negative_image_embeds,
														    "generator": generator,
														    "height": 64,
														    "width": 64,
														    "guidance_scale": 4.0,
														    "num_inference_steps": 2,
														    "output_type": "np",
														}
														return inputs



							def 		lowerCAmelCase							(					self				:   Any							)       ->Optional[int]:



														"""simple docstring"""



														snake_case_     							=		"cpu"

														snake_case_     							=		self.get_dummy_components()

														snake_case_     							=		self.pipeline_class(**__lowerCamelCase							)
														snake_case_     							=		pipe.to(__lowerCamelCase							)

														pipe.set_progress_bar_config(disable=__lowerCamelCase							)

														snake_case_     							=		pipe(**self.get_dummy_inputs(__lowerCamelCase							)							)
														snake_case_     							=		output.images

														snake_case_     							=		pipe(
														    **self.get_dummy_inputs(__lowerCamelCase							)		,							return_dict=__lowerCamelCase		,							)[0]

														snake_case_     							=		image[0, -3:, -3:, -1]
														snake_case_     							=		image_from_tuple[0, -3:, -3:, -1]

														assert image.shape == (1, 64, 64, 3)

														snake_case_     							=		np.array(
														    [0.328_663, 1.0, 0.23_216_873, 1.0, 0.92_717_564, 0.4_639_046, 0.96_894_777, 0.31_713_378, 0.6_293_953]							)

														assert (
														    np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
														), F""" expected_slice {expected_slice}, but got {image_slice.flatten()}"""
														assert (
														    np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1E-2
														), F""" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"""





@slow
@require_torch_gpu
class   __A  (unittest.TestCase):





							'''simple docstring'''

							def 		lowerCAmelCase							(					self				:   Dict							)       ->List[Any]:



														"""simple docstring"""



														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()



							def 		lowerCAmelCase							(					self				:   Optional[int]							)       ->Union[str, Any]:



														"""simple docstring"""



														snake_case_     							=		load_numpy(
														    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
														    """/kandinsky/kandinsky_text2img_cat_fp16.npy"""							)

														snake_case_     							=		KandinskyPriorPipeline.from_pretrained(
														    """kandinsky-community/kandinsky-2-1-prior"""		,							torch_dtype=torch.floataa							)
														pipe_prior.to(__lowerCamelCase							)

														snake_case_     							=		KandinskyPipeline.from_pretrained("""kandinsky-community/kandinsky-2-1"""		,							torch_dtype=torch.floataa							)
														snake_case_     							=		pipeline.to(__lowerCamelCase							)
														pipeline.set_progress_bar_config(disable=__lowerCamelCase							)

														snake_case_     							=		"red cat, 4k photo"

														snake_case_     							=		torch.Generator(device="""cuda"""							).manual_seed(0							)
														snake_case_     							=		pipe_prior(
														    __lowerCamelCase		,							generator=__lowerCamelCase		,							num_inference_steps=5		,							negative_prompt=""""""		,							).to_tuple()

														snake_case_     							=		torch.Generator(device="""cuda"""							).manual_seed(0							)
														snake_case_     							=		pipeline(
														    __lowerCamelCase		,							image_embeds=__lowerCamelCase		,							negative_image_embeds=__lowerCamelCase		,							generator=__lowerCamelCase		,							num_inference_steps=100		,							output_type="""np"""		,							)

														snake_case_     							=		output.images[0]

														assert image.shape == (512, 512, 3)

														assert_mean_pixel_difference(__lowerCamelCase		,							__lowerCamelCase							)







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					:


       """simple docstring"""




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


             '''simple docstring'''



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





       def 		lowerCAmelCase	(  self				:     int			):


             '''simple docstring'''



             lowerCamelCase__						:							Dict       =    ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size			)

             lowerCamelCase__						:							List[Any]       =    ids_tensor(
                 [self.batch_size, self.seq_length, self.max_depth]   , self.max_xpath_tag_unit_embeddings			)

             lowerCamelCase__						:							int       =    ids_tensor(
                 [self.batch_size, self.seq_length, self.max_depth]   , self.max_xpath_subs_unit_embeddings			)

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

             lowerCamelCase__						:							int       =    None
             if self.use_token_type_ids:
                   lowerCamelCase__						:							Union[str, Any]       =    ids_tensor([self.batch_size, self.seq_length]   , self.type_vocab_size			)

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

             lowerCamelCase__						:							int       =    self.get_config()

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





       def 		lowerCAmelCase	(  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 		lowerCAmelCase	(  self				:     Optional[Any]   , __lowerCamelCase				:     Union[str, Any]   , __lowerCamelCase				:     Optional[int]   , __lowerCamelCase				:     str   , __lowerCamelCase				:     Tuple   , __lowerCamelCase				:     List[Any]   , __lowerCamelCase				:     List[Any]   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     str   , ):


             '''simple docstring'''



             lowerCamelCase__						:							List[Any]       =    MarkupLMModel(config=__lowerCamelCase			)
             model.to(__lowerCamelCase			)
             model.eval()
             print("Configs:"   , model.config.tag_pad_id   , model.config.subs_pad_id			)
             lowerCamelCase__						:							Optional[int]       =    model(__lowerCamelCase   , attention_mask=__lowerCamelCase   , token_type_ids=__lowerCamelCase			)
             lowerCamelCase__						:							List[str]       =    model(__lowerCamelCase   , token_type_ids=__lowerCamelCase			)
             lowerCamelCase__						:							str       =    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 		lowerCAmelCase	(  self				:     Dict   , __lowerCamelCase				:     Union[str, Any]   , __lowerCamelCase				:     Tuple   , __lowerCamelCase				:     int   , __lowerCamelCase				:     Dict   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     Tuple   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     List[Any]   , ):


             '''simple docstring'''



             lowerCamelCase__						:							Optional[Any]       =    self.num_labels
             lowerCamelCase__						:							str       =    MarkupLMForSequenceClassification(__lowerCamelCase			)
             model.to(__lowerCamelCase			)
             model.eval()
             lowerCamelCase__						:							Optional[int]       =    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 		lowerCAmelCase	(  self				:     Any   , __lowerCamelCase				:     Optional[int]   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     List[str]   , __lowerCamelCase				:     List[Any]   , __lowerCamelCase				:     int   , __lowerCamelCase				:     str   , ):


             '''simple docstring'''



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


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    MarkupLMForQuestionAnswering(config=__lowerCamelCase			)
             model.to(__lowerCamelCase			)
             model.eval()
             lowerCamelCase__						:							Union[str, 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 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    self.prepare_config_and_inputs()
             (
                 (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  (
                 lowerCamelCase__
             )       ,  
             )						:							Optional[int]       =    config_and_inputs
             lowerCamelCase__						:							List[str]       =    {
                 "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					(				lowercase__				,    lowercase__				,    unittest.TestCase):


       """simple docstring"""




       A__   		=     (
           (
               MarkupLMModel,
               MarkupLMForSequenceClassification,
               MarkupLMForTokenClassification,
               MarkupLMForQuestionAnswering,
           )
           if is_torch_available()
           else None
       )
       A__   		=     (
           {
               "feature-extraction": MarkupLMModel,
               "question-answering": MarkupLMForQuestionAnswering,
               "text-classification": MarkupLMForSequenceClassification,
               "token-classification": MarkupLMForTokenClassification,
               "zero-shot": MarkupLMForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )





       def 		lowerCAmelCase	(  self				:     int   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     int   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     List[str]			):


             '''simple docstring'''



             return True





       def 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    MarkupLMModelTester(self			)
             lowerCamelCase__						:							Any       =    ConfigTester(self   , config_class=__lowerCamelCase   , hidden_size=37			)





       def 		lowerCAmelCase	(  self				:     Dict			):


             '''simple docstring'''



             self.config_tester.run_common_tests()





       def 		lowerCAmelCase	(  self				:     List[Any]			):


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     int			):


             '''simple docstring'''



             lowerCamelCase__						:							Dict       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     Tuple			):


             '''simple docstring'''



             lowerCamelCase__						:							Optional[Any]       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     List[Any]			):


             '''simple docstring'''



             lowerCamelCase__						:							List[Any]       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase			)



def  lowercase_						(						):

      """simple docstring"""




      lowerCamelCase__						:							int       =    "\n    <!DOCTYPE html>\n    <html>\n    <head>\n    <title>Page Title</title>\n    </head>\n    <body>\n\n    <h1>This is a Heading</h1>\n    <p>This is a paragraph.</p>\n\n    </body>\n    </html>\n    "

      return html_string







@require_torch
class      _lowercase					(				unittest.TestCase):


       """simple docstring"""




       @cached_property
       def 		lowerCAmelCase	(  self				:     Tuple			):


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    MarkupLMFeatureExtractor()
             lowerCamelCase__						:							Union[str, Any]       =    MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base"			)

             return MarkupLMProcessor(__lowerCamelCase   , __lowerCamelCase			)





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


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    MarkupLMModel.from_pretrained("microsoft/markuplm-base"			).to(__lowerCamelCase			)

             lowerCamelCase__						:							Dict       =    self.default_processor

             lowerCamelCase__						:							Dict       =    processor(prepare_html_string()   , return_tensors="pt"			)
             lowerCamelCase__						:							Optional[Any]       =    inputs.to(__lowerCamelCase			)

             # forward pass
             with torch.no_grad():
                   lowerCamelCase__						:							Union[str, Any]       =    model(**__lowerCamelCase			)

             # verify the last hidden states
             lowerCamelCase__						:							Dict       =    torch.Size([1, 14, 768]			)
             self.assertEqual(outputs.last_hidden_state.shape   , __lowerCamelCase			)

             lowerCamelCase__						:							Dict       =    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(__lowerCamelCase			)

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


