


'''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 					lowercase_     (    unittest.TestCase   ):
    __UpperCAmelCase   			=	MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
    __UpperCAmelCase   			=	TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


    def    __a							(     self  ,					a  ,					a  ,					a    ):
          UpperCamelCase__										=				TextaTextGenerationPipeline(model=a  ,					tokenizer=a    )
          return generator, ["Something to write", "Something else"]


    def    __a							(     self  ,					a  ,					a    ):
          UpperCamelCase__										=				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"    )    )

          UpperCamelCase__										=				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    )}],
              ]  ,					)

          UpperCamelCase__										=				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    __a							(     self    ):
          UpperCamelCase__										=				pipeline("text2text-generation"  ,					model="patrickvonplaten/t5-tiny-random"  ,					framework="pt"    )
          # do_sample=False necessary for reproducibility
          UpperCamelCase__										=				generator("Something there"  ,					do_sample=a    )
          self.assertEqual(a  ,					[{"generated_text": ""}]    )

          UpperCamelCase__										=				3
          UpperCamelCase__										=				generator(
              "Something there"  ,					num_return_sequences=a  ,					num_beams=a  ,					)
          UpperCamelCase__										=				[
              {"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    )

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






'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__a: Dict          =   {
    """configuration_ctrl""": ["""CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP""", """CTRLConfig"""],
    """tokenization_ctrl""": ["""CTRLTokenizer"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __a: int          =   [
      """CTRL_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """CTRLForSequenceClassification""",
      """CTRLLMHeadModel""",
      """CTRLModel""",
      """CTRLPreTrainedModel""",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __a: int          =   [
      """TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """TFCTRLForSequenceClassification""",
      """TFCTRLLMHeadModel""",
      """TFCTRLModel""",
      """TFCTRLPreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
  from .tokenization_ctrl import CTRLTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_ctrl import (
        CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
        CTRLForSequenceClassification,
        CTRLLMHeadModel,
        CTRLModel,
        CTRLPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_ctrl import (
        TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFCTRLForSequenceClassification,
        TFCTRLLMHeadModel,
        TFCTRLModel,
        TFCTRLPreTrainedModel,
    )

else:
  import sys

  __a: Dict          =   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

