Skip to main content
QUICK REVIEW

[Paper Review] Efficiently Scaling Transformer Inference

Reiner Pope, Sholto Douglas|arXiv (Cornell University)|Nov 9, 2022
Generative Adversarial Networks and Image SynthesisComputer Science57 citations
TL;DR

The paper presents an engineering framework for partitioning large Transformer models across multiple TPU chips to optimize inference latency and FLOPS utilization, achieving a new Pareto frontier on 500B+ parameter models and enabling longer context with multiquery attention.

ABSTRACT

We study the problem of efficient generative inference for Transformer models, in one of its most challenging settings: large deep models, with tight latency targets and long sequence lengths. Better understanding of the engineering tradeoffs for inference for large Transformer-based models is important as use cases of these models are growing rapidly throughout application areas. We develop a simple analytical model for inference efficiency to select the best multi-dimensional partitioning techniques optimized for TPU v4 slices based on the application requirements. We combine these with a suite of low-level optimizations to achieve a new Pareto frontier on the latency and model FLOPS utilization (MFU) tradeoffs on 500B+ parameter models that outperforms the FasterTransformer suite of benchmarks. We further show that with appropriate partitioning, the lower memory requirements of multiquery attention (i.e. multiple query heads share single key/value head) enables scaling up to 32x larger context lengths. Finally, we achieve a low-batch-size latency of 29ms per token during generation (using int8 weight quantization) and a 76% MFU during large-batch-size processing of input tokens, while supporting a long 2048-token context length on the PaLM 540B parameter model.

Motivation & Objective

  • Develop a simple analytical model to select multi-axis partitioning strategies for large Transformer inference based on application needs.
  • Combine partitioning with memory and low-level scheduling optimizations to improve MFU and latency on 500B+ parameter models.
  • Show that multiquery attention reduces KV cache memory costs and enables longer context lengths.
  • Demonstrate a practical, configurable inference framework validated on PaLM 540B across 64 TPU v4 chips.
  • Provide guidelines for selecting partition layouts during prefill and generation phases under different workload requirements.

Proposed method

  • Define metrics: latency, throughput, and model FLOPS utilization (MFU).
  • Develop partitioning layouts including 1D/2D weight-stationary and weight-gathered schemes for feedforward layers.
  • Propose multiquery attention partitioning by batching KV cache across batch to reduce memory time.
  • Leverage parallel attention/feedforward configurations to fuse operations and reduce communication.
  • Apply low-level optimizations (Looped CollectiveEinsum, async collectives) and int8 weight quantization to improve performance.
  • Validate on PaLM 540B (64 TPU v4 chips) with context length up to 2048 tokens and 29 ms per-token latency (int8) during generation.

Experimental results

Research questions

  • RQ1How do partitioning strategies affect latency, MFU, and memory traffic for large Transformer inference?
  • RQ2What is the optimal mix of 1D/2D/weight-gathered layouts for feedforward layers at varying batch sizes and context lengths?
  • RQ3Can multiquery attention significantly reduce KV cache memory load and enable longer contexts without incurring prohibitive communication?
  • RQ4How do parallel attention/feedforward formulations impact latency and MFU compared to serialized implementations?
  • RQ5What quantization and low-level optimizations yield the best practical Pareto frontier on PaLM-scale models?

Key findings

  • A simple analytical partitioning framework can identify near-optimal multi-axis partitioning for given model size, context length, and chip count.
  • 2D weight-stationary and weight-gathered feedforward layouts switch as batch size grows, with weight-gathered layouts outperforming at large batches (up to 76% MFU).
  • Multiquery attention reduces KV cache memory by a factor of up to n_chips, enabling longer contexts (32–64x longer) than multihead setups in the reported configurations.
  • Parallel attention/feedforward formulation reduces latency and communication, increasing FLOPS utilization compared to serialized variants.
  • On PaLM 540B with 64 TPUs, prefill latency and generation throughput achieve low-batch latency of 29 ms per token (int8) and MFU of 76% under large batches, with 2048-token context.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.