You Only Cache Once: Decoder-Decoder Architectures for Language Models

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Sun, Yutao, Dong, Li, Zhu, Yi, Huang, Shaohan, Wang, Wenhui, Ma, Shuming, Zhang, Quanlu, Wang, Jianyong, Wei, Furu
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866929338178338816
author Sun, Yutao
Dong, Li
Zhu, Yi
Huang, Shaohan
Wang, Wenhui
Ma, Shuming
Zhang, Quanlu
Wang, Jianyong
Wei, Furu
author_facet Sun, Yutao
Dong, Li
Zhu, Yi
Huang, Shaohan
Wang, Wenhui
Ma, Shuming
Zhang, Quanlu
Wang, Jianyong
Wei, Furu
contents We introduce a decoder-decoder architecture, YOCO, for large language models, which only caches key-value pairs once. It consists of two components, i.e., a cross-decoder stacked upon a self-decoder. The self-decoder efficiently encodes global key-value (KV) caches that are reused by the cross-decoder via cross-attention. The overall model behaves like a decoder-only Transformer, although YOCO only caches once. The design substantially reduces GPU memory demands, yet retains global attention capability. Additionally, the computation flow enables prefilling to early exit without changing the final output, thereby significantly speeding up the prefill stage. Experimental results demonstrate that YOCO achieves favorable performance compared to Transformer in various settings of scaling up model size and number of training tokens. We also extend YOCO to 1M context length with near-perfect needle retrieval accuracy. The profiling results show that YOCO improves inference memory, prefill latency, and throughput by orders of magnitude across context lengths and model sizes. Code is available at https://aka.ms/YOCO.
format Preprint
id arxiv_https___arxiv_org_abs_2405_05254
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle You Only Cache Once: Decoder-Decoder Architectures for Language Models
Sun, Yutao
Dong, Li
Zhu, Yi
Huang, Shaohan
Wang, Wenhui
Ma, Shuming
Zhang, Quanlu
Wang, Jianyong
Wei, Furu
Computation and Language
We introduce a decoder-decoder architecture, YOCO, for large language models, which only caches key-value pairs once. It consists of two components, i.e., a cross-decoder stacked upon a self-decoder. The self-decoder efficiently encodes global key-value (KV) caches that are reused by the cross-decoder via cross-attention. The overall model behaves like a decoder-only Transformer, although YOCO only caches once. The design substantially reduces GPU memory demands, yet retains global attention capability. Additionally, the computation flow enables prefilling to early exit without changing the final output, thereby significantly speeding up the prefill stage. Experimental results demonstrate that YOCO achieves favorable performance compared to Transformer in various settings of scaling up model size and number of training tokens. We also extend YOCO to 1M context length with near-perfect needle retrieval accuracy. The profiling results show that YOCO improves inference memory, prefill latency, and throughput by orders of magnitude across context lengths and model sizes. Code is available at https://aka.ms/YOCO.
title You Only Cache Once: Decoder-Decoder Architectures for Language Models
topic Computation and Language
url https://arxiv.org/abs/2405.05254