






"""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 	snake_case__ (							unittest.TestCase				):
	lowercase__						:					Optional[Any]											=   MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
	lowercase__						:					int											=   TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				List[Any]:
							__magic_name__      :       Dict       						= TextaTextGenerationPipeline(model=lowerCAmelCase__      ,       tokenizer=lowerCAmelCase__			)
							return generator, ["Something to write", "Something else"]
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				List[Any]:
							__magic_name__      :       List[str]       						= generator("""Something there"""			)
							self.assertEqual(lowerCAmelCase__      ,       [{"""generated_text""": ANY(lowerCAmelCase__			)}]			)
							# These are encoder decoder, they don't just append to incoming string
							self.assertFalse(outputs[0]["""generated_text"""].startswith("""Something there"""			)			)

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

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

							with self.assertRaises(lowerCAmelCase__			):
													generator(4			)
	@require_torch
	def       __magic_name__    (    self			)							->				Optional[int]:
							__magic_name__      :       str       						= pipeline("""text2text-generation"""      ,       model="""patrickvonplaten/t5-tiny-random"""      ,       framework="""pt"""			)
							# do_sample=False necessary for reproducibility
							__magic_name__      :       int       						= generator("""Something there"""      ,       do_sample=lowerCAmelCase__			)
							self.assertEqual(lowerCAmelCase__      ,       [{"""generated_text""": """"""}]			)

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

							__magic_name__      :       Tuple       						= generator("""This is a test"""      ,       do_sample=lowerCAmelCase__      ,       num_return_sequences=2      ,       return_tensors=lowerCAmelCase__			)
							self.assertEqual(
							    lowerCAmelCase__      ,       [
							        {"""generated_token_ids""": ANY(torch.Tensor			)},
							        {"""generated_token_ids""": ANY(torch.Tensor			)},
							    ]      ,       )
							__magic_name__      :       Optional[int]       						= generator.model.config.eos_token_id
							__magic_name__      :       str       						= """<pad>"""
							__magic_name__      :       List[Any]       						= generator(
							    ["""This is a test""", """This is a second test"""]      ,       do_sample=lowerCAmelCase__      ,       num_return_sequences=2      ,       batch_size=2      ,       return_tensors=lowerCAmelCase__      ,       )
							self.assertEqual(
							    lowerCAmelCase__      ,       [
							        [
							            {"""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       __magic_name__    (    self			)							->				Union[str, Any]:
							__magic_name__      :       Optional[Any]       						= pipeline("""text2text-generation"""      ,       model="""patrickvonplaten/t5-tiny-random"""      ,       framework="""tf"""			)
							# do_sample=False necessary for reproducibility
							__magic_name__      :       List[Any]       						= generator("""Something there"""      ,       do_sample=lowerCAmelCase__			)
							self.assertEqual(lowerCAmelCase__      ,       [{"""generated_text""": """"""}]			)








import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

__magic_name__:					int							=     "python tqdm regex requests packaging filelock numpy tokenizers".split()
if sys.version_info < (3, 7):
		pkgs_to_check_at_runtime.append("dataclasses")
if sys.version_info < (3, 8):
		pkgs_to_check_at_runtime.append("importlib_metadata")

for pkg in pkgs_to_check_at_runtime:
		if pkg in deps:
				if pkg == "tokenizers":
						# must be loaded here, or else tqdm check may fail
						from .utils import is_tokenizers_available

						if not is_tokenizers_available():
								continue  # not required, check version only if installed

				require_version_core(deps[pkg])
		else:
				raise ValueError(F"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")

def    UpperCamelCase						(	_A,   _A=None			):






						"""simple docstring"""







						require_version(deps[pkg],   _A			)
