Skip to main content

Low-bit vector and KV-cache compression research toolkit for PyTorch

Project description

Tiny TurboQuant

Tiny TurboQuant is a lightweight PyTorch research toolkit for low-bit vector compression and KV-cache compression experiments.

Version 0.3.0 adds quality-hardening and integration-oriented research features:

  • optional per-head calibration in HybridTurboQuantKVCache
  • separate Key/Value recent windows for stronger Key preservation
  • safer outlier clamping for small head dimensions
  • paged/streaming attention utility that avoids one giant dense cache reconstruction in research tests
  • CompressedVectorIndex API with optional full-precision reranking
  • serving-engine integration scaffolding for vLLM/TensorRT-LLM style experiments

Important limitation

This package demonstrates packed memory compression and memory-quality benchmarking. It is not a production compressed-attention engine. Hugging Face generation still receives dense K/V tensors. The paged attention utility dequantizes page-by-page and avoids one full dense cache tensor, but it is not a fused CUDA/Triton kernel. Real latency gains require fused kernels or serving-engine integration.

Do not use this package to claim training acceleration, fine-tuning memory reduction, production legal/medical QA readiness, drop-in vLLM replacement, exact nearest-neighbor search, or faster LLM inference.

Install

pip install tiny-turboquant

Hybrid KV-cache usage

from tiny_turboquant import HybridTurboQuantKVCache

cache = HybridTurboQuantKVCache(
    key_bits=6,
    value_bits=4,
    key_outlier_bits=8,
    value_outlier_bits=8,
    n_key_outliers=32,
    n_value_outliers=16,
    key_recent_window=128,
    value_recent_window=64,
    per_layer_calibration=True,
    per_head_calibration=True,
)

Compressed vector index usage

import torch
from tiny_turboquant import CompressedVectorIndex

emb = torch.randn(10_000, 384)
index = CompressedVectorIndex(bits=4, store_original_for_rerank=True).add(emb)
results = index.search(emb[0], top_k=5, rerank_top_k=100)

print(index.compression_ratio())
print(results[0])

Paged attention utility

import torch
from tiny_turboquant import HybridTurboQuantKVCache

cache = HybridTurboQuantKVCache(key_bits=6, value_bits=4, recent_window=16)
k = torch.randn(1, 4, 64, 32)
v = torch.randn(1, 4, 64, 32)
cache.update(k, v, layer_idx=0)

q = torch.randn(1, 4, 1, 32)
out = cache.paged_attention(q, layer_idx=0)

Serving integration scaffolding

from tiny_turboquant import PagedKVCacheSpec, VLLMExperimentAdapter

spec = PagedKVCacheSpec(key_bits=6, value_bits=4, page_size=128)
plan = VLLMExperimentAdapter(spec).integration_plan()
print(plan)

Scope

Use this package for:

  • compressed vector-search experiments
  • RAG embedding compression experiments
  • KV-cache memory/quality tradeoff experiments
  • educational or research benchmarking
  • testing hybrid recent-token retention strategies
  • studying separate K/V compression settings
  • testing per-layer/per-head calibration

Current focus:

  • memory compression
  • quality measurement
  • cache-format experiments
  • research scaffolding for serving integration

Future direction:

  • actual Triton/CUDA fused dequant + attention kernels
  • stronger compressed-domain attention estimators
  • engine-specific paged-cache integration experiments

Project details


Download files

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

Source Distribution

tiny_turboquant-0.3.1.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

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

tiny_turboquant-0.3.1-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

Details for the file tiny_turboquant-0.3.1.tar.gz.

File metadata

  • Download URL: tiny_turboquant-0.3.1.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tiny_turboquant-0.3.1.tar.gz
Algorithm Hash digest
SHA256 07287166bcc1c4c43322d9168ecbe9673ed4bf0c1fd72e8c86468e689f26d83a
MD5 1b04791f8e3e0756783d496ce9bf5ea5
BLAKE2b-256 0bbc3648bf6a072110b6c878cb8cfe8de0fa29d1fe717298cf6a550bec0d3823

See more details on using hashes here.

File details

Details for the file tiny_turboquant-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tiny_turboquant-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2aa31bd253e8fbc89105ef87518c5db4fdab17d1c251d7f620087168fc7f0324
MD5 bfef67ecd9856d37349b045eb110715a
BLAKE2b-256 4e580cb5bd19b34f36bdecb12c946ef8f8252c4064a087d5d8db7c2997dcfc0c

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 Pingdom Monitoring Sentry Error logging StatusPage Status page