Skip to main content

turboquant-gpu

TurboQuant-GPU

5.02x KV cache compression for LLM inference — cuTile kernels with automatic PyTorch fallback.

pip install turboquant-gpu

Works on any NVIDIA GPU. Uses cuTile kernels when available, otherwise falls back to PyTorch automatically — no driver upgrades or manual config needed.

quick start

from transformers import AutoModelForCausalLM, AutoTokenizer
from turboquant_gpu import TurboQuantEngine
import torch

model_id = "mistralai/Mistral-7B-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="cuda")
tok   = AutoTokenizer.from_pretrained(model_id)

engine = TurboQuantEngine(head_dim=128, total_bits=3, device="cuda")
result = engine.generate(model, tok, "The University of Waterloo is known for ")

print(result["text"])
print(f"{result['tokens']} tokens | {result['stats']['ratio']:.2f}x compression")

install

pip install turboquant-gpu

For cuTile acceleration (optional, requires CUDA 13.0+ driver):

pip install cuda-tile[tileiras] --extra-index-url https://pypi.nvidia.com

If you skip cuda-tile or your driver is older, everything still works via PyTorch.

how it works

Implements the TurboQuant algorithm:

  1. normalize + rotate — random orthogonal rotation (Pi) makes coordinates near-Gaussian
  2. Lloyd-Max quantize — optimal 3-bit scalar quantization against N(0, 1/d), shared codebook for K and V

For HuggingFace integration, keys and values are both compressed and decompressed via fused kernels — a single kernel launch compresses both K and V, and a single launch decompresses both. The reconstructed FP16 tensors are packed into a standard DynamicCache that HuggingFace's attention uses directly. No model changes needed.

The package also ships fused attention kernels with QJL bias correction (2-bit Lloyd-Max keys + 1-bit sign sketch of the quantization residual). These perform scoring, online softmax, and V accumulation in one kernel with on-chip V decompression. They're fully implemented but not yet wired into the HuggingFace path — integrating them requires replacing the model's internal attention, which is model-specific. This is a candidate for a cuTile Gym contribution.

step-by-step api

engine = TurboQuantEngine(head_dim=128, total_bits=3, device="cuda")

# after model prefill:
compressed = engine.compress_kv_cache(out.past_key_values)
cache      = engine.build_cache(compressed)
stats      = engine.compression_stats(out.past_key_values)

# or just do it all in one call:
result = engine.generate(model, tokenizer, "your prompt here")

# auto-tune for your specific GPU:
engine.auto_tune(seq_len=512)

gpu support

Written in cuTile for cross-architecture portability. Falls back to PyTorch if cuTile or a compatible driver isn't available.

GPU cuTile kernels PyTorch fallback
A100 (Ampere, sm_80) CUDA 13.2+ driver always works
H100 (Hopper, sm_90) not yet supported by tileiras always works
RTX 4090 (Ada, sm_89) CUDA 13.2+ driver always works
B200/B300 (Blackwell, sm_100) CUDA 13.0+ driver always works
Any other CUDA GPU depends on tileiras always works

kernels

HuggingFace path (used by default):

kernel what it does
compress_kv_3bit fused K+V compression, 3-bit shared codebook, single launch
decompress_kv_3bit fused K+V decompression, single launch
compress_values_3bit / 2bit separate fallback for K or V individually
decompress_3bit / 2bit separate fallback decompression

Fused attention path (included, not in HuggingFace API):

kernel what it does
compress_keys_2bit_qjl 2-bit Lloyd-Max + 1-bit QJL signs for keys
fused_attention QJL-corrected scores + online softmax + V accumulation
fused_attention_vfused_3bit same + on-chip V decompression from compressed indices
attention_scores score-only (no softmax), for debugging

license

MIT

Metadata

Release files for turboquant-gpu 0.1.8

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

Source distribution (sdist)

Source distribution for turboquant-gpu 0.1.8
File Size Uploaded Provenance
turboquant_gpu-0.1.8.tar.gz 29.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for turboquant-gpu 0.1.8
File Interpreter ABI Platform
turboquant_gpu-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 54.8 kB

Release files / turboquant_gpu-0.1.8.tar.gz

Download URL turboquant_gpu-0.1.8.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6605527173354544837a8cdcafe292e41a5e97960f21c21653d686329a3fd469
BLAKE2b-256 checksum
How to use checksums
8427e1184474f7188c54098bc6d59f2ac3d335dfeeb04cf615b05314f5a6e23a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.1

Release files / turboquant_gpu-0.1.8-py3-none-any.whl

Download URL turboquant_gpu-0.1.8-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd4f7cd11bcb890632ad6c68bffab82b2dac33e2695dfbf626c044b251eea8c6
BLAKE2b-256 checksum
How to use checksums
0565c691e1ca1e60fb8cd6bb5932a2ebb9086b7e901de10779ce66586215d002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.1

Security for turboquant-gpu 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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