KV Prediction for Improved Time to First Token

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Horton, Maxwell, Cao, Qingqing, Sun, Chenfan, Jin, Yanzi, Mehta, Sachin, Rastegari, Mohammad, Nabi, Moin
Format: Preprint
Publié: 2024
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866914969928335360
author Horton, Maxwell
Cao, Qingqing
Sun, Chenfan
Jin, Yanzi
Mehta, Sachin
Rastegari, Mohammad
Nabi, Moin
author_facet Horton, Maxwell
Cao, Qingqing
Sun, Chenfan
Jin, Yanzi
Mehta, Sachin
Rastegari, Mohammad
Nabi, Moin
contents Inference with transformer-based language models begins with a prompt processing step. In this step, the model generates the first output token and stores the KV cache needed for future generation steps. This prompt processing step can be computationally expensive, taking 10s of seconds or more for billion-parameter models on edge devices when prompt lengths or batch sizes rise. This degrades user experience by introducing significant latency into the model's outputs. To reduce the time spent producing the first output (known as the ``time to first token'', or TTFT) of a pretrained model, we introduce a novel method called KV Prediction. In our method, a small auxiliary model is used to process the prompt and produce an approximation of the KV cache used by a base model. This approximated KV cache is then used with the base model for autoregressive generation without the need to query the auxiliary model again. We demonstrate that our method produces a pareto-optimal efficiency-accuracy trade-off when compared to baselines. On TriviaQA, we demonstrate relative accuracy improvements in the range of $15\%-50\%$ across a range of TTFT FLOPs budgets. We also demonstrate accuracy improvements of up to $30\%$ on HumanEval python code completion at fixed TTFT FLOPs budgets. Additionally, we benchmark models on an Apple M2 Pro CPU and demonstrate that our improvement in FLOPs translates to a TTFT speedup on hardware. We release our code at https://github.com/apple/corenet/tree/main/projects/kv-prediction .
format Preprint
id arxiv_https___arxiv_org_abs_2410_08391
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle KV Prediction for Improved Time to First Token
Horton, Maxwell
Cao, Qingqing
Sun, Chenfan
Jin, Yanzi
Mehta, Sachin
Rastegari, Mohammad
Nabi, Moin
Computation and Language
Artificial Intelligence
Inference with transformer-based language models begins with a prompt processing step. In this step, the model generates the first output token and stores the KV cache needed for future generation steps. This prompt processing step can be computationally expensive, taking 10s of seconds or more for billion-parameter models on edge devices when prompt lengths or batch sizes rise. This degrades user experience by introducing significant latency into the model's outputs. To reduce the time spent producing the first output (known as the ``time to first token'', or TTFT) of a pretrained model, we introduce a novel method called KV Prediction. In our method, a small auxiliary model is used to process the prompt and produce an approximation of the KV cache used by a base model. This approximated KV cache is then used with the base model for autoregressive generation without the need to query the auxiliary model again. We demonstrate that our method produces a pareto-optimal efficiency-accuracy trade-off when compared to baselines. On TriviaQA, we demonstrate relative accuracy improvements in the range of $15\%-50\%$ across a range of TTFT FLOPs budgets. We also demonstrate accuracy improvements of up to $30\%$ on HumanEval python code completion at fixed TTFT FLOPs budgets. Additionally, we benchmark models on an Apple M2 Pro CPU and demonstrate that our improvement in FLOPs translates to a TTFT speedup on hardware. We release our code at https://github.com/apple/corenet/tree/main/projects/kv-prediction .
title KV Prediction for Improved Time to First Token
topic Computation and Language
Artificial Intelligence
url https://arxiv.org/abs/2410.08391