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

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

TL;DR

This paper introduces a "self-aware" inference pipeline where Large Language Models (LLMs) predict the length of their own responses before generating them. By grouping queries with similar predicted lengths into optimized micro-batches, the researchers achieved a staggering 86% increase in inference throughput without sacrificing the quality of the model's output.

The Problem: Redundant Computation in Batching

LLM inference is notoriously expensive and computationally intensive. To improve efficiency, engineers typically use "batching"—processing multiple queries simultaneously to saturate the GPU's parallel processing power.

However, standard batching has a major flaw: redundant computation. In a typical batch, the GPU must continue processing until the longest sequence in that batch is finished. If one query requires a 500-token response and five others only need 10 tokens, the shorter queries are forced to "wait." This results in the GPU performing useless calculations for padding tokens. The authors found that in vanilla batching, redundant tokens can account for as much as 66% of the total computation.

Comparison of standard batching with redundant computation versus the proposed sequence scheduling pipeline.

Proposed Methods

The authors propose an LLM-empowered pipeline that treats response length as a predictable variable. Their method consists of three main stages:

  1. Response Length Perception: The researchers discovered that instruction-tuned models (like GPT-4 or Vicuna) possess an innate ability to estimate how long their answers will be. They explored Perception in Advance (PiA), where the model is prompted to output a length estimate before generating the actual response. For smaller models, they used Instruction Tuning (via LoRA) to specifically train them to predict token counts with high accuracy.
  2. Sequence Scheduling: Instead of processing queries in the order they arrive, the system groups queries with similar predicted lengths into micro-batches.
  3. Efficiency Boosters:
    • Variable Batch Size (VBS): Since shorter responses consume less memory, the system dynamically increases the batch size for shorter predicted sequences, further maximizing GPU utilization.
  4. Failure Collection and Recomputation (FCR): If a model's prediction is too short and the response exceeds the predicted limit, the system halts that specific generation and moves it to a "failure queue" to be re-processed later. This prevents a single "wrong" prediction from holding up an entire batch of short sequences.

Datasets Used

The study utilized two primary datasets for training and evaluation:

  • Alpaca: A subset of 10,000 instructions was used to train the length predictor and evaluate performance.
  • Instruction-in-Wild: A set of 429 real-world prompts used to test the system's robustness on diverse, uncurated user queries.

Key Insights

  • LLMs are "Self-Aware" of Complexity: One of the most fascinating findings is that LLMs have a "global" understanding of a task before they begin. Just as a human knows a request for a "history of the French Revolution" will be longer than "what is the capital of France," LLMs can perceive this complexity and quantify it.
  • Words vs. Tokens: Interestingly, out-of-the-box LLMs are better at estimating response length in words rather than tokens. However, they can be easily tuned to understand tokens, which is the metric that actually matters for GPU scheduling.
  • Predicting the "Max" is Safer than the "Mean": When tuning the models, it is more effective to predict the maximum potential length across multiple samples rather than the average. This minimizes the "failure" rate where a model exceeds its allocated slot in a batch.
  • Orthogonality: This method doesn't replace existing optimizations like FlashAttention or Quantization; it sits on top of them. It optimizes how we batch, regardless of how the underlying kernels are computed.

Key Results

  • 86% Throughput Increase: On the Vicuna-7B model, the proposed sequence scheduling improved inference throughput by 86% compared to vanilla batching.
  • Reduced Latency: By using the FCR mechanism, the system reduced the average waiting time for users by 63%.
Throughput improvements across different batch and group sizes using the proposed scheduling method.
  • High Accuracy: The instruction-tuned Vicuna-7B achieved an "Acc-100" (prediction within 100 tokens of the actual length) of 81%, which was sufficient to drive significant scheduling gains.
  • Minimal Overhead: The time taken for the model to predict its own response length is negligible—typically requiring the generation of only 2 to 3 tokens—which is easily offset by the massive gains in batch efficiency.

Limitations and Future Work

While the results are impressive, the authors acknowledge a few hurdles:

  • Prediction Uncertainty: Length prediction isn't perfect. While the FCR strategy mitigates the impact of under-predictions, very frequent mispredictions could erode throughput gains.
  • Input Length Neglect: The current work focuses primarily on output length. As LLMs support increasingly large context windows (32k to 100k+ tokens), the computational cost of processing long inputs will also need to be addressed in scheduling.
  • Closed-Source Constraints: Implementing the full pipeline on closed-source models like GPT-4 is difficult because users don't have control over the batching or KV-cache management of the underlying API.

The authors suggest that future work could explore "software-hardware co-design," where the model's internal states are used even more directly to manage hardware resources.

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