class_docstr: Language generation pipeline using any `ModelWithLMHead`. This pipeline predicts the words that will follow a
  specified text prompt.
  
  Example:
  
  ```python
  >>> from transformers import pipeline
  
  >>> generator = pipeline(model="gpt2")
  >>> generator("I can't believe you did such a ", do_sample=False)
  [{'generated_text': "I can't believe you did such a icky thing to me. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I"}]
  
  >>> # These parameters will return suggestions, and only the newly created text making it easier for prompting suggestions.
  >>> outputs = generator("My tart needs some", num_return_sequences=4, return_full_text=False)
  ```
  
  Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial). You can pass text
  generation parameters to this pipeline to control stopping criteria, decoding strategy, and more. Learn more about
  text generation parameters in [Text generation strategies](../generation_strategies) and [Text
  generation](text_generation).
  
  This language generation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
  `"text-generation"`.
  
  The models that this pipeline can use are models that have been trained with an autoregressive language modeling
  objective, which includes the uni-directional models in the library (e.g. gpt2). See the list of available models
  on [huggingface.co/models](https://huggingface.co/models?filter=text-generation).
class_docstr_tok: ["Language","generation","pipeline","using","any","`","ModelWithLMHead","`",".","This","pipeline","predicts","the","words","that","will","follow","a","specified","text","prompt",".","Example",":","``","`","python",">",">",">","from","transformers","import","pipeline",">",">",">","generator","=","pipeline","(","model=","''","gpt2","''",")",">",">",">","generator","(","``","I","ca","n't","believe","you","did","such","a","``",",","do_sample=False",")","[","{","'generated_text","'",":","``","I","ca","n't","believe","you","did","such","a","icky","thing","to","me",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","''","}","]",">",">",">","#","These","parameters","will","return","suggestions",",","and","only","the","newly","created","text","making","it","easier","for","prompting","suggestions",".",">",">",">","outputs","=","generator","(","``","My","tart","needs","some","''",",","num_return_sequences=4",",","return_full_text=False",")","``","`","Learn","more","about","the","basics","of","using","a","pipeline","in","the","[","pipeline","tutorial","]","(","..","\/pipeline_tutorial",")",".","You","can","pass","text","generation","parameters","to","this","pipeline","to","control","stopping","criteria",",","decoding","strategy",",","and","more",".","Learn","more","about","text","generation","parameters","in","[","Text","generation","strategies","]","(","..","\/generation_strategies",")","and","[","Text","generation","]","(","text_generation",")",".","This","language","generation","pipeline","can","currently","be","loaded","from","[","`","pipeline","`","]","using","the","following","task","identifier",":","`","``","text-generation","''","`",".","The","models","that","this","pipeline","can","use","are","models","that","have","been","trained","with","an","autoregressive","language","modeling","objective",",","which","includes","the","uni-directional","models","in","the","library","(","e.g",".","gpt2",")",".","See","the","list","of","available","models","on","[","huggingface.co\/models","]","(","https",":","\/\/huggingface.co\/models","?","filter=text-generation",")","."]
code: def _forward(self, model_inputs, **generate_kwargs):
      input_ids = model_inputs["input_ids"]
      attention_mask = model_inputs.get("attention_mask", None)
      # Allow empty prompts
      if input_ids.shape[1] == 0:
          input_ids = None
          attention_mask = None
          in_b = 1
      else:
          in_b = input_ids.shape[0]
      prompt_text = model_inputs.pop("prompt_text")
  
      # If there is a prefix, we may need to adjust the generation length. Do so without permanently modifying
      # generate_kwargs, as some of the parameterization may come from the initialization of the pipeline.
      prefix_length = generate_kwargs.pop("prefix_length", 0)
      if prefix_length > 0:
          has_max_new_tokens = "max_new_tokens" in generate_kwargs or (
              "generation_config" in generate_kwargs
              and generate_kwargs["generation_config"].max_new_tokens
              is not None
          )
          if not has_max_new_tokens:
              generate_kwargs["max_length"] = (
                  generate_kwargs.get("max_length")
                  or self.model.config.max_length
              )
              generate_kwargs["max_length"] += prefix_length
          has_min_new_tokens = "min_new_tokens" in generate_kwargs or (
              "generation_config" in generate_kwargs
              and generate_kwargs["generation_config"].min_new_tokens
              is not None
          )
          if not has_min_new_tokens and "min_length" in generate_kwargs:
              generate_kwargs["min_length"] += prefix_length
  
      # BS x SL
      generated_sequence = self.model.generate(
          input_ids=input_ids,
          attention_mask=attention_mask,
          **generate_kwargs,
      )
      out_b = generated_sequence.shape[0]
      if self.framework == "pt":
          generated_sequence = generated_sequence.reshape(
              in_b, out_b // in_b, *generated_sequence.shape[1:]
          )
      elif self.framework == "tf":
          generated_sequence = tf.reshape(
              generated_sequence,
              (in_b, out_b // in_b, *generated_sequence.shape[1:]),
          )
      return {
          "generated_sequence": generated_sequence,
          "input_ids": input_ids,
          "prompt_text": prompt_text,
      }
  
file_path: transformers/src/transformers/pipelines/text_generation.py
imports: import enum
  import warnings
  from ..utils import add_end_docstrings, is_tf_available, is_torch_available
  from .base import PIPELINE_INIT_ARGS, Pipeline
label_desc: Use image node_id 6 for calling the TextGenerationPipeline obj's underlying member method code with example usage: obj._forward(model_inputs) and returns: dict