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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kvpacket-0.1.0.tar.gz (775.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kvpacket-0.1.0-py3-none-any.whl (121.9 kB view details)

Uploaded Python 3

File details

Details for the file kvpacket-0.1.0.tar.gz.

File metadata

  • Download URL: kvpacket-0.1.0.tar.gz
  • Upload date:
  • Size: 775.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for kvpacket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9be3afb4a9f72db9e901806b3b7fec6999a22b752c974bd958f2d887fc8ab385
MD5 e6c9bc5bdb34d080797826de4cc6b8e7
BLAKE2b-256 b4888969fe30c90abec4e23d9cb5ae4b9d6eeecae03bbb9d8a397f48f86b83ad

See more details on using hashes here.

File details

Details for the file kvpacket-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kvpacket-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 121.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for kvpacket-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8aecd61cdd76a7ab95956fba55a0d018d2304084278a7b6e3c8243d3c31048eb
MD5 6325b7901b1efa99180d7a7176cc7486
BLAKE2b-256 eff94bbf7ce7eafc1191130c5f3886e402468d755dd57b7d9414712049affead

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page