File size: 3,079 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# TurboQuant Command Reference

Quick reference for the commands documented in `usage.md`.

## Benchmark CLI (`benchmark` example)

```
cargo run --release --example benchmark -- [FLAGS]
```

| Flag | Values | Used with |
|------|--------|-----------|
| `--workload` | `synthetic` \| `trace` \| `real-model` | all |
| `--quick` | flag | `synthetic` |
| `--trace <PATH>` | safetensors file | `trace` |
| `--real-model-dir <DIR>` | ONNX bundle dir | `real-model` |
| `--prompt <TEXT>` | prompt string | `real-model` |
| `--real-eval-mode` | `exact` \| `quantized` \| `compare` | `real-model` |
| `--bits <N>` | integer bit width (keys) | `quantized`/`compare` |
| `--value-bits <N>` | integer bit width (values) | `compare` |
| `--real-key-strategy` | `prod` \| `mse` | `quantized`/`compare` |
| `--top-k <N>` | integer | `compare` |
| `--max-new-tokens <N>` | integer | `real-model` |

Output: a benchmark report whose `source` field is one of `synthetic`, `trace`, or `real-model`. `real-model` mode reports logit RMSE, top-k agreement, token match/divergence rates, cross-entropy/perplexity, latency, tokens/sec, and exact vs quantized KV memory usage.

## ONNX Decoder Export (`scripts/export_hf_decoder_onnx.py`)

```
python3 scripts/export_hf_decoder_onnx.py [--preset NAME | --model ID] --output-dir DIR
```

- `--preset`: `distilgpt2` or `smollm2-135m-instruct` (verified presets)
- `--model`: explicit HuggingFace model id
- `--output-dir`: destination for the exported ONNX bundle
- Exports target `text-generation-with-past`, dtype `fp32` (verified on the CPU ONNX Runtime path)

## One-Command Eval Orchestrator (`scripts/run_real_model_eval.py`)

```
python3 scripts/run_real_model_eval.py [FLAGS]
```

| Flag | Meaning |
|------|---------|
| `--preset <NAME>` | verified export preset |
| `--model-dir <DIR>` | reuse an existing ONNX bundle |
| `--bits <N...>` | bit widths to sweep |
| `--strategies <S...>` | `prod`, `mse` |
| `--prompts <FILE>` | JSONL prompt suite (default: `scripts/prompts/real_model_eval_prompts.jsonl`) |
| `--max-prompts <N>` | limit prompts |
| `--max-new-tokens <N>` | generation length |
| `--top-k <N>` | top-k metric window |

Output: raw JSON plus a markdown summary report under `artifacts/real-model-evals/`.

## KV Trace Export (`scripts/export_hf_kv.py`)

```
python3 scripts/export_hf_kv.py \
  --model <HF_MODEL_ID> \
  --input <PROMPTS_FILE> \
  --output <OUT.safetensors> \
  --layer <N> \
  --head <N>
```

Output: a per-head safetensors trace consumable by the `benchmark` example with `--workload trace --trace <PATH>`.

## Environment Variables

| Variable | Meaning |
|----------|---------|
| `TURBOQUANT_REAL_MODEL_DIR` | directory of an exported ONNX bundle used by the manual real-model smoke test |

## Setup Prerequisites

- Rust `1.87.0+` (newer stable may be needed for the experimental `gpu` feature)
- Python 3 venv with the pinned dependencies in `assets/requirements-real-model.txt` for the export/eval helper scripts
- ONNX Runtime CPU binaries are fetched automatically by the `ort` crate on first Rust build