Keep real model benchmark validity checks active under optimization

This commit is contained in:
karl committed 2026-10-13 13:54:33 +02:00
1 parent d568bdb2b1
commit 66bf7d7b47
4 files changed
+79 -27

No files matched your search

@@ -0,0 +1,32 @@
"""Benchmark validity checks must survive python -O."""
import math
import unittest
from benchmark import Session, require, vectors
class Contract(unittest.TestCase):
def test_bad_vectors_rejected(self):
for result in ([], [[1.0]], [[math.nan] * 768], [[0.0] * 768]):
with self.subTest(result_length=len(result)), self.assertRaises(ValueError):
vectors({"vectors": result}, 1)
def test_real_shape_normalized_vector_accepted(self):
vector = [1.0] + [0.0] * 767
self.assertEqual(vectors({"vectors": [vector]}, 1), [vector])
def test_cpu_contract_cannot_be_bypassed(self):
class FakeSession:
def send(self, value):
pass
def next(self):
return {"ok": True, "device": "gpu"}
with self.assertRaises(ValueError):
Session.worker(FakeSession(), {"op": "query"})
def test_explicit_guard_survives_optimization(self):
with self.assertRaises(ValueError):
require(False, "invalid asset")
if __name__ == "__main__":
unittest.main()