{"id":50686401,"url":"https://github.com/back2matching/kvcache-bench","last_synced_at":"2026-06-08T23:04:34.740Z","repository":{"id":346740533,"uuid":"1191381383","full_name":"back2matching/kvcache-bench","owner":"back2matching","description":"Benchmark every KV cache compression method on your GPU. One command, real numbers. Supports Ollama + llama.cpp.","archived":false,"fork":false,"pushed_at":"2026-03-26T03:21:33.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-26T11:52:43.443Z","etag":null,"topics":["benchmark","gpu","inference","kv-cache","llama-cpp","llm","local-llm","ollama","quantization","vram"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/back2matching.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-25T07:25:47.000Z","updated_at":"2026-03-26T03:21:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/back2matching/kvcache-bench","commit_stats":null,"previous_names":["back2matching/kvcache-bench"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/back2matching/kvcache-bench","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/back2matching%2Fkvcache-bench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/back2matching%2Fkvcache-bench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/back2matching%2Fkvcache-bench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/back2matching%2Fkvcache-bench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/back2matching","download_url":"https://codeload.github.com/back2matching/kvcache-bench/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/back2matching%2Fkvcache-bench/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34083858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","gpu","inference","kv-cache","llama-cpp","llm","local-llm","ollama","quantization","vram"],"created_at":"2026-06-08T23:04:34.057Z","updated_at":"2026-06-08T23:04:34.730Z","avatar_url":"https://github.com/back2matching.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kvcache-bench\n\nBenchmark every KV cache compression method on your GPU. One command, real numbers.\n\n```\nkvcache-bench --model qwen3.5:9b\n```\n\n```\n| KV Type | Context | Prompt    | Gen tok/s | Prefill tok/s | VRAM +MB | Quality |\n|---------|---------|-----------|-----------|---------------|----------|---------|\n| f16     | 4096    | short     | 86.9      | 509.5         | +80      | PASS    |\n| f16     | 16384   | short     | 78.8      | 784.6         | +316     | PASS    |\n| q8_0    | 4096    | short     | 86.7      | 793.1         | +48      | PASS    |\n| q8_0    | 16384   | short     | 87.2      | 741.9         | +219     | PASS    |\n| q4_0    | 4096    | short     | 86.7      | 798.0         | +59      | PASS    |\n| q4_0    | 16384   | short     | 86.7      | 522.7         | +156     | PASS    |\n\n──────────────────────────────────────────────────\nRECOMMENDATION\n──────────────────────────────────────────────────\n\n  Use q8_0 (8-bit KV cache)\n  Speed: 87 tok/s (-0.1% vs f16)\n  VRAM: saves 97 MB vs f16 (2x compression)\n  Quality: negligible loss (+0.004 perplexity)\n\n  Set: OLLAMA_KV_CACHE_TYPE=q8_0 OLLAMA_FLASH_ATTENTION=1\n```\n\n*Real output from Qwen3.5-9B on RTX 4080 16GB.*\n\n## Why\n\nWhen you run a local LLM, the KV cache eats your VRAM. Ollama and llama.cpp support different KV cache quantization types (f16, q8_0, q4_0), but nobody tells you what the actual tradeoff is on YOUR hardware.\n\nCurrent state of the world:\n- You Google \"ollama kv cache quantization\" and find forum posts with conflicting advice\n- You manually test each config, eyeball nvidia-smi, and guess\n- No tool compares them systematically\n\nkvcache-bench fixes this. It tests every KV cache type on your GPU and gives you a comparison table with speed, VRAM, and quality.\n\n## Install\n\n```bash\npip install kvcache-bench\n```\n\n## Usage\n\n```bash\n# Auto-detect your first model, test all KV types\nkvcache-bench\n\n# Specific model\nkvcache-bench --model qwen3.5:9b\n\n# Test at multiple context lengths (where KV savings matter most)\nkvcache-bench --model llama3.1:8b --context 4096,8192,16384\n\n# Include tool calling test\nkvcache-bench --model qwen3.5:9b --prompts short,code,reasoning,tool_call\n\n# Save results as JSON\nkvcache-bench --model qwen3.5:9b --json results.json\n\n# Just show GPU info\nkvcache-bench --gpu\n\n# List available models\nkvcache-bench --list-models\n```\n\n## What It Tests\n\nFor each KV cache type (f16, q8_0, q4_0), it measures:\n\n| Metric | How |\n|--------|-----|\n| **Generation speed** | Tokens per second during generation |\n| **Prefill speed** | Tokens per second processing the prompt |\n| **VRAM delta** | Extra VRAM used beyond model weights (measured via nvidia-smi) |\n| **Quality** | Auto-checked against expected answers (Paris, code structure, reasoning) |\n\n## How It Works\n\n1. Detects your GPU and Ollama installation\n2. For each KV cache type: restarts Ollama with `OLLAMA_KV_CACHE_TYPE=\u003ctype\u003e`, warms up the model, runs benchmark prompts\n3. Measures VRAM before and during inference via nvidia-smi\n4. Extracts timing from Ollama's API response (prompt_eval_duration, eval_duration)\n5. Checks response quality with simple auto-graders\n6. Produces a markdown table (and optional JSON)\n\n## What the Research Says\n\nBased on llama.cpp community benchmarks and our testing:\n\n| KV Type | VRAM Savings | Perplexity Impact | Best For |\n|---------|-------------|-------------------|----------|\n| f16 | Baseline | None | When you have VRAM to spare |\n| q8_0 | 2x | +0.004 (negligible) | **Default recommendation.** Free VRAM, zero quality cost. |\n| q4_0 | 4x | +0.2 (noticeable) | When you need max context length or are VRAM-constrained |\n\nThe sweet spot for most users: **q8_0**. Halves your KV cache VRAM with essentially zero quality loss.\n\n## Requirements\n\n- Python 3.10+\n- NVIDIA GPU with nvidia-smi\n- Ollama installed and running\n\n## Roadmap\n\n- [ ] Mixed K/V types (q8 keys + q4 values)\n- [ ] Context length sweep charts\n- [ ] HuggingFace backend (vLLM, TGI)\n- [ ] TurboQuant integration\n- [ ] Multi-model matrix\n- [ ] HuggingFace Spaces leaderboard\n- [ ] Community result submissions\n\n## License\n\nApache 2.0\n\n## Related\n\n- [turboquant](https://github.com/back2matching/turboquant) -- TurboQuant KV cache compression (sub-4-bit)\n- [NVIDIA kvpress](https://github.com/NVIDIA/kvpress) -- KV cache eviction/pruning methods\n- [llama.cpp](https://github.com/ggml-org/llama.cpp) -- Where KV cache quantization lives\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fback2matching%2Fkvcache-bench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fback2matching%2Fkvcache-bench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fback2matching%2Fkvcache-bench/lists"}