





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  ):
					_SCREAMING_SNAKE_CASE							   =    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
					_SCREAMING_SNAKE_CASE							   =    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		TextaTextGenerationPipeline(model=__snake_case       ,     tokenizer=__snake_case       )
											return generator, ["Something to write", "Something else"]


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Optional[Any]       ):





											'''simple docstring'''





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

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

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

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


					@require_torch
					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





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

											_snake_case:   Optional[int]  					=		3
											_snake_case:   str  					=		generator(
											    'Something there'       ,     num_return_sequences=__snake_case       ,     num_beams=__snake_case       ,     )
											_snake_case:   Dict  					=		[
											    {'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(__snake_case       ,     __snake_case       )

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





											'''simple docstring'''





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












'''simple docstring'''






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


A   : Tuple             =			logging.get_logger(__name__)

A   : Any             =			{
    'microsoft/biogpt': 'https://huggingface.co/microsoft/biogpt/resolve/main/config.json',
    # See all BioGPT models at https://huggingface.co/models?filter=biogpt
}







class 			lowerCamelCase					(						__UpperCAmelCase  ):
					_SCREAMING_SNAKE_CASE							   =    "biogpt"


					def __init__(					self	:  Union[str, Any]       ,     __snake_case	:  Tuple=4_23_84       ,     __snake_case	:  Any=10_24       ,     __snake_case	:  Optional[int]=24       ,     __snake_case	:  int=16       ,     __snake_case	:  str=40_96       ,     __snake_case	:  Dict="gelu"       ,     __snake_case	:  List[str]=0.1       ,     __snake_case	:  List[Any]=0.1       ,     __snake_case	:  List[Any]=10_24       ,     __snake_case	:  Optional[int]=0.02       ,     __snake_case	:  Union[str, Any]=1e-12       ,     __snake_case	:  List[Any]=True       ,     __snake_case	:  Union[str, Any]=True       ,     __snake_case	:  Any=0.0       ,     __snake_case	:  int=0.0       ,     __snake_case	:  Dict=1       ,     __snake_case	:  str=0       ,     __snake_case	:  List[str]=2       ,     **__snake_case	:  Optional[int]       ,     ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		vocab_size
											_snake_case:   Optional[int]  					=		max_position_embeddings
											_snake_case:   Dict  					=		hidden_size
											_snake_case:   Union[str, Any]  					=		num_hidden_layers
											_snake_case:   str  					=		num_attention_heads
											_snake_case:   Any  					=		intermediate_size
											_snake_case:   List[Any]  					=		hidden_act
											_snake_case:   int  					=		hidden_dropout_prob
											_snake_case:   List[str]  					=		attention_probs_dropout_prob
											_snake_case:   Optional[Any]  					=		initializer_range
											_snake_case:   Union[str, Any]  					=		layer_norm_eps
											_snake_case:   Dict  					=		scale_embedding
											_snake_case:   Dict  					=		use_cache
											_snake_case:   List[Any]  					=		layerdrop
											_snake_case:   int  					=		activation_dropout
											super().__init__(pad_token_id=__snake_case       ,     bos_token_id=__snake_case       ,     eos_token_id=__snake_case       ,     **__snake_case       )





