MCPcopy Index your code
hub / github.com/StargazerX0/ScaleKV

github.com/StargazerX0/ScaleKV @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
421 symbols 1,308 edges 44 files 36 documented · 9% updated 3mo ago★ 522 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ScaleKV: Memory-Efficient Visual Autoregressive Modeling with Scale-Aware KV Cache Compression

MIT Paper

Memory-Efficient Visual Autoregressive Modeling with Scale-Aware KV Cache Compression
Kunjun Li, Zigeng Chen, Cheng-Yen Yang, Jenq-Neng Hwang
University of WashingtonNational University of Singapore

💡 Introduction

We propose Scale-Aware KV Cache (ScaleKV), a novel KV Cache compression framework tailored for VAR’s next-scale prediction paradigm. ScaleKV leverages on two critical observations: varying cache demands across transformer layers and distinct attention patterns at different scales. Based on these insights, we categorizes transformer layers into two functional groups termed drafters and refiners, implementing adaptive cache management strategies based on these roles and optimize multi-scale inference by identifying each layer's function at every scale, enabling adaptive cache allocation that aligns with specific computational demands of each layer. On Infinity-8B, it achieves 10x memory reduction from 85 GB to 8.5 GB with negligible quality degradation (GenEval score remains at 0.79 and DPG score marginally decreases from 86.61 to 86.49).

🔥Updates

  • 🔥 May 26, 2025: Our paper is available now!
  • 🔥 May 25, 2025: Code repo is released! Arxiv paper will come soon!

🔧 Installation:

Reequirements

pip install -r requirements.txt

Model Checkpoints

Download google flan-t5-xl:

pip install -U huggingface_hub
huggingface-cli download google/flan-t5-xl --local-dir ./weights/flan-t5-xl

Download Infinity-2B:

huggingface-cli download FoundationVision/Infinity --include "infinity_2b_reg.pth" --local-dir ./weights/
huggingface-cli download FoundationVision/Infinity --include "infinity_vae_d32reg.pth" --local-dir ./weights/

Download Infinity-8B:

huggingface-cli download FoundationVision/Infinity --include "infinity_8b_weights/**" --local-dir ./weights/infinity_8b_weights
huggingface-cli download FoundationVision/Infinity --include "infinity_vae_d56_f8_14_patchify.pth" --local-dir ./weights/

⚡ Quick Start:

Sample images with ScaleKV-Compressed Infinity-8B (10% KV Cache):

python infer_8B.py

Sample images with ScaleKV-Compressed Infinity-2B (10% KV Cache):

python infer_2B.py

⚡ Sample & Evaluations

Sampling 5000 images from COCO-2017 captions with Infinity-8B.

torchrun --nproc_per_node=$N_GPUS scripts/sample_8b.py

Sample images with ScaleKV compressed Infinity-8B (10% KV Cache):

torchrun --nproc_per_node=$N_GPUS scripts/sample_kv_8b.py

After you sample all the images, you can calculate PSNR, LPIPS and FID with:

python scripts/compute_metrics.py --input_root0 samples/gt_8b --input_root1 samples/scalekv_8b

Sampling 5000 images from COCO captions with Infinity-2B.

torchrun --nproc_per_node=$N_GPUS scripts/sample_2b.py
torchrun --nproc_per_node=$N_GPUS scripts/sample_kv_2b.py
python scripts/compute_metrics.py --input_root0 samples/gt_2b --input_root1 samples/scalekv_2b

📚 Key Results

Acknowlegdement

Thanks to Infinity for their wonderful work and codebase!

Citation

If our research assists your work, please give us a star ⭐ or cite us using:

@article{li2025scalekv,
  title={Memory-Efficient Visual Autoregressive Modeling with Scale-Aware KV Cache Compression},
  author={Li, Kunjun and Chen, Zigeng and Yang, Cheng-Yen and Hwang, Jenq-Neng},
  journal={Advances in Neural Information Processing Systems},
  year={2025}
}

Core symbols most depended-on inside this repo

state_dict
called by 16
infinity/utils/arg_util.py
gen_one_img
called by 14
tools/run_infinity.py
update
called by 13
infinity/utils/misc.py
load_tokenizer
called by 9
tools/run_infinity.py
load_visual_tokenizer
called by 9
tools/run_infinity.py
load_transformer
called by 9
tools/run_infinity.py
decode
called by 9
infinity/models/bsq_vae/flux_vqgan.py
default
called by 7
infinity/models/bsq_vae/multiscale_bsq.py

Shape

Method 204
Function 165
Class 52

Languages

Python100%

Modules by API surface

infinity/utils/misc.py51 symbols
infinity/models/basic.py37 symbols
infinity/utils/dist.py36 symbols
infinity/models/infinity.py34 symbols
infinity/models/bsq_vae/multiscale_bsq.py34 symbols
infinity/models/bsq_vae/flux_vqgan.py33 symbols
infinity/dataset/dataset_t2i_iterable.py20 symbols
tools/inception.py17 symbols
infinity/utils/arg_util.py15 symbols
tools/run_infinity.py14 symbols
infinity/dataset/build.py13 symbols
tools/fid_score.py12 symbols

For agents

$ claude mcp add ScaleKV \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact