How HeadInfer works (Lossless Offloading)
mainUnlike compression methods, HeadInfer is a lossless offloading method. It keeps the full KV cache but stores it in one slot per (layer, kv head) pair. It streams these slots between CPU and GPU, prefetching the next head's cache asynchronously while the current head computes.
Key Characteristics:
- Memory Efficiency: Only a constant number of head-caches occupy GPU memory regardless of context length.
- Performance Trade-off: It is a memory-for-latency trade. Expect a decode-latency cost due to per-head cache traffic.
- Requirements: Requires
--attn_implementation flash_attention_2. - Usage: It can be used with any runner that accepts
--method(e.g., LongBench).
python3 run_longbench.py \
--method HeadInfer \
--model_path /path/to/Llama-3-8B-Instruct \
--attn_implementation flash_attention_2 \
--save_dir ./results_long_bench \
--use_cache True