This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: n1ck-guo <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models | ||
1. [Introduction](#introduction) | ||
2. [Usage](#usage) | ||
|
||
## Introduction | ||
**Heavy-Hitter Oracal (H2O)** is a novel approach for implementing the KV cache wihich significantly reduces memory footprint. | ||
|
||
This methods base on the fact that the accumulated attention scores of all tokens in attention blocks adhere to a power-law distribution. It suggests that there exists a small set of influential tokens that are critical during generation, named heavy-hitters (H2). H2 provides an opportunity to step away from the combinatorial search problem and identify an eviction policy that maintains accuracy. | ||
|
||
H2O can dynamically retains the balance of recent and H2 tokens. Significantly increase model throughput while ensuring accuracy. | ||
|
||
|
||
For more info, please refer to the paper [H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models](https://arxiv.org/pdf/2306.14048). | ||
|
||
|
||
![](./imgs/h2o.png) | ||
|
||
|
||
## Usage | ||
Using simulation mode | ||
```python | ||
from intel_extension_for_transformers.transformers.kv_cache_compression import H2OConfig, LlamaForCausalLM | ||
h2o_config = H2OConfig( | ||
heavy_ratio=heavy_ratio, | ||
recent_ratio=recent_ratio, | ||
h2o_min_seqlen=h2o_min_seqlen, | ||
real_drop=False, | ||
) | ||
user_model = LlamaForCausalLM.from_pretrained( | ||
args.model, | ||
prune_config=h2o_config, | ||
trust_remote_code=args.trust_remote_code) | ||
``` | ||
To run the real_drop mode | ||
```python | ||
from intel_extension_for_transformers.transformers.kv_cache_compression import H2OConfig, LlamaForCausalLM | ||
h2o_config = H2OConfig( | ||
heavy_ratio=heavy_ratio, | ||
recent_ratio=recent_ratio, | ||
h2o_min_seqlen=h2o_min_seqlen, | ||
real_drop=True, | ||
) | ||
user_model = LlamaForCausalLM.from_pretrained( | ||
args.model, | ||
prune_config=h2o_config, | ||
trust_remote_code=args.trust_remote_code) | ||
``` | ||
|
||
Please refer to [h2o example](../examples/huggingface/pytorch/text-generation/h2o/run_generation.py) for the details. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.