Files
leleka/engine/strata/tools/test_draft_vocab.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

48 lines
1.8 KiB
Python

"""Tests for tools/draft_vocab.py's corpus coverage mode (#597): the most frequent tokens of a corpus that together cover
a given share of its occurrences. No model, no GPU.
python -m unittest tools.test_draft_vocab
"""
from __future__ import annotations
import sys
import tempfile
import unittest
from collections import Counter
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import draft_vocab as DV # noqa: E402
class Coverage(unittest.TestCase):
def test_most_frequent_first_until_the_share_is_covered(self):
c = Counter({7: 50, 3: 30, 9: 15, 4: 5}) # 100 occurrences
self.assertEqual(DV.covering(c, 0.5), [7])
self.assertEqual(DV.covering(c, 0.8), [7, 3])
self.assertEqual(DV.covering(c, 0.81), [7, 3, 9])
self.assertEqual(DV.covering(c, 1.0), [7, 3, 9, 4])
def test_ties_take_the_lower_id_first(self):
self.assertEqual(DV.covering(Counter({5: 10, 2: 10, 8: 10}), 0.5), [2, 5])
def test_share_outside_a_subset(self):
c = Counter({1: 60, 2: 30, 3: 10})
self.assertAlmostEqual(DV.outside(c, [1]), 0.4)
self.assertAlmostEqual(DV.outside(c, [1, 2, 3]), 0.0)
self.assertEqual(DV.outside(Counter(), [1]), 0.0)
def test_corpus_counts_reads_every_file(self):
class Tok: # one id per character
def encode(self, text):
return [ord(ch) for ch in text]
with tempfile.TemporaryDirectory() as d:
a, b = Path(d) / "a.txt", Path(d) / "b.txt"
a.write_text("été", encoding="utf-8")
b.write_text("eté", encoding="utf-8")
self.assertEqual(DV.corpus_counts(Tok(), [a, b]), Counter({ord("é"): 3, ord("t"): 2, ord("e"): 1}))
if __name__ == "__main__":
unittest.main()