



'''simple docstring'''






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


UpperCamelCase__:   List[Any]								=			logging.get_logger(__name__)

UpperCamelCase__:   List[Any]								=			{
    "unc-nlp/lxmert-base-uncased": "https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json",
}

class 				SCREAMING_SNAKE_CASE(							A__			):







	"""simple docstring"""






	lowerCamelCase__			 =       """lxmert"""
	lowerCamelCase__			 =       {}







	def __init__(						self			:     Tuple		,			__snake_case			:     int=30522		,			__snake_case			:     Union[str, Any]=768		,			__snake_case			:     List[str]=12		,			__snake_case			:     Any=9500		,			__snake_case			:     int=1600		,			__snake_case			:     Any=400		,			__snake_case			:     Dict=3072		,			__snake_case			:     int="gelu"		,			__snake_case			:     List[Any]=0.1		,			__snake_case			:     Any=0.1		,			__snake_case			:     Optional[Any]=512		,			__snake_case			:     str=2		,			__snake_case			:     Optional[Any]=0.02		,			__snake_case			:     Optional[Any]=1E-12		,			__snake_case			:     Dict=9		,			__snake_case			:     Any=5		,			__snake_case			:     int=5		,			__snake_case			:     Tuple=2048		,			__snake_case			:     Union[str, Any]=4		,			__snake_case			:     Optional[Any]=6.67		,			__snake_case			:     Optional[int]=True		,			__snake_case			:     str=True		,			__snake_case			:     List[Any]=True		,			__snake_case			:     List[Any]=True		,			__snake_case			:     int=True		,			__snake_case			:     Dict=True		,			__snake_case			:     int=True		,			**__snake_case			:     int		,			)			->		Optional[int]:
								UpperCAmelCase :       List[str] 							=		vocab_size
								UpperCAmelCase :       Optional[Any] 							=		hidden_size
								UpperCAmelCase :       Tuple 							=		num_attention_heads
								UpperCAmelCase :       List[str] 							=		hidden_act
								UpperCAmelCase :       Optional[Any] 							=		intermediate_size
								UpperCAmelCase :       Tuple 							=		hidden_dropout_prob
								UpperCAmelCase :       Dict 							=		attention_probs_dropout_prob
								UpperCAmelCase :       Tuple 							=		max_position_embeddings
								UpperCAmelCase :       str 							=		type_vocab_size
								UpperCAmelCase :       Dict 							=		initializer_range
								UpperCAmelCase :       List[Any] 							=		layer_norm_eps
								UpperCAmelCase :       List[Any] 							=		num_qa_labels
								UpperCAmelCase :       Optional[Any] 							=		num_object_labels
								UpperCAmelCase :       Optional[int] 							=		num_attr_labels
								UpperCAmelCase :       List[Any] 							=		l_layers
								UpperCAmelCase :       Optional[Any] 							=		x_layers
								UpperCAmelCase :       Optional[Any] 							=		r_layers
								UpperCAmelCase :       Union[str, Any] 							=		visual_feat_dim
								UpperCAmelCase :       Dict 							=		visual_pos_dim
								UpperCAmelCase :       Optional[int] 							=		visual_loss_normalizer
								UpperCAmelCase :       Any 							=		task_matched
								UpperCAmelCase :       List[Any] 							=		task_mask_lm
								UpperCAmelCase :       List[str] 							=		task_obj_predict
								UpperCAmelCase :       List[Any] 							=		task_qa
								UpperCAmelCase :       Any 							=		visual_obj_loss
								UpperCAmelCase :       Any 							=		visual_attr_loss
								UpperCAmelCase :       Dict 							=		visual_feat_loss
								UpperCAmelCase :       Union[str, Any] 							=		{'''vision''': r_layers, '''cross_encoder''': x_layers, '''language''': l_layers}
								super().__init__(**__snake_case		)







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


  '''simple docstring'''







  a__           =		MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
  a__           =		TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
  def 							_lowercase							( self			: str			,							UpperCamelCase__			: Optional[int]			,							UpperCamelCase__			: int			,							UpperCamelCase__			: int    )			->	Tuple:







    """simple docstring"""






    __magic_name__				     =       TextaTextGenerationPipeline(model=UpperCamelCase__			,							tokenizer=UpperCamelCase__    )
    return generator, ["Something to write", "Something else"]
  def 							_lowercase							( self			: Any			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: List[str]    )			->	Optional[Any]:







    """simple docstring"""






    __magic_name__				     =       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"""    )    )

    __magic_name__				     =       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__    )}],
        ]			,							)

    __magic_name__				     =       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 							_lowercase							( self			: Optional[int]    )			->	Union[str, Any]:







    """simple docstring"""






    __magic_name__				     =       pipeline("""text2text-generation"""			,							model="""patrickvonplaten/t5-tiny-random"""			,							framework="""pt"""    )
    # do_sample=False necessary for reproducibility
    __magic_name__				     =       generator("""Something there"""			,							do_sample=UpperCamelCase__    )
    self.assertEqual(UpperCamelCase__			,							[{"""generated_text""": """"""}]    )

    __magic_name__				     =       3
    __magic_name__				     =       generator(
        """Something there"""			,							num_return_sequences=UpperCamelCase__			,							num_beams=UpperCamelCase__			,							)
    __magic_name__				     =       [
        {"""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__    )

    __magic_name__				     =       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    )},
        ]			,							)
    __magic_name__				     =       generator.model.config.eos_token_id
    __magic_name__				     =       """<pad>"""
    __magic_name__				     =       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 							_lowercase							( self			: int    )			->	str:







    """simple docstring"""






    __magic_name__				     =       pipeline("""text2text-generation"""			,							model="""patrickvonplaten/t5-tiny-random"""			,							framework="""tf"""    )
    # do_sample=False necessary for reproducibility
    __magic_name__				     =       generator("""Something there"""			,							do_sample=UpperCamelCase__    )
    self.assertEqual(UpperCamelCase__			,							[{"""generated_text""": """"""}]    )

