Response Length Perception and Sequence Scheduling: An LLM-Empowered LLM Inference Pipeline

Zangwei Zheng, Xiaozhe Ren, Fuzhao Xue, Yang Luo, Xin Jiang, Yang You

Abstract

Large language models (LLMs) have revolutionized the field of AI, demonstrating unprecedented capacity across various tasks. However, the inference process for LLMs comes with significant computational costs. In this paper, we propose an efficient LLM inference pipeline that harnesses the power of LLMs. Our approach begins by tapping into the potential of LLMs to accurately perceive and predict the response length with minimal overhead. By leveraging this information, we introduce an efficient sequence scheduling technique that groups queries with similar response lengths into micro-batches. We evaluate our approach on real-world instruction datasets using the LLaMA-based model, and our results demonstrate an impressive 86% improvement in inference throughput without compromising effectiveness. Notably, our method is orthogonal to other inference acceleration techniques, making it a valuable addition to many existing toolkits (e.g., FlashAttention, Quantization) for LLM inference.

Introduction

Large Language Models (LLMs) are notoriously expensive to deploy. While batching multiple queries is the standard approach to improve efficiency, it is severely hampered by response length variability. In a standard batch, the GPU must continue processing until the longest sequence in that batch is finished. Shorter sequences sit idle, generating "redundant tokens" or padding while waiting for the longest response to complete. Research indicates that in vanilla batching, these redundant tokens can account for a staggering 66% of total computation.

Distribution of response lengths for ChatGPT and Vicuna, showing significant variability across data points.

This inefficiency is a massive bottleneck because self-attention complexity grows quadratically with sequence length. We propose an inference pipeline that leverages the "self-awareness" of LLMs—their ability to predict their own response lengths—to optimize hardware scheduling and reduce waste.

Methodology: The LLM-Empowered Pipeline

Our approach consists of two primary stages: Response Length Perception and Sequence Scheduling.

1. Response Length Perception

Instruction-tuned models like GPT-4 or Vicuna possess an inherent ability to estimate their response length. We explored two methods to harness this:

  • Perception in Advance (PiA): Prompting the model to predict its response length in the first line of its output.
  • Instruction Tuning: Fine-tuning smaller models (e.g., Vicuna-7B) to output only a numerical length prediction for a given prompt, avoiding potential side effects like response truncation.

2. Sequence Scheduling

With predicted lengths in hand, the system organizes the workload through three key mechanisms:

  • Binning: Rounding predicted lengths to the nearest "bin" (e.g., 50-token increments) to provide a buffer for prediction errors.
  • Variable Batch Size (VBS): Using larger batch sizes for shorter bins and smaller batches for longer ones to maximize GPU utilization.
  • Failure Collection and Recomputation (FCR): If a response exceeds its predicted length, it is cut off and re-scheduled in a later batch. This prevents a single under-predicted "long" response from stalling an entire batch of "short" ones.
Comparison between vanilla batching (left) and the proposed LLM-empowered pipeline (right), highlighting the reduction in redundant computation.

Experimental Results

We evaluated the pipeline using the Alpaca dataset and the Instruction-in-Wild set. Key findings include:

  • Throughput Gains: The pipeline achieved an 86% increase in throughput on Vicuna-7B compared to vanilla batching.
  • Efficiency: Redundant computation (padding tokens) dropped from 66% in the baseline to just 15% using our method.
  • Prediction Accuracy: Instruction-tuned Vicuna-7B reached 81% accuracy (within a 100-word margin) for length prediction.
  • Orthogonality: The method is orthogonal to other popular acceleration techniques like FlashAttention or Quantization, meaning it can be stacked for even greater gains.

Insights and Future Work

Our research suggests that LLMs maintain an "internal plan" of task complexity before generation begins. Interestingly, they are better at predicting word counts than token counts, suggesting their internal planning aligns more with human linguistic concepts than sub-word tokenization.

While effective, the method introduces a small prediction overhead. Future work will focus on optimizing KV-cache management for the FCR stage—potentially offloading or compressing the cache to speed up recomputation—and extending the system to handle variability in input prompt lengths.

Summary updated

BibTeX
@inproceedings{zheng2023response,
  author = {Zangwei Zheng and Xiaozhe Ren and Fuzhao Xue and Yang Luo and Xin Jiang and Yang You},
  title = {{Response Length Perception and Sequence Scheduling: An LLM-Empowered LLM Inference Pipeline}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=eW233GDOpm},
}
Figure