Encode Once and Decode in Parallel: Efficient Transformer Decoding

Bo-Ru Lu, Nikita Haduong, Chien-Yu Lin, Hao Cheng, Noah A. Smith, Mari Ostendorf · OpenReview

Abstract

Transformer-based NLP models are powerful but have high computational costs that limit deployment. Finetuned encoder-decoder models are popular in specialized domains and can outperform larger more generalized decoder-only models, such as GPT-4. We introduce a new configuration for encoder-decoder models that improves efficiency on structured output and decomposable tasks where multiple outputs are required for a single shared input. Our method, prompt-in-decoder (PiD), encodes the input once and decodes the output in parallel, boosting both training and inference efficiency by avoiding duplicate input encoding and increasing the operational intensity of the decoding process by sharing the input key-value cache. We achieve computation reduction that roughly scales with the number of subtasks, gaining up to 4.6x speed-up over state-of-the-art models for dialogue state tracking, summarization, and question-answering tasks, with comparable or better performance.

Introduction

Transformer models are the gold standard for NLP, but their high latency and massive computational requirements make them difficult to deploy efficiently. This is especially true for decomposable tasks, where a single large input (like a long dialogue or a medical report) requires multiple specific outputs (like tracking 30 different "slots" in a conversation or summarizing four different sections of a clinical note).

The traditional approach, Prompt-in-Encoder (PiE), pairs the document with a specific prompt in the encoder. If a task has 30 subtasks, the model ends up encoding that same document 30 times. This redundancy creates a massive bottleneck in both memory access and raw floating-point operations (FLOPs). While large decoder-only models can handle these tasks, they are often overkill and more expensive than specialized encoder-decoder models like T5.

Methodology: Prompt-in-Decoder (PiD)

The core innovation of Prompt-in-Decoder (PiD) is a shift in architecture designed to eliminate redundant computation. Instead of including task-specific prompts in the encoder, PiD processes the shared input document exactly once. The task-specific prompts (the "questions" or "instructions") are moved into the decoder, allowing for parallel decoding.

Comparison of the traditional Prompt-in-encoder (PiE) and the proposed Prompt-in-decoder (PiD) architectures.

Because the encoder output is identical for every subtask, the decoder can share the Key-Value (KV) cache of the input. This significantly increases operational intensity—the ratio of arithmetic operations to memory access. In modern hardware, the bottleneck is often moving data from memory to the processor (IO). By sharing the cache, PiD ensures the processor spends more time calculating and less time waiting for data to arrive.

Cross-attention mechanisms in PiE vs PiD, illustrating how PiD shares the input key-value cache (K) across multiple queries (Q).

Experimental Evaluation

Researchers evaluated PiD by "upcycling" existing T5 models across three diverse domains:

  • MultiWoZ 2.4: Dialogue State Tracking (DST) requiring the tracking of multiple conversation "slots."
  • ACI-Bench: Clinical note generation based on doctor-patient dialogues.
  • RadQA: Extractive question-answering focused on radiology reports.

Key Results

  • Massive Speedups: PiD achieved up to a 4.6x speedup in wall-clock time for single-instance inference compared to the standard PiE approach.
  • Computational Efficiency: The method showed a 2x to 10x reduction in FLOPs, depending on the number of subtasks involved.
  • Competitive Accuracy: PiD maintained 98-101% of the performance of state-of-the-art models. In tasks like ACI-Bench summarization, it actually outperformed baselines as subtasking allowed the model to focus on shorter, more manageable sections of text.
  • Hardware Versatility: Benefits were most pronounced on consumer-grade hardware (like the RTX 2080Ti), where memory bandwidth is more limited than on enterprise-grade A100s.

Conclusion and Future Work

PiD demonstrates that simply changing where a prompt is placed can fundamentally improve the efficiency profile of an architecture. The primary limitation is that PiD is specifically designed for decomposable tasks. Future research may focus on automated subtasking, where models learn to decompose complex requests independently, and adapting these parallel decoding strategies for decoder-only architectures.

Summary updated

BibTeX
@misc{lu2024encode,
  author = {Bo-Ru Lu and Nikita Haduong and Chien-Yu Lin and Hao Cheng and Noah A. Smith and Mari Ostendorf},
  title = {{Encode Once and Decode in Parallel: Efficient Transformer Decoding}},
  year = {2024},
  eprint = {2403.13112},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.13112},
}
Figure