Skip to content

Latest commit

 

History

History
116 lines (93 loc) · 6.06 KB

RESULTS.md

File metadata and controls

116 lines (93 loc) · 6.06 KB

Measured lookup and scoring performance

Recorded: 2026-11-19T14:11:50.837774+00:00.

Environment: CPython 3.12.14 / NumPy 2.3.5; Linux-6.18.57-x86_64-with-glibc2.41; AMD EPYC 9V74 80-Core Processor.

These are synthetic, repeatable warm-cache measurements on this machine. They are not promises for another CPU, a full cryptanalysis application, or cold/random access over a larger working set.

Parameters: vocabulary size 26; 9 repeated samples after 2 warmups; target 25.0 ms per timing batch; seed 20261119. Implementations are timed in cyclically interleaved rounds to reduce time-dependent host-load bias.

Scores and packed keys were checked against independent reference calculations before measurement. All implementations use the same float32 values. Observed-key fractions are listed in the JSON result. SHA-256 fingerprints of the benchmark and scoring sources are recorded there and were verified unchanged after timing.

Whole candidate scoring

Input is a Python list of token IDs. Window/key preparation is included. Speedup = legacy median time / new median time; below 1 means slower.

n Tokens Legacy µs Dense µs Dense speedup Sparse µs Sparse speedup
2 16 2.68 8.83 0.30× 7.55 0.35×
2 64 9.95 10.11 0.98× 11.40 0.87×
2 256 39.56 16.61 2.38× 27.93 1.42×
2 4096 722.82 153.56 4.71× 455.55 1.59×
3 16 2.92 9.83 0.30× 8.68 0.34×
3 64 11.80 11.33 1.04× 12.89 0.91×
3 256 50.43 18.82 2.68× 32.42 1.56×
3 4096 836.05 140.65 5.94× 420.70 1.99×
4 16 3.80 12.75 0.30× 11.63 0.33×
4 64 16.46 13.85 1.19× 15.36 1.07×
4 256 63.39 19.52 3.25× 32.59 1.95×
4 4096 1108.83 162.62 6.82× 445.58 2.49×
5 16 3.72 12.10 0.31× 10.86 0.34×
5 64 18.58 15.33 1.21× 16.26 1.14×
5 256 74.70 21.69 3.44× 35.83 2.09×
5 4096 1260.74 156.67 8.05× 423.65 2.98×

Exact legacy scoring adapter

model.as_legacy_grams(copy=False) returns the existing specialized class for dense orders 1–6, sharing the score array. Method identity and exact numeric equality were checked. The timed method is literally the existing calculate_cost; variation around 1× is measurement noise, not an added format/scoring wrapper. This explicit option retains the old path for very short candidates as well as its float32 accumulation behaviour.

n Tokens Original µs Adapter µs Measured ratio
2 16 2.68 2.68 1.00×
2 64 9.95 9.93 1.00×
2 256 39.56 38.96 1.02×
2 4096 722.82 724.66 1.00×
3 16 2.92 2.89 1.01×
3 64 11.80 11.75 1.00×
3 256 50.43 48.28 1.04×
3 4096 836.05 831.91 1.00×
4 16 3.80 4.02 0.95×
4 64 16.46 16.36 1.01×
4 256 63.39 62.34 1.02×
4 4096 1108.83 1132.64 0.98×
5 16 3.72 3.72 1.00×
5 64 18.58 18.83 0.99×
5 256 74.70 73.54 1.02×
5 4096 1260.74 1234.89 1.02×

Prepared scalar lookup

All tensor index tuples and radix keys were prepared before timing. Numbers are median nanoseconds per lookup, including the Python loop and identical float conversion/accumulation. Raw binds the NumPy array or dictionary lookup directly; API calls lookup_key.

n Legacy tensor ns Dense raw ns Dense API ns Sparse raw ns Sparse API ns
2 70.6 67.1 82.7 53.2 76.6
3 84.9 64.2 81.9 54.9 80.7
4 88.8 61.6 79.5 51.9 77.1
5 104.9 64.9 82.5 55.3 80.7

Prepared key-batch scoring

Keys are already available. These timings exclude candidate-to-key conversion; do not compare them directly with complete candidate scoring above.

n Tokens Dense µs Sparse µs
2 16 5.41 4.09
2 64 5.29 6.25
2 256 5.73 15.87
2 4096 11.96 301.95
3 16 5.31 4.09
3 64 5.46 6.71
3 256 6.25 18.55
3 4096 11.31 265.52
4 16 6.25 4.50
4 64 5.94 7.64
4 256 5.97 18.74
4 4096 12.07 275.48
5 16 6.26 4.65
5 64 6.22 7.33
5 256 5.82 17.99
5 4096 13.31 282.83

Large vocabulary and high-order sparse models

The legacy implementation has no practical dense equivalent for these workloads; no legacy speedup is claimed. Full-scoring numbers include key preparation, while prepared-scoring numbers do not.

Unit V n Tokens Maximum key bits Full score µs Prepared score µs
word 50000 3 16 47 8.31 4.05
word 50000 3 64 47 13.75 7.22
word 50000 3 256 47 32.14 18.51
word 50000 3 4096 47 444.65 296.85
syllable 100 12 16 80 7.10 7.32
syllable 100 12 64 80 19.09 26.70
syllable 100 12 256 80 68.64 99.82
syllable 100 12 4096 80 1280.82 1745.69

Limits and engineering implications

  • New file-format parsing, decompression and checksums happen at load time; they add no format dispatch to a prepared lookup.
  • Dense arrays retain direct addressing. Public API calls still have Python call overhead; use prepared key batches or a bound score table in a hot loop.
  • Sparse tables avoid allocating V^n scores. Hashing and key construction for arbitrarily large integer keys are not constant in n.
  • Dense/sparse selection and candidate length affect whole-text timing. A single universal equality-of-speed claim would be misleading.
  • The benchmark deliberately separates conversion from lookup where stated. A complete application's tokenization, candidate mutation, memory locality and concurrency must be measured in that application.

Reproduce with the command in README.md. Detailed individual samples, loop counts and numeric errors are in results.json.