code: def run_pipeline_test(self, text_generator, _):
      model = text_generator.model
      tokenizer = text_generator.tokenizer
  
      outputs = text_generator("This is a test")
      self.assertEqual(outputs, [{"generated_text": ANY(str)}])
      self.assertTrue(
          outputs[0]["generated_text"].startswith("This is a test")
      )
  
      outputs = text_generator("This is a test", return_full_text=False)
      self.assertEqual(outputs, [{"generated_text": ANY(str)}])
      self.assertNotIn("This is a test", outputs[0]["generated_text"])
  
      text_generator = pipeline(
          task="text-generation",
          model=model,
          tokenizer=tokenizer,
          return_full_text=False,
      )
      outputs = text_generator("This is a test")
      self.assertEqual(outputs, [{"generated_text": ANY(str)}])
      self.assertNotIn("This is a test", outputs[0]["generated_text"])
  
      outputs = text_generator("This is a test", return_full_text=True)
      self.assertEqual(outputs, [{"generated_text": ANY(str)}])
      self.assertTrue(
          outputs[0]["generated_text"].startswith("This is a test")
      )
  
      outputs = text_generator(
          ["This is great !", "Something else"],
          num_return_sequences=2,
          do_sample=True,
      )
      self.assertEqual(
          outputs,
          [
              [
                  {"generated_text": ANY(str)},
                  {"generated_text": ANY(str)},
              ],
              [
                  {"generated_text": ANY(str)},
                  {"generated_text": ANY(str)},
              ],
          ],
      )
  
      if text_generator.tokenizer.pad_token is not None:
          outputs = text_generator(
              ["This is great !", "Something else"],
              num_return_sequences=2,
              batch_size=2,
              do_sample=True,
          )
          self.assertEqual(
              outputs,
              [
                  [
                      {"generated_text": ANY(str)},
                      {"generated_text": ANY(str)},
                  ],
                  [
                      {"generated_text": ANY(str)},
                      {"generated_text": ANY(str)},
                  ],
              ],
          )
  
      # Empty prompt is slighly special
      # it requires BOS token to exist.
      # Special case for Pegasus which will always append EOS so will
      # work even without BOS.
      if (
          text_generator.tokenizer.bos_token_id is not None
          or "Pegasus" in tokenizer.__class__.__name__
      ):
          outputs = text_generator("")
          self.assertEqual(outputs, [{"generated_text": ANY(str)}])
      else:
          with self.assertRaises((ValueError, AssertionError)):
              outputs = text_generator("")
  
      if text_generator.framework == "tf":
          # TF generation does not support max_new_tokens, and it's impossible
          # to control long generation with only max_length without
          # fancy calculation, dismissing tests for now.
          return
      # We don't care about infinite range models.
      # They already work.
      # Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
      if (
          tokenizer.model_max_length < 10000
          and "XGLM" not in tokenizer.__class__.__name__
      ):
          # Handling of large generations
          with self.assertRaises(
              (RuntimeError, IndexError, ValueError, AssertionError)
          ):
              text_generator("This is a test" * 500, max_new_tokens=20)
  
          outputs = text_generator(
              "This is a test" * 500,
              handle_long_generation="hole",
              max_new_tokens=20,
          )
          # Hole strategy cannot work
          with self.assertRaises(ValueError):
              text_generator(
                  "This is a test" * 500,
                  handle_long_generation="hole",
                  max_new_tokens=tokenizer.model_max_length + 10,
              )
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/tests/pipelines/test_pipelines_text_generation.py
imports: import unittest
  from transformers import MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_CAUSAL_LM_MAPPING, TextGenerationPipeline, pipeline
  from transformers.testing_utils import require_accelerate, require_tf, require_torch, require_torch_gpu, require_torch_or_tf
  from .test_pipelines_common import ANY, PipelineTestCaseMeta
label_desc: Use image node_id 5 for calling the TextGenerationPipelineTests obj's underlying member method code with example usage: obj.run_pipeline_test(text_generator, _) without return types