Skip to content

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

HeadWiseKV

Tylogi AI Lab

English | 中文

Static head-wise KV cache allocation with prefix-conditioned offline calibration for long-context LLM inference.

HeadWiseKV is a per-layer, per-KV-head cache-window allocation method that physically slices KV cache residency in llama.cpp. This repository includes the patched source snapshot, focused patch files, default allocation config, helper scripts, and preserved experiment artifacts needed to inspect and rerun the current public version.

The default profile targets Qwen3.6-27B Q4_K_M with a HeadWiseKV SWA/full allocation. It remains the profile used by the preserved evaluation tables. Newer sequential-calibration artifacts are published separately under configs/experimental until their model and corpus provenance is complete.

Highlights

  • Exact capacity numbers in this repository are preserved 24 GB 4090D CUDA full-GPU-offload measurements.
  • In those 4090D measurements, UD-Q4_K_XL reaches the model's full 262144-token context under HeadWiseKV.
  • With KV-cache q8_0, Q6_K reaches 159744 confirmed context under HeadWiseKV, while the unmodified llama.cpp path reaches 53248 under the same setup.
  • The target hardware class is local 24 GB RTX 3090/4090-class inference, but exact capacity should be read as 4090D-specific unless rerun.
  • Aggregate GSM8K and LoCoMo-MC10 results in this snapshot do not show a clear accuracy drop under the evaluated settings; see the limitations below before generalizing.

Complete accuracy tables, capacity tables, and rendered figures are in Experiments.

Q6_K Capacity Preview

The retained 4090D curve below shows regular Q6_K with KV-cache q8_0. It is a quick visual preview; the complete capacity table and all remaining plots are in Experiments.

Q6_K VRAM usage with KV q8_0

Documentation

document purpose
Docs index Entry point for the split technical documentation.
Quickstart Minimal runnable path, platform selection, and smoke test.
Platform setup Windows, Linux CUDA, macOS Metal.
Method Head-wise allocation model, SWA/full encoding, runtime behavior, and implementation entry points.
Sequential calibration Deployment-conditioned layer order, fidelity threshold tau, and generated profiles.
Experiments Accuracy tables, 4090D context-capacity table, and rendered figures.
Reproducibility Preserved artifacts, benchmark entry points, environment templates, and provenance notes.
Glossary Short definitions for smoke test, variant, judge metadata, offload, KV q8_0, and related terms.
Roadmap Planned follow-up technical notes.

Quick Start

Start with Quickstart; it links to the platform setup pages and gives the shared smoke test. The minimal flow is:

  1. Prepare a GGUF model outside this repository. The default server config is for Qwen3.6-27B Q4_K_M.
  2. Build the patched runtime from src_runtime/llama.cpp-9a532ae-kvmemfix, or provide an already built patched llama-server executable.
  3. Load configs/qwen36_27b_q4_e2e36_best_e2e_all64.env.
  4. Start llama-server with the desired -c context length.
  5. Verify the OpenAI-compatible endpoint with /v1/models, then call /v1/chat/completions using model alias qwen36-27b-headwisekv-swa.

Repository Layout

headwise-kv/
|-- configs/
|   `-- qwen36_27b_q4_e2e36_best_e2e_all64.env
|-- scripts/
|   `-- start_qwen36_portable.ps1
|-- patches/
|   `-- qwen35_per_head_swa_ggml.patch
|-- src_patched/
|-- src_runtime/
|   `-- llama.cpp-9a532ae-kvmemfix/
|-- docs/
|   |-- README.md / README.zh-CN.md
|   |-- quickstart*.md
|   |-- setup-{windows,linux,macos}*.md
|   |-- method*.md, experiments*.md, reproducibility*.md
|   |-- glossary*.md, roadmap*.md
|   `-- figures/
|-- results/
|   |-- locomo/
|   `-- summary.json
`-- data/
    `-- raw_text/

Model weights, benchmark datasets, and prebuilt runtime binaries are not included.

Scope And Limitations

The exact capacity numbers are 24 GB 4090D CUDA full-GPU-offload measurements. They should not be read as macOS Metal capacity claims or as guarantees for every RTX 3090/4090-class machine.

This public snapshot preserves aggregate GSM8K rows, LoCoMo-MC10 rows, LoCoMo QA artifacts, rendered figures, and the default allocation. It does not include model weights, benchmark dataset files, GGUF hashes, every raw per-question GSM8K prediction, every raw capacity probe log, or exact OS/driver/CUDA version records. No statistical significance test was run; quality statements are limited to the listed tasks, prompts, quantization types, and hardware.

Citation

If you find HeadWiseKV useful, please cite our paper:

@misc{xie2026headwisekvbudgetedperheadcache,
      title={HeadWiseKV: Budgeted Per-Head Cache Residency for Hybrid Long-Context Language Models},
      author={Renjie Xie and Juncheng Yang and Aoting Hu and Mingxi Zhang and Liyao Wu and Zheheng Hong and Wei Xu},
      year={2026},
      eprint={2609.02029},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2609.02029},
}

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages