Integration API¶
Common¶
Shared integration exceptions.
IntegrationError ¶
Bases: RuntimeError
Base class for runtime integration failures.
OptionalDependencyError ¶
Bases: IntegrationError
Raised when an optional backend package is required but unavailable.
ProductionModeError ¶
Bases: IntegrationError
Raised when a requested production path cannot satisfy the contract.
HuggingFace¶
HuggingFace DynamicCache wrapper with compressed storage.
CompressedDynamicCache ¶
CompressedDynamicCache(cache: Any, *, head_dim: int, bits: int | None = 4, k_bits: int | None = None, v_bits: int | None = None, seed: int = 42, device: device | None = None, rotation_mode: RotationMode = RotationMode.RHT, model_config: Any | None = None)
Patch a Transformers cache and store compressed K/V rows.
The wrapper dequantizes for HuggingFace attention output, so this is a diagnostic route. Production decode should use packed page kernels.
Source code in turboquant/integration/hf/dynamic_cache.py
vLLM¶
Paged compressed cache operations.
PagedCompressedKVCache ¶
PagedCompressedKVCache(*, config: KVQuantConfig, spec: PagedCacheSpec, device: device, dtype: dtype = torch.float16)
Owns compressed KV blocks addressed by vLLM-style flat slots.
Source code in turboquant/integration/vllm/ops.py
TurboQuant vLLM integration - thin adapter layer.
Responsibilities: - Detect layer/backend type (flash vs MLA/GDN) - Install minimal monkey-patches that delegate to capture/store/score - Expose clean modes: off | capture_only | hybrid | full_tq - Keep patching surface tiny; all real logic lives in capture/store
Modes: - off: no TQ activity, passthrough - capture_only: capture KV into compressed store, always use flash output - hybrid: use compressed history + exact recent for decode - full_tq: (future) TQ handles everything including prefill
LayerConfig
dataclass
¶
LayerConfig(head_dim: int, num_kv_heads: int, num_query_heads: int, key_bits: int = 3, value_bits: int = 2, value_group_size: int = 32, ring_capacity: int = 128, layer_idx: int = 0, backend_kind: str = 'flash', device: device = (lambda: torch.device('cuda'))())
Per-layer TQ configuration.
LayerState
dataclass
¶
Per-layer runtime state. Owns the capture engine and store.
set_mode ¶
Set global TurboQuant mode.
get_mode ¶
install_hooks ¶
install_hooks(model_runner, key_bits: int = 3, value_bits: int = 2, value_group_size: int = 32, ring_capacity: int = 128, initial_layers_count: int = 4, initial_layers_key_bits: int = None, mode: str = MODE_CAPTURE_ONLY, no_alloc: bool = False) -> Dict[str, LayerState]
Install TurboQuant hooks on all attention layers in a vLLM model runner.
Returns: dict mapping layer_name -> LayerState
Source code in turboquant/integration/vllm/hooks.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
free_kv_cache ¶
Free paged KV cache for TQ-hooked layers. Returns bytes freed.
Only frees layers that have TQ state. Non-TQ layers (MLA/GDN) keep their cache.
Source code in turboquant/integration/vllm/hooks.py
get_stats ¶
Return summary statistics for all TQ layer states.