Giter VIP home page Giter VIP logo

pqcache's Introduction

PQCache: Product Quantization-based KVCache for Long Context LLM Inference (Paper)

Codes for the paper "PQCache: Product Quantization-based KVCache for Long Context LLM Inference".

Overview

As the field of Large Language Models (LLMs) continues to evolve, the context length in inference is steadily growing. Key-Value Cache (KVCache), a crucial component in LLM inference, has now become the primary memory bottleneck due to limited GPU memory. Current methods selectively determine suitable keys and values for self-attention computation in LLMs to address the issue. However, they either fall short in maintaining model quality or result in high serving latency. Drawing inspiration from advanced embedding retrieval techniques used in the database community, we consider the storage and searching of KVCache as a typical embedding retrieval problem. We propose PQCache, which employs Product Quantization (PQ) to manage KVCache, maintaining model quality while ensuring low serving latency. During the prefilling phase, we apply PQ to tokens' keys for each LLM layer and head. During the autoregressive decoding phase, for each newly generated token, we first identify important tokens through Maximum Inner-Product Search (MIPS) using PQ codes and centroids, then fetch the corresponding key-value pairs for self-attention computation. Through meticulous design of overlapping and caching, we minimize any additional computation and communication overhead during both phases. Extensive experiments show that PQCache achieves both effectiveness and efficiency. It maintains model quality even when only 1/5 of the tokens are involved in attention, while attaining acceptable system latency.

PQCache

Scripts

  1. First compile lfucache for GPU cache:
cd vq_method/retrieval_based/lfu/
mkdir build; cd build; cmake ..; make
cd ../../../../
  1. Then download the datasets of LongBench to ./data/.

  2. Run the script:

bash run_mistral.sh

Code Structure

Our codes are mainly in the vq_method directory.

- retrieval_based
    - lfu: codes for GPU cache.
    - cache_manager.py: codes for cache management.
    - multi_core_compressor_v2.py: codes for multi-CPU-core compression.
    - pq_search.py: codes for PQ compressor.
- mistral_patch.py: codes for replacing the original attention in Mistral.

Acknowledgement

During the development and implementation of PQCache, we learned a lot and borrowed some codes from the following projects.

LongBench
H2O
InfLLM
SPARQ
Hetu

Citation

If you find this work useful, please cite our paper.

pqcache's People

Contributors

hugozhl avatar

Stargazers

 avatar DY Yao avatar  avatar  avatar Xiaodong Ji avatar EnanaShinonome avatar

Watchers

 avatar

pqcache's Issues

KMeans is not executed on the GPU?

Thanks for your great work!
During the inference process, the GPU utilization is relatively low. Could you kindly explain why the KMeans algorithm is not performed asynchronously on the GPU? I am curious to understand the reasoning behind this design choice and whether there are specific considerations or limitations that influenced this decision.

CMake Error at CMakeLists.txt:3 (find_package)

您好~ 我已安装pybind11,但是在运行cmake ..后出现以下报错,请问有相关的解决方案吗?

pybind11        2.6.0
pybind11-global 2.6.0
CMake Error: Error in cmake code at
/root/miniconda3/envs/PQcache/lib/cmake/pybind11/pybind11Config.cmake:3:
Parse error.  Expected a command name, got unquoted argument with text "pybind11Config.cmake".
CMake Error at CMakeLists.txt:3 (find_package):
  find_package Error reading CMake code from
  "/root/miniconda3/envs/PQcache/lib/cmake/pybind11/pybind11Config.cmake".


CMake Error at CMakeLists.txt:6 (message):
  pybind11 not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.