benchmark
turboquant_vllm.benchmark ¶
Benchmark harness for TurboQuant KV cache compression on Molmo2.
Loads Molmo2 via HuggingFace transformers and runs inference with: 1. Baseline: standard DynamicCache (no compression) 2. TurboQuant: accuracy-only or compressed mode
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 Molmo2 model and processor from HuggingFace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
HuggingFace model identifier (e.g., 'allenai/Molmo2-8B'). |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, Any]
|
Tuple of (model, processor) 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,
) -> tuple[str, float, float]
Run a single inference pass and measure performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Loaded Molmo2 model. |
required |
processor
|
Any
|
Loaded Molmo2 processor. |
required |
prompt
|
str
|
Text prompt for the model. |
required |
video_path
|
str | None
|
Optional path to a video file. |
None
|
max_new_tokens
|
int
|
Maximum tokens to generate. |
256
|
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.
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. |
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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 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 | |
main ¶
CLI entry point for the benchmark harness.