Files
leleka/engine/strata/tools/test_setup_bench_tips.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

101 lines
4.4 KiB
Python

"""Setup's recommendations from the community bench data (0.1.40): text only, never a changed default.
python -m unittest tools.test_setup_bench_tips
"""
from __future__ import annotations
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "tools"))
import setup # noqa: E402
from test_setup_hybrid import fake_sys # noqa: E402
BASE = ["--expert-cache", "auto", "--prefill", "auto", "--max-context", "65536"]
def tips(args=BASE, env=None, ram=32.0, model=20.0, vram=12.0, vision="none", win=False):
return setup.bench_tips(list(args), env, ram, model, vram, vision, win)
class BenchTips(unittest.TestCase):
def test_nothing_to_say_on_a_plain_pc(self):
self.assertEqual(tips(), [])
def test_explicit_cache_warns_on_windows_only(self):
a = ["--expert-cache", "2400", "--prefill", "auto"]
self.assertTrue(any("--expert-cache 2400" in t and "7x" in t for t in tips(a, win=True)))
self.assertEqual(tips(a, win=False), [])
self.assertEqual(tips(BASE, win=True), []) # auto: nothing to warn about
def test_prefill_auto_32768_follows_the_ram(self):
self.assertTrue(any("auto:32768" in t and t.startswith("tip") for t in tips(ram=128)))
self.assertEqual([t for t in tips(ram=64) if "auto:32768" in t], [])
big = ["--prefill", "auto:32768"]
self.assertTrue(any(t.startswith("warning") and "auto:32768" in t for t in tips(big, ram=32)))
self.assertEqual([t for t in tips(big, ram=96) if "auto:32768" in t], [])
def test_resident_headroom_on_small_ram(self):
res = [*BASE, "--resident-experts"]
self.assertTrue(any("STRATA_RESIDENT_HEADROOM_GIB" in t for t in tips(res, ram=32)))
self.assertTrue(any("STRATA_RESIDENT_HEADROOM_GIB" in t for t in tips([*BASE, "--resident-budget-gib", "40"], ram=48)))
self.assertEqual([t for t in tips(res, ram=64) if "HEADROOM" in t], [])
self.assertEqual([t for t in tips(res, {"STRATA_RESIDENT_HEADROOM_GIB": "8"}, ram=32) if "HEADROOM" in t], [])
self.assertEqual([t for t in tips(BASE, ram=32) if "HEADROOM" in t], []) # not a resident config
def test_no_conversation_cache_tip_the_engine_sizes_it_itself(self):
# 0.2.3 (#3493): the engine sizes the conversation cache from the free RAM when no value is given, so setup no longer tips about it
for ram, model in ((64, 40), (64, 41), (128, 40)):
self.assertEqual([t for t in tips(ram=ram, model=model) if "conversation" in t], [])
self.assertEqual([t for t in tips([*BASE, "--conversation-cache-mib", "4096"], ram=128) if "conversation" in t], [])
def test_vision_cpu_on_small_cards(self):
self.assertTrue(any("--vision cpu" in t for t in tips(vision="gpu", vram=12)))
self.assertEqual([t for t in tips(vision="gpu", vram=24) if "vision" in t], [])
self.assertEqual([t for t in tips(vision="cpu", vram=12) if "vision" in t], [])
def test_tips_never_touch_the_arguments(self):
a = ["--expert-cache", "2400", "--prefill", "auto", "--resident-experts"]
before = list(a)
env = {}
tips(a, env, ram=128, vision="gpu", win=True)
self.assertEqual(a, before)
self.assertEqual(env, {})
class Sockets(unittest.TestCase):
def fake(self, d, sockets, cores):
n = 0
for s in range(sockets):
for c in range(cores):
t = Path(d) / "devices" / "system" / "cpu" / f"cpu{n}" / "topology"
t.mkdir(parents=True)
(t / "physical_package_id").write_text(str(s))
(t / "core_id").write_text(str(c))
n += 1
def test_linux_sockets(self):
with tempfile.TemporaryDirectory() as d:
self.fake(d, 2, 18)
self.assertEqual(setup.linux_sockets(d), (2, 18))
with tempfile.TemporaryDirectory() as d:
self.fake(d, 1, 8)
self.assertEqual(setup.linux_sockets(d), (1, 8))
with tempfile.TemporaryDirectory() as d:
self.assertIsNone(setup.linux_sockets(d))
def test_two_socket_tip(self):
t = setup.two_socket_note((2, 18))
self.assertEqual(len(t), 1)
self.assertIn("--pool-workers 17", t[0])
self.assertEqual(setup.two_socket_note((1, 18)), [])
self.assertEqual(setup.two_socket_note(None), [])
if __name__ == "__main__":
unittest.main()