





"""simple docstring"""





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 					_lowerCAmelCase   (     unittest.TestCase       ):
       """simple docstring"""




       __magic_name__     :int		  =					MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
       __magic_name__     :Dict		  =					TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[Any]											=							TextaTextGenerationPipeline(model=__a    , tokenizer=__a      )
         return generator, ["Something to write", "Something else"]






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							generator('Something there'      )
         self.assertEqual(__a    , [{'generated_text': ANY(__a      )}]      )
         # These are encoder decoder, they don't just append to incoming string
         self.assertFalse(outputs[0]['generated_text'].startswith('Something there'      )      )

         lowerCAmelCase__			:Tuple											=							generator(['This is great !', 'Something else']    , num_return_sequences=2    , do_sample=__a      )
         self.assertEqual(
             __a    , [
                 [{'generated_text': ANY(__a      )}, {'generated_text': ANY(__a      )}],
                 [{'generated_text': ANY(__a      )}, {'generated_text': ANY(__a      )}],
             ]    , )

         lowerCAmelCase__			:Dict											=							generator(
             ['This is great !', 'Something else']    , num_return_sequences=2    , batch_size=2    , do_sample=__a      )
         self.assertEqual(
             __a    , [
                 [{'generated_text': ANY(__a      )}, {'generated_text': ANY(__a      )}],
                 [{'generated_text': ANY(__a      )}, {'generated_text': ANY(__a      )}],
             ]    , )

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






       @require_torch
       def      snake_case						(    self      ):



         '''simple docstring'''

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

         lowerCAmelCase__			:str											=							3
         lowerCAmelCase__			:Union[str, Any]											=							generator(
             'Something there'    , num_return_sequences=__a    , num_beams=__a    , )
         lowerCAmelCase__			:str											=							[
             {'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(__a    , __a      )

         lowerCAmelCase__			:Optional[Any]											=							generator('This is a test'    , do_sample=__a    , num_return_sequences=2    , return_tensors=__a      )
         self.assertEqual(
             __a    , [
                 {'generated_token_ids': ANY(torch.Tensor      )},
                 {'generated_token_ids': ANY(torch.Tensor      )},
             ]    , )
         lowerCAmelCase__			:int											=							generator.model.config.eos_token_id
         lowerCAmelCase__			:Dict											=							'<pad>'
         lowerCAmelCase__			:Optional[Any]											=							generator(
             ['This is a test', 'This is a second test']    , do_sample=__a    , num_return_sequences=2    , batch_size=2    , return_tensors=__a    , )
         self.assertEqual(
             __a    , [
                 [
                     {'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      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:str											=							pipeline('text2text-generation'    , model='patrickvonplaten/t5-tiny-random'    , framework='tf'      )
         # do_sample=False necessary for reproducibility
         lowerCAmelCase__			:List[Any]											=							generator('Something there'    , do_sample=__a      )
         self.assertEqual(__a    , [{'generated_text': ''}]      )







'''simple docstring'''







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


lowerCAmelCase_					:    Dict      	=			logging.get_logger(__name__)

lowerCAmelCase_					:    int      	=			{
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}
class 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







				__a            ='gpt_bigcode'
				__a            =['past_key_values']
				__a            ={
				    'hidden_size': 'n_embd',
				    'max_position_embeddings': 'n_positions',
				    'num_attention_heads': 'n_head',
				    'num_hidden_layers': 'n_layer',
				}




				def __init__(  self     :					Optional[Any]					,				__a     :					Tuple=5_02_57					,				__a     :					str=10_24					,				__a     :					Dict=7_68					,				__a     :					Tuple=12					,				__a     :					str=12					,				__a     :					Optional[int]=None					,				__a     :					Dict="gelu_pytorch_tanh"					,				__a     :					Tuple=0.1					,				__a     :					Tuple=0.1					,				__a     :					Union[str, Any]=0.1					,				__a     :					Tuple=1e-5					,				__a     :					str=0.02					,				__a     :					Dict=True					,				__a     :					Union[str, Any]=True					,				__a     :					Optional[int]=5_02_56					,				__a     :					Optional[int]=5_02_56					,				__a     :					Union[str, Any]=True					,				__a     :					Dict=True					,				__a     :					Union[str, Any]=True					,				**__a     :					List[Any]					,				):
								_a								= vocab_size
								_a								= n_positions
								_a								= n_embd
								_a								= n_layer
								_a								= n_head
								_a								= n_inner
								_a								= activation_function
								_a								= resid_pdrop
								_a								= embd_pdrop
								_a								= attn_pdrop
								_a								= layer_norm_epsilon
								_a								= initializer_range
								_a								= scale_attn_weights
								_a								= use_cache
								_a								= attention_softmax_in_fpaa
								_a								= scale_attention_softmax_in_fpaa
								_a								= multi_query

								_a								= bos_token_id
								_a								= eos_token_id

								super().__init__(bos_token_id=__a					,				eos_token_id=__a					,				**__a					)
