MatryoshkaKV: Adaptive KV Compression via Trainable Orthogonal Projection

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Lin, Bokai, Zeng, Zihao, Xiao, Zipeng, Kou, Siqi, Hou, Tianqi, Gao, Xiaofeng, Zhang, Hao, Deng, Zhijie
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866910946630303744
author Lin, Bokai
Zeng, Zihao
Xiao, Zipeng
Kou, Siqi
Hou, Tianqi
Gao, Xiaofeng
Zhang, Hao
Deng, Zhijie
author_facet Lin, Bokai
Zeng, Zihao
Xiao, Zipeng
Kou, Siqi
Hou, Tianqi
Gao, Xiaofeng
Zhang, Hao
Deng, Zhijie
contents KV cache has become a de facto technique for the inference of large language models (LLMs), where tensors of shape (layer number, head number, sequence length, feature dimension) are introduced to cache historical information for self-attention. As the size of the model and data grows, the KV cache can quickly become a bottleneck within the system in both storage and memory transfer. To address this, prior studies usually focus on the first three axes of the cache tensors for compression. This paper supplements them, focusing on the feature dimension axis, by utilizing low-rank projection matrices to transform the cache features into spaces with reduced dimensions. We begin by investigating the canonical orthogonal projection method for data compression through principal component analysis (PCA). We observe the issue with PCA projection where significant performance degradation is observed at low compression rates. To bridge the gap, we propose to directly tune the orthogonal projection matrices with a distillation objective using an elaborate Matryoshka training strategy. After training, we adaptively search for the optimal compression rates for various layers and heads given varying compression budgets. Compared to previous works, our method can easily embrace pre-trained LLMs and hold a smooth tradeoff between performance and compression rate. We empirically witness the high data efficiency of our training procedure and find that our method can sustain over 90% performance with an average KV cache compression rate of 60% (and up to 75% in certain extreme scenarios) for popular LLMs like LLaMA2-7B-base and Mistral-7B-v0.3-base.
format Preprint
id arxiv_https___arxiv_org_abs_2410_14731
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle MatryoshkaKV: Adaptive KV Compression via Trainable Orthogonal Projection
Lin, Bokai
Zeng, Zihao
Xiao, Zipeng
Kou, Siqi
Hou, Tianqi
Gao, Xiaofeng
Zhang, Hao
Deng, Zhijie
Machine Learning
Artificial Intelligence
Computation and Language
KV cache has become a de facto technique for the inference of large language models (LLMs), where tensors of shape (layer number, head number, sequence length, feature dimension) are introduced to cache historical information for self-attention. As the size of the model and data grows, the KV cache can quickly become a bottleneck within the system in both storage and memory transfer. To address this, prior studies usually focus on the first three axes of the cache tensors for compression. This paper supplements them, focusing on the feature dimension axis, by utilizing low-rank projection matrices to transform the cache features into spaces with reduced dimensions. We begin by investigating the canonical orthogonal projection method for data compression through principal component analysis (PCA). We observe the issue with PCA projection where significant performance degradation is observed at low compression rates. To bridge the gap, we propose to directly tune the orthogonal projection matrices with a distillation objective using an elaborate Matryoshka training strategy. After training, we adaptively search for the optimal compression rates for various layers and heads given varying compression budgets. Compared to previous works, our method can easily embrace pre-trained LLMs and hold a smooth tradeoff between performance and compression rate. We empirically witness the high data efficiency of our training procedure and find that our method can sustain over 90% performance with an average KV cache compression rate of 60% (and up to 75% in certain extreme scenarios) for popular LLMs like LLaMA2-7B-base and Mistral-7B-v0.3-base.
title MatryoshkaKV: Adaptive KV Compression via Trainable Orthogonal Projection
topic Machine Learning
Artificial Intelligence
Computation and Language
url https://arxiv.org/abs/2410.14731