This document shows how one benchmark run moves through the codebase.
wrapper script
-> CLI parser
-> config objects
-> benchmark runner
-> model prefill
-> cache compression
-> decode loop
-> report formatting
-> terminal output
File: turboquant_h_smollm_benchmark.py
Purpose:
- preserve the old script name,
- add
src/tosys.path, - delegate to
turboquant_h.cli.main().
This file is intentionally tiny. It exists for convenience, not business logic.
File: src/turboquant_h/cli.py
Important functions:
build_parser()build_configs()main()
What happens:
- command-line arguments are parsed,
- runtime settings become a
RuntimeConfig, - compression settings become a
TurboQuantHConfig, - both configs are validated,
run_benchmark(...)is called.
File: src/turboquant_h/benchmark.py
Important functions:
select_device()select_model_dtype()load_model_and_tokenizer()run_benchmark()
What happens:
- choose CPU or CUDA,
- pick the model dtype,
- load tokenizer and model,
- seed PyTorch,
- start timing,
- call
generate_with_compressed_cache(...).
Still in src/turboquant_h/benchmark.py
Important function:
generate_with_compressed_cache()
What happens:
- the prompt is converted into model input text,
- a prefill forward pass is run with
use_cache=True, past_key_valuesfrom the dense model output are collected,- baseline dtype size is measured,
- dense cache is converted into a compressed cache.
Main file:
src/turboquant_h/compression/cache.py
Supporting files:
rotation.pyquantization.pycorrection.pypacking.py
What happens conceptually:
- split cache tensors into recent and old regions,
- keep recent tokens in higher precision,
- chop older regions into blocks,
- rotate blocks if enabled,
- quantize blocks into packed low-bit form,
- optionally store correction information,
- optionally retain selected salient tokens in higher precision,
- store everything in compressed cache structures.
File: src/turboquant_h/benchmark.py
For every generated token:
- sample the next token from logits,
- append it to the generated sequence,
- run the next forward pass using either:
- direct compressed attention, or
- dense reconstruction of the cache first.
File: src/turboquant_h/compression/attention.py
Important functions:
enable_compressed_attention()compressed_eager_attention_forward()
What happens:
- compatible attention modules are patched,
- the patched attention layer receives a
CompressedCache, - cached blocks are streamed piece by piece,
- attention logits are accumulated without fully rebuilding a dense cache,
- optional QJL score-space correction is applied when enabled.
Files:
src/turboquant_h/benchmark.pysrc/turboquant_h/compression/cache.py
If direct compressed attention is disabled:
- compressed cache is materialized back into dense tensors,
- the model runs a normal forward step with dense
past_key_values, - the new dense cache is compressed again for the next step.
This path is easier to reason about, but less efficient.
Files:
src/turboquant_h/benchmark.pysrc/turboquant_h/reporting.py
What happens:
- baseline and compressed bit counts are estimated,
- generated token ids are decoded into text,
- a
BenchmarkResultobject is built, format_benchmark_report(...)turns it into readable output,- the CLI prints the final report.
When something breaks, it usually helps to ask which layer the issue belongs to:
- argument or configuration issue:
cli.pyorconfig.py - model loading or decode-loop issue:
benchmark.py - wrong cache size or weird reconstruction:
cache.py - strange bit-level values:
packing.py - strange rotated values:
rotation.py - quantization quality issue:
quantization.py - correction issue:
correction.py - direct compressed attention issue:
attention.py