
'''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 UpperCAmelCase__	( unittest.TestCase	):





  """simple docstring"""

  __UpperCAmelCase				:				int   =					MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
  __UpperCAmelCase				:				int   =					TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


  def   __lowercase		(		self      :     Any							,_a      :     Any							,_a      :     List[str]							,_a      :     str       ):


     '''simple docstring'''






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


  def   __lowercase		(		self      :     int							,_a      :     int							,_a      :     Optional[Any]       ):


     '''simple docstring'''






     _a				:	Dict			=   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'       )       )

     _a				:	List[str]			=   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       )}],
         ]							,)

     _a				:	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   __lowercase		(		self      :     Optional[int]       ):


     '''simple docstring'''






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

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

     _a				:	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       )},
         ]							,)
     _a				:	List[Any]			=   generator.model.config.eos_token_id
     _a				:	Optional[Any]			=   '<pad>'
     _a				:	List[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   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






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





'''simple docstring'''







import os

from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE, hf_cache_home


__lowerCAmelCase         =    HUGGINGFACE_HUB_CACHE


__lowerCAmelCase         =    """config.json"""
__lowerCAmelCase         =    """diffusion_pytorch_model.bin"""
__lowerCAmelCase         =    """diffusion_flax_model.msgpack"""
__lowerCAmelCase         =    """model.onnx"""
__lowerCAmelCase         =    """diffusion_pytorch_model.safetensors"""
__lowerCAmelCase         =    """weights.pb"""
__lowerCAmelCase         =    """https://huggingface.co"""
__lowerCAmelCase         =    default_cache_path
__lowerCAmelCase         =    """diffusers_modules"""
__lowerCAmelCase         =    os.getenv("""HF_MODULES_CACHE""", os.path.join(hf_cache_home, """modules"""))
__lowerCAmelCase         =    ["""fp16""", """non-ema"""]
__lowerCAmelCase         =    """.self_attn"""



