[论文解读] Efficiently Scaling Transformer Inference
本文提出一种工程框架,用于在多个 TPU 芯片上划分大型 Transformer 模型,以优化推理延迟和 FLOPS 利用率,在 500B+ 参数模型上实现新的帕累托前沿,并通过多查询注意力实现更长的上下文。
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.
研究动机与目标
- 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.
提出的方法
- 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.
实验结果
研究问题
- 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?
主要发现
- 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.
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。