benchmark
turboquant_vllm.benchmark ¶
Benchmark harness for TurboQuant KV cache compression on supported models.
Loads a model via HuggingFace transformers and runs inference with: 1. Baseline: standard DynamicCache (no compression) 2. TurboQuant: accuracy-only or compressed mode
Supports both VLMs (e.g., Molmo2) and text-only models (e.g., Llama, Mistral). Model type is detected automatically from the config.
Two modes:
- Accuracy-only (default): TurboQuantKVCache compresses then immediately decompresses. Measures quality impact, no VRAM savings.
- Compressed (
--compressed): CompressedDynamicCache stores uint8 indices + fp16 norms. Measures real VRAM savings.
Measures output text diff, VRAM peak, generation time, and (in compressed mode) KV cache compression statistics.
Usage
Requires GPU with sufficient VRAM for the chosen model.
Examples:
from turboquant_vllm.benchmark import run_benchmark
results = run_benchmark("allenai/Molmo2-4B", "Describe the scene.", bits=3)
See Also
:class:turboquant_vllm.TurboQuantKVCache: Accuracy-only cache wrapper.
:class:turboquant_vllm.CompressedDynamicCache: Compressed cache with VRAM savings.
Functions¶
load_model ¶
Load a supported model and tokenizer/processor from HuggingFace.
Detects whether the model is a VLM (e.g., Molmo2) or text-only (e.g., Llama, Mistral) and loads the appropriate classes. The config is loaded once and reused for model instantiation to avoid redundant Hub calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
HuggingFace model identifier (e.g., 'allenai/Molmo2-8B'). |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, Any, bool]
|
Tuple of (model, processor, is_vlm) ready for inference. |
Source code in src/turboquant_vllm/benchmark.py
run_inference ¶
run_inference(
model: Any,
processor: Any,
prompt: str,
video_path: str | None = None,
max_new_tokens: int = 256,
*,
is_vlm: bool = False,
) -> tuple[str, float, float]
Run a single inference pass and measure performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Loaded HuggingFace model (VLM or text-only). |
required |
processor
|
Any
|
Loaded processor (AutoProcessor for VLMs, AutoTokenizer for text-only models). |
required |
prompt
|
str
|
Text prompt for the model. |
required |
video_path
|
str | None
|
Optional path to a video file (VLM only). |
None
|
max_new_tokens
|
int
|
Maximum tokens to generate. |
256
|
is_vlm
|
bool
|
Whether the model is a VLM (True) or text-only (False). |
False
|
Returns:
| Type | Description |
|---|---|
tuple[str, float, float]
|
Tuple of (output_text, vram_peak_mib, elapsed_seconds). |
Source code in src/turboquant_vllm/benchmark.py
run_benchmark ¶
run_benchmark(
model_id: str,
prompt: str,
video_path: str | None = None,
bits: int = 3,
max_new_tokens: int = 256,
*,
compressed: bool = False,
) -> dict
Run baseline vs TurboQuant comparison benchmark.
Detects model type (VLM or text-only) and runs both baseline and
TurboQuant inference passes for comparison. Warns if video_path
is provided for a text-only model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
HuggingFace model identifier. |
required |
prompt
|
str
|
Text prompt for inference. |
required |
video_path
|
str | None
|
Optional path to a video file (VLM only). |
None
|
bits
|
int
|
TurboQuant bits per coordinate. |
3
|
max_new_tokens
|
int
|
Maximum tokens to generate. |
256
|
compressed
|
bool
|
If True, benchmark CompressedDynamicCache (real VRAM savings). If False, benchmark TurboQuantKVCache (accuracy only). |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with benchmark results including both runs and comparison metrics. |
Source code in src/turboquant_vllm/benchmark.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 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 | |
main ¶
CLI entry point for the benchmark harness.
Supports VLMs (e.g., Molmo2) and text-only models (e.g., Llama, Mistral).