Skip to main content

KV Packet

KV Packet provides recomputation-free, context-independent KV-cache reuse for large language models. It surrounds reusable sources with small trainable header/trailer adapters, prefills each packet independently, and assembles their caches at serving time with positional realignment but no document-token recomputation.

Installation

pip install kvpacket

Optional integrations are installed separately:

pip install "kvpacket[compress]"  # KVPress cache compression
pip install "kvpacket[serve]"     # OpenAI Responses-compatible HTTP/SSE transport
pip install "kvpacket[agent]"     # MCP support for agent examples

KV Packet requires Python 3.12 or newer. Install the PyTorch build appropriate for your compute platform before loading a model.

Using preprocessed packets

from kvpacket import HFBackend, PacketSession, PacketStore

backend = HFBackend(model)
store = PacketStore.load("document-packets.pt", backend=backend)

session = PacketSession(backend=backend, store=store, tokenizer=tokenizer)
session.register_store_chunks()
session.push(prompt_containing_registered_content)
result = session.generate()

Packet construction and adapter training are offline operations. At serving time, PacketStore loads validated precomputed caches, while PacketSession matches registered content and forwards only unmatched online tokens.

Library layers

  • PacketPreprocessor builds reusable packet caches from original sources.
  • PacketTrainer trains wrapper adapters from full-attention teacher samples.
  • PacketExecutor exposes reentrant packet-aware prefill for existing serving stacks.
  • PacketSession provides stateful matching, prefill, recording, and generation.
  • HFBackend supplies the included Hugging Face compute backend.
  • KVPressCompressor optionally compresses packet caches offline.

See the documentation, training guide, and serving guide for complete workflows and extension interfaces.

Paper

KV Packet implements the method introduced in KV Packet: Recomputation-Free Context-Independent KV Caching for LLMs.

The package is distributed under the MIT License.

Metadata

Release files for kvpacket 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kvpacket 0.1.0
File Size Uploaded
kvpacket-0.1.0.tar.gz 775.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kvpacket 0.1.0
File Interpreter ABI Platform
kvpacket-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 897.2 kB

Release files / kvpacket-0.1.0.tar.gz

Download URL kvpacket-0.1.0.tar.gz
Size 775.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9be3afb4a9f72db9e901806b3b7fec6999a22b752c974bd958f2d887fc8ab385
BLAKE2b-256 checksum
How to use checksums
b4888969fe30c90abec4e23d9cb5ae4b9d6eeecae03bbb9d8a397f48f86b83ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / kvpacket-0.1.0-py3-none-any.whl

Download URL kvpacket-0.1.0-py3-none-any.whl
Size 121.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aecd61cdd76a7ab95956fba55a0d018d2304084278a7b6e3c8243d3c31048eb
BLAKE2b-256 checksum
How to use checksums
eff94bbf7ce7eafc1191130c5f3886e402468d755dd57b7d9414712049affead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page