






import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
 import torch



@is_pipeline_test
class 							_UpperCamelCase			(unittest.TestCase			):
      snake_case_  =							MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
      snake_case_  =							TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	str:
           __lowerCAmelCase								=					TextaTextGenerationPipeline(model=__UpperCamelCase					,						tokenizer=__UpperCamelCase	)
           return generator, ["Something to write", "Something else"]


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase	)->	str:
           __lowerCAmelCase								=					generator("Something there"	)
           self.assertEqual(__UpperCamelCase					,						[{"generated_text": ANY(__UpperCamelCase	)}]	)
           # These are encoder decoder, they don't just append to incoming string
           self.assertFalse(outputs[0]["generated_text"].startswith("Something there"	)	)

           __lowerCAmelCase								=					generator(["This is great !", "Something else"]					,						num_return_sequences=2					,						do_sample=__UpperCamelCase	)
           self.assertEqual(
               __UpperCamelCase					,						[
                   [{"generated_text": ANY(__UpperCamelCase	)}, {"generated_text": ANY(__UpperCamelCase	)}],
                   [{"generated_text": ANY(__UpperCamelCase	)}, {"generated_text": ANY(__UpperCamelCase	)}],
               ]					,						)

           __lowerCAmelCase								=					generator(
               ["This is great !", "Something else"]					,						num_return_sequences=2					,						batch_size=2					,						do_sample=__UpperCamelCase	)
           self.assertEqual(
               __UpperCamelCase					,						[
                   [{"generated_text": ANY(__UpperCamelCase	)}, {"generated_text": ANY(__UpperCamelCase	)}],
                   [{"generated_text": ANY(__UpperCamelCase	)}, {"generated_text": ANY(__UpperCamelCase	)}],
               ]					,						)

           with self.assertRaises(__UpperCamelCase	):
                generator(4	)


      @require_torch
      def  __UpperCAmelCase		(	self	)->	List[Any]:
           __lowerCAmelCase								=					pipeline("text2text-generation"					,						model="patrickvonplaten/t5-tiny-random"					,						framework="pt"	)
           # do_sample=False necessary for reproducibility
           __lowerCAmelCase								=					generator("Something there"					,						do_sample=__UpperCamelCase	)
           self.assertEqual(__UpperCamelCase					,						[{"generated_text": ""}]	)

           __lowerCAmelCase								=					3
           __lowerCAmelCase								=					generator(
               "Something there"					,						num_return_sequences=__UpperCamelCase					,						num_beams=__UpperCamelCase					,						)
           __lowerCAmelCase								=					[
               {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide Beide"},
               {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide"},
               {"generated_text": ""},
           ]
           self.assertEqual(__UpperCamelCase					,						__UpperCamelCase	)

           __lowerCAmelCase								=					generator("This is a test"					,						do_sample=__UpperCamelCase					,						num_return_sequences=2					,						return_tensors=__UpperCamelCase	)
           self.assertEqual(
               __UpperCamelCase					,						[
                   {"generated_token_ids": ANY(torch.Tensor	)},
                   {"generated_token_ids": ANY(torch.Tensor	)},
               ]					,						)
           __lowerCAmelCase								=					generator.model.config.eos_token_id
           __lowerCAmelCase								=					"<pad>"
           __lowerCAmelCase								=					generator(
               ["This is a test", "This is a second test"]					,						do_sample=__UpperCamelCase					,						num_return_sequences=2					,						batch_size=2					,						return_tensors=__UpperCamelCase					,						)
           self.assertEqual(
               __UpperCamelCase					,						[
                   [
                       {"generated_token_ids": ANY(torch.Tensor	)},
                       {"generated_token_ids": ANY(torch.Tensor	)},
                   ],
                   [
                       {"generated_token_ids": ANY(torch.Tensor	)},
                       {"generated_token_ids": ANY(torch.Tensor	)},
                   ],
               ]					,						)


      @require_tf
      def  __UpperCAmelCase		(	self	)->	Union[str, Any]:
           __lowerCAmelCase								=					pipeline("text2text-generation"					,						model="patrickvonplaten/t5-tiny-random"					,						framework="tf"	)
           # do_sample=False necessary for reproducibility
           __lowerCAmelCase								=					generator("Something there"					,						do_sample=__UpperCamelCase	)
           self.assertEqual(__UpperCamelCase					,						[{"generated_text": ""}]	)














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


lowerCamelCase			:					Any         =	logging.get_logger(__name__)

lowerCamelCase			:					Dict         =	{
    '''microsoft/markuplm-base''': '''https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json''',
    '''microsoft/markuplm-large''': '''https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json''',
}



class 							_UpperCamelCase			(a_			):
      snake_case_  =							"""markuplm"""


      def __init__(	self					,						__UpperCamelCase=3_0_5_2_2					,						__UpperCamelCase=7_6_8					,						__UpperCamelCase=1_2					,						__UpperCamelCase=1_2					,						__UpperCamelCase=3_0_7_2					,						__UpperCamelCase="gelu"					,						__UpperCamelCase=0.1					,						__UpperCamelCase=0.1					,						__UpperCamelCase=5_1_2					,						__UpperCamelCase=2					,						__UpperCamelCase=0.0_2					,						__UpperCamelCase=1e-12					,						__UpperCamelCase=0					,						__UpperCamelCase=0					,						__UpperCamelCase=2					,						__UpperCamelCase=2_5_6					,						__UpperCamelCase=1_0_2_4					,						__UpperCamelCase=2_1_6					,						__UpperCamelCase=1_0_0_1					,						__UpperCamelCase=3_2					,						__UpperCamelCase=5_0					,						__UpperCamelCase="absolute"					,						__UpperCamelCase=True					,						__UpperCamelCase=None					,						**__UpperCamelCase					,						)->	Dict:
           super().__init__(
               pad_token_id=__UpperCamelCase					,						bos_token_id=__UpperCamelCase					,						eos_token_id=__UpperCamelCase					,						**__UpperCamelCase					,						)
           __lowerCAmelCase								=					vocab_size
           __lowerCAmelCase								=					hidden_size
           __lowerCAmelCase								=					num_hidden_layers
           __lowerCAmelCase								=					num_attention_heads
           __lowerCAmelCase								=					hidden_act
           __lowerCAmelCase								=					intermediate_size
           __lowerCAmelCase								=					hidden_dropout_prob
           __lowerCAmelCase								=					attention_probs_dropout_prob
           __lowerCAmelCase								=					max_position_embeddings
           __lowerCAmelCase								=					type_vocab_size
           __lowerCAmelCase								=					initializer_range
           __lowerCAmelCase								=					layer_norm_eps
           __lowerCAmelCase								=					position_embedding_type
           __lowerCAmelCase								=					use_cache
           __lowerCAmelCase								=					classifier_dropout
           # additional properties
           __lowerCAmelCase								=					max_depth
           __lowerCAmelCase								=					max_xpath_tag_unit_embeddings
           __lowerCAmelCase								=					max_xpath_subs_unit_embeddings
           __lowerCAmelCase								=					tag_pad_id
           __lowerCAmelCase								=					subs_pad_id
           __lowerCAmelCase								=					xpath_unit_hidden_size






