





'''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"""






     snake_case_						      =   MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
     snake_case_						      =   TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING



     def      lowerCAmelCase			(   self							:			Tuple   ,       __snake_case							:			str   ,       __snake_case							:			List[Any]   ,       __snake_case							:			List[Any]						)->	Tuple:
        snake_case 						=   TextaTextGenerationPipeline(model=__snake_case   ,       tokenizer=__snake_case						)
        return generator, ["Something to write", "Something else"]



     def      lowerCAmelCase			(   self							:			List[str]   ,       __snake_case							:			Union[str, Any]   ,       __snake_case							:			str						)->	Optional[int]:
        snake_case 						=   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 						=   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 						=   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      lowerCAmelCase			(   self							:			str						)->	Optional[int]:
        snake_case 						=   pipeline("""text2text-generation"""   ,       model="""patrickvonplaten/t5-tiny-random"""   ,       framework="""pt"""						)
        # do_sample=False necessary for reproducibility
        snake_case 						=   generator("""Something there"""   ,       do_sample=__snake_case						)
        self.assertEqual(__snake_case   ,       [{"""generated_text""": """"""}]						)

        snake_case 						=   3
        snake_case 						=   generator(
            """Something there"""   ,       num_return_sequences=__snake_case   ,       num_beams=__snake_case   ,       )
        snake_case 						=   [
            {"""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 						=   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 						=   generator.model.config.eos_token_id
        snake_case 						=   """<pad>"""
        snake_case 						=   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      lowerCAmelCase			(   self							:			Any						)->	Tuple:
        snake_case 						=   pipeline("""text2text-generation"""   ,       model="""patrickvonplaten/t5-tiny-random"""   ,       framework="""tf"""						)
        # do_sample=False necessary for reproducibility
        snake_case 						=   generator("""Something there"""   ,       do_sample=__snake_case						)
        self.assertEqual(__snake_case   ,       [{"""generated_text""": """"""}]						)








'''simple docstring'''




from ..utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
)


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 from ..utils.dummy_pt_objects import *  # noqa F403
else:
 from .scheduling_consistency_models import CMStochasticIterativeScheduler
 from .scheduling_ddim import DDIMScheduler
 from .scheduling_ddim_inverse import DDIMInverseScheduler
 from .scheduling_ddim_parallel import DDIMParallelScheduler
 from .scheduling_ddpm import DDPMScheduler
 from .scheduling_ddpm_parallel import DDPMParallelScheduler
 from .scheduling_deis_multistep import DEISMultistepScheduler
 from .scheduling_dpmsolver_multistep import DPMSolverMultistepScheduler
 from .scheduling_dpmsolver_multistep_inverse import DPMSolverMultistepInverseScheduler
 from .scheduling_dpmsolver_singlestep import DPMSolverSinglestepScheduler
 from .scheduling_euler_ancestral_discrete import EulerAncestralDiscreteScheduler
 from .scheduling_euler_discrete import EulerDiscreteScheduler
 from .scheduling_heun_discrete import HeunDiscreteScheduler
 from .scheduling_ipndm import IPNDMScheduler
 from .scheduling_k_dpm_2_ancestral_discrete import KDPMaAncestralDiscreteScheduler
 from .scheduling_k_dpm_2_discrete import KDPMaDiscreteScheduler
 from .scheduling_karras_ve import KarrasVeScheduler
 from .scheduling_pndm import PNDMScheduler
 from .scheduling_repaint import RePaintScheduler
 from .scheduling_sde_ve import ScoreSdeVeScheduler
 from .scheduling_sde_vp import ScoreSdeVpScheduler
 from .scheduling_unclip import UnCLIPScheduler
 from .scheduling_unipc_multistep import UniPCMultistepScheduler
 from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
 from .scheduling_vq_diffusion import VQDiffusionScheduler

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 from ..utils.dummy_flax_objects import *  # noqa F403
else:
 from .scheduling_ddim_flax import FlaxDDIMScheduler
 from .scheduling_ddpm_flax import FlaxDDPMScheduler
 from .scheduling_dpmsolver_multistep_flax import FlaxDPMSolverMultistepScheduler
 from .scheduling_karras_ve_flax import FlaxKarrasVeScheduler
 from .scheduling_lms_discrete_flax import FlaxLMSDiscreteScheduler
 from .scheduling_pndm_flax import FlaxPNDMScheduler
 from .scheduling_sde_ve_flax import FlaxScoreSdeVeScheduler
 from .scheduling_utils_flax import (
     FlaxKarrasDiffusionSchedulers,
     FlaxSchedulerMixin,
     FlaxSchedulerOutput,
     broadcast_to_shape_from_left,
 )


try:
 if not (is_torch_available() and is_scipy_available()):
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 from ..utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
 from .scheduling_lms_discrete import LMSDiscreteScheduler

try:
 if not (is_torch_available() and is_torchsde_available()):
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 from ..utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
 from .scheduling_dpmsolver_sde import DPMSolverSDEScheduler

