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.0.tar.gz (40.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.0-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tiny_turboquant-0.3.0.tar.gz
  • Upload date:
  • Size: 40.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.0.tar.gz
Algorithm Hash digest
SHA256 e8a93f044bd0647fff05d08a61c8d98c1109fb049d0daa6604469f49a39c6258
MD5 8f987b309c80fc267fd1ad997f1c3386
BLAKE2b-256 0ab8a404108458581a5646244d8e1afee217034f5fc1b3b8e320bd5628844fea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiny_turboquant-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3db9a7549095b4bc9193ca0660ef3bfbe91faca424a551a2680cbf9bb250877f
MD5 8d3597495b495a14bf3d2ab4328aa941
BLAKE2b-256 cdb85dd9964696de624b085d56c0f9f5030df880257ece32ad753fba29dd337e

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