# kvcached

> Elastic, virtual-memory KV cache that lets several LLMs share one GPU

- Category: Models & Inference / Serving & Deployment
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/ovg-project/kvcached
- Website: https://kvcached.org/
- Canonical page: https://ai-tldr.dev/tools/kvcached/

## In short

kvcached (short for KV cache daemon) is an open-source KV cache library for LLM serving and training on shared GPUs. It sits in the Serving & Deployment category of the Models & Inference tools and is open-source, written in Python and licensed Apache-2.0. To get started: install the package.

## Overview

kvcached (short for KV cache daemon) is an open-source KV cache library for LLM serving and training on shared GPUs. It brings an operating-system-style virtual memory abstraction to the key-value cache that serving engines keep for every in-flight request, so that cache memory is allocated elastically as load rises and handed back when it falls, instead of being reserved up front.

The trick is decoupling GPU virtual addresses from physical memory. A serving engine running with kvcached first reserves only virtual address space for its KV cache and backs it with physical GPU memory when the cache is actually used. Engines no longer need to claim a fixed slice of the card at startup with a flag like --gpu-memory-utilization, which is what normally forces one model per GPU.

It installs as a plugin into existing SGLang and vLLM environments, and the project documents support for MHA, GQA, MLA, sliding-window and hybrid attention models on both engines. Around the allocator it adds a memory-control CLI, a frontend router with a sleep mode for idle models, and prefix caching with a configurable memory bound. The project is Apache-2.0 licensed and comes out of research on GPU multitasking for LLMs, described in the papers the README cites.

## What it does

- Elastic KV cache: allocates and reclaims KV memory dynamically to match live load instead of reserving it statically at startup
- GPU virtual memory: maps logical KV cache to physical GPU memory at runtime, so memory is only committed when a cache is in use
- Plugs into unmodified SGLang and vLLM via environment variables, with prebuilt Docker images for each engine
- kvctl memory-control shell and the kvtop live view to list, watch and cap each engine's KV memory (absolute or as a percentage of GPU RAM)
- Frontend router that directs requests to the target model and puts idle models to sleep
- Prefix caching support — automatic prefix caching on vLLM and RadixCache on SGLang — with a configurable memory bound

## Getting started

kvcached installs into an existing SGLang or vLLM environment (the README lists Python 3.9–3.13). Install it, switch it on with two environment variables, and launch the engine as you normally would.

1. Install the package

   Install from PyPI into the same environment as your serving engine. Alternatively, pull one of the project's engine images: ghcr.io/ovg-project/kvcached-sglang or ghcr.io/ovg-project/kvcached-vllm.

```bash
pip install kvcached --no-build-isolation
```

2. Enable kvcached

   Set these variables before starting the engine. With kvcached enabled there is no need to pass a memory-utilization limit — it manages KV memory itself.

```bash
export ENABLE_KVCACHED=true
export KVCACHED_AUTOPATCH=1
```

3. Launch your engine as usual

   Start SGLang or vLLM normally; running several servers side by side on one GPU is where the elastic cache pays off.

```bash
# SGLang
python -m sglang.launch_server --model meta-llama/Llama-3.2-1B-Instruct --port 30000

# vLLM
vllm serve meta-llama/Llama-3.2-1B-Instruct --port=12346
```

4. Watch and cap memory with kvctl

   The kvctl shell ships with the package. Inside it, list shows each engine's KV usage, limit or limit-percent caps it, and kvtop opens a live usage view.

```bash
kvctl
# kvcached> list
# kvcached> limit-percent <ipc> 40
# kvcached> kvtop
```

## When to use it

- Serve several LLMs on one GPU so they share memory elastically instead of each claiming a fixed partition
- Run serverless-style deployments where models spin up and down on demand and only hold KV memory while active
- Fit a compound AI pipeline of specialised models (retrieval, reasoning, summarisation) onto limited hardware
- Co-locate LLM inference with training, fine-tuning or vision workloads on the same GPU
