Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix round: pin IDOT_KERNELS/newline mutants, fix F2/F3 at the root
monotophic1a7adce454c5
diff --git a/c/tests/test_engine_evidence.py b/c/tests/test_engine_evidence.pyindex 8bcfa5a6..7dafd3da 100644--- a/c/tests/test_engine_evidence.py+++ b/c/tests/test_engine_evidence.py@@ -9,6 +9,7 @@ matching without a local, fast failure.import unittestfrom tools.engine_evidence import (+ IDOT_KERNELS,PreambleError,parse_engine_banner,parse_engine_loaded,@@ -58,6 +59,8 @@ class ParseEngineBannerTest(unittest.TestCase):parse_engine_banner("not a banner at all")def test_unknown_kernel_raises(self):+ # Negative control for the roster test below: an unlisted kernel+ # name (real ISA extension, not in IDOT_KERNELS) must be refused.with self.assertRaises(PreambleError):parse_engine_banner(_banner(**{"idot: avx2": "idot: sse4"}))@@ -65,6 +68,17 @@ class ParseEngineBannerTest(unittest.TestCase):with self.assertRaises(PreambleError):parse_engine_banner(_BANNER + " extra")+ def test_trailing_newline_rejected(self):+ # fullmatch requires consuming the WHOLE string; $ is zero-width+ # and matches just before a trailing "\n" too, so a weakening to+ # .match() or .search() would let a newline-terminated banner+ # through here even though fullmatch correctly refuses it. A+ # caller doing `for line in f:` on real engine stdout hands over+ # lines WITH their trailing newline, so this is the shape a real+ # caller would actually feed in, not a synthetic corner case.+ with self.assertRaises(PreambleError):+ parse_engine_banner(_BANNER + "\n")+# -- cap: [1, 2**31-1] --def test_cap_lower_bound_accepted(self):@@ -132,6 +146,69 @@ class ParseEngineBannerTest(unittest.TestCase):fields = parse_engine_banner(_banner(**{"cache=8": "cache=7"}))self.assertEqual(fields["cap"], 7)+ def test_oversized_field_raises_preamble_error_not_bare_value_error(self):+ # _UINT_TEXT has no digit-count cap, so a field beyond Python's+ # int-string conversion limit (sys.int_info.default_max_str_digits,+ # 4300 by default) used to reach int()/float() raw, escaping as a+ # bare ValueError instead of this module's own PreambleError --+ # breaking every caller's contract to refuse with a named error.+ huge = "1" + "0" * 4300+ with self.assertRaises(PreambleError):+ parse_engine_banner(_banner(**{"cache=8": f"cache={huge}"}))+++class IdotKernelRosterTest(unittest.TestCase):+ """Pin every IDOT_KERNELS entry from the engine's own source, not just+ avx2 (the only entry any test previously referenced -- confirmed by+ RAN mutation: reducing IDOT_KERNELS to ("avx2",) alone left this+ module's OWN 45-test suite fully green, since nothing here iterated+ or symbolically referenced the roster). Removing any single entry+ below, or the roster itself down to fewer entries, must fail this+ test -- proof-of-bite for each is in the worker report.++ Source of the 7 entries, cited by file:line: c/quant.h:582-594's+ #if/#elif ladder defines IDOT_KERNEL to each of these string+ literals in turn, and c/colibri.c:11243 prints it unmodified inside+ the exact banner format this fixture reproduces character-for-+ character (cache=%d experts/layer | compute experts@%d-bit+ dense@%d-bit | idot: <IDOT_KERNEL>).++ c/quant.h:582 "avx512-vnni" (__AVX512VNNI__ && __AVX512BW__)+ c/quant.h:584 "avx-vnni" (__AVXVNNI__ && __AVX2__)+ c/quant.h:586 "avx2" (__AVX2__)+ c/quant.h:588 "neon-i8mm" (__ARM_NEON && __ARM_FEATURE_MATMUL_INT8)+ c/quant.h:590 "neon" (__ARM_NEON, no i8mm) -- RAN+ c/quant.h:592 "vsx" (__VSX__)+ c/quant.h:594 "scalar" (else)++ "neon" is marked RAN: this development host is arm64 Darwin, and+ `echo | cc -dM -E -` (no -mcpu, matching this project's own Makefile+ comment "ARCH unset -> no -mcpu, default build byte-identical")+ defines __ARM_NEON but NOT __ARM_FEATURE_MATMUL_INT8 on this+ machine, so its own default (unaccelerated) build takes the "neon"+ branch of the ladder above -- confirmed by running that exact+ compiler invocation, not by reading the source alone. This is a+ compiler-preprocessor probe of the flags the default build actually+ uses, not a captured engine stdout banner: no engine binary was+ built or run for this (no model runs, per the dispatch's hard+ bound). The other six entries are taken from the C source only+ (INFERRED from c/quant.h's literals, not independently reproduced on+ real hardware for each ISA).+ """++ def test_every_roster_entry_parses_from_real_banner_text(self):+ for kernel in IDOT_KERNELS:+ with self.subTest(kernel=kernel):+ fields = parse_engine_banner(+ _banner(**{"idot: avx2": f"idot: {kernel}"}))+ self.assertEqual(fields["kernel"], kernel)++ def test_roster_is_not_accidentally_empty_or_singleton(self):+ # A cheap sanity backstop for the roster itself, independent of+ # any one entry's own test above.+ self.assertEqual(len(IDOT_KERNELS), 7)+ self.assertEqual(len(set(IDOT_KERNELS)), 7)+class ParseEngineLoadedTest(unittest.TestCase):def test_exact_loaded_returns_typed_fields(self):@@ -149,6 +226,13 @@ class ParseEngineLoadedTest(unittest.TestCase):with self.assertRaises(PreambleError):parse_engine_loaded("not a load record")+ def test_trailing_newline_rejected(self):+ # See ParseEngineBannerTest.test_trailing_newline_rejected: same+ # fullmatch-vs-$ subtlety, same real-caller shape (stdout lines+ # iterated with their newline still attached).+ with self.assertRaises(PreambleError):+ parse_engine_loaded(_LOADED + "\n")+# -- layers: [1, 128] --def test_layers_lower_bound_accepted(self):@@ -233,6 +317,13 @@ class ParseEngineLoadedTest(unittest.TestCase):self.assertEqual(fields["mtp"], "DISABLED (multiplexed serve)")self.assertEqual(fields["draft"], 0)+ def test_oversized_field_raises_preamble_error_not_bare_value_error(self):+ # See ParseEngineBannerTest's identical test: same digit-count+ # cap gap, same fix, this function's own layers field.+ huge = "1" + "0" * 4300+ with self.assertRaises(PreambleError):+ parse_engine_loaded(_loaded(**{"layers=32": f"layers={huge}"}))+class ParseEnginePreambleTest(unittest.TestCase):def test_dispatches_to_banner(self):diff --git a/c/tests/test_eval_glm.py b/c/tests/test_eval_glm.pyindex 8094f47a..581c3fad 100644--- a/c/tests/test_eval_glm.py+++ b/c/tests/test_eval_glm.py@@ -323,29 +323,26 @@ class EvalGlmEvidenceTests(unittest.TestCase):# tree ever prints a line starting with "loaded index" -- the only# stdout "loaded" record any engine emits is the exact "loaded in# ...s | resident dense: ..." line this module already pins above.- # This test documents eval_glm's actual, current behavior for that- # coincidental prefix collision (refused, not silently passed- # through) rather than asserting it is the last word on the- # question -- see the worker report's F2 section for why the- # underlying docstring in the shared engine_evidence.py is not- # touched here.+ # This is deliberately fail-loud dispatch behavior, not a bug --+ # see engine_evidence.parse_engine_preamble's own docstring+ # (fixed in this cycle to document the prefix mechanism and this+ # exact collision explicitly, since no engine anywhere in this+ # tree emits "loaded index" today). This test pins eval_glm's+ # own consumer-visible behavior for the same collision.with self.assertRaises(EVAL.EvidenceError):EVAL.classify_score_stdout("loaded index 5 whatever\n")def test_oversized_numeric_field_refuses_as_evidence_error(self):- # engine_evidence's int()/float() calls on a preamble field raise- # Python's own bare ValueError (not its PreambleError) once a- # numeric field exceeds the interpreter's 4300-digit int-string- # conversion limit (sys.int_info.default_max_str_digits) -- the- # regex that captures the field has no digit-count cap of its- # own. Before this module's three call sites caught ValueError- # alongside PreambleError, that bare ValueError escaped- # classify_score_stdout, ScoreStdoutClassifier.classify, and- # is_score_preamble uncaught, breaking this module's own- # contract to refuse every non-canonical record with a named- # error rather than crash. This module's own error contract is- # fixed here; the underlying engine_evidence.py, shared- # verbatim with other in-flight branches, is unchanged.+ # engine_evidence's own int()/float() calls now catch this at+ # the root (a numeric preamble field beyond the interpreter's+ # 4300-digit int-string conversion limit raises engine_evidence's+ # own PreambleError, not a bare ValueError) -- see+ # test_engine_evidence.py's identical-purpose tests on+ # parse_engine_banner/parse_engine_loaded directly. This+ # module's three call sites still catch ValueError alongside+ # PreambleError too, as defense in depth for any other+ # ValueError the shared module might someday raise; this test+ # pins the end-to-end result through eval_glm's own consumers.big = "1" + "0" * 4300banner = (f"== GLM C engine (glm_moe_dsa), cache={big} experts/layer | "diff --git a/c/tools/engine_evidence.py b/c/tools/engine_evidence.pyindex b52feced..9e37d02c 100644--- a/c/tools/engine_evidence.py+++ b/c/tools/engine_evidence.py@@ -45,8 +45,17 @@ def parse_engine_banner(line):match = _BANNER_RE.fullmatch(line)if not match:raise PreambleError(f"not an exact engine banner: {line!r}")- cap, expert_bits, dense_bits = map(- int, match.group("cap", "expert_bits", "dense_bits"))+ try:+ cap, expert_bits, dense_bits = map(+ int, match.group("cap", "expert_bits", "dense_bits"))+ except ValueError as exc:+ # _UINT_TEXT has no digit-count cap of its own, so a numeric+ # field beyond Python's int-string conversion limit (4300+ # digits by default) reaches here as a bare ValueError, not+ # this module's own PreambleError -- every caller of this+ # module refuses with a named error, never a crash.+ raise PreambleError(f"engine banner field is not a valid integer: "+ f"{line!r}") from excif not 1 <= cap <= _INT32_MAX:raise PreambleError(f"engine cache outside [1,{_INT32_MAX}]: {cap}")if not 1 <= expert_bits <= 16 or not 1 <= dense_bits <= 16:@@ -65,10 +74,18 @@ def parse_engine_loaded(line):match = _LOADED_RE.fullmatch(line)if not match:raise PreambleError(f"not an exact engine load record: {line!r}")- load_s = float(match.group("load_s"))- resident_mb = float(match.group("resident_mb"))- layers, experts, draft = map(- int, match.group("layers", "experts", "draft"))+ try:+ load_s = float(match.group("load_s"))+ resident_mb = float(match.group("resident_mb"))+ layers, experts, draft = map(+ int, match.group("layers", "experts", "draft"))+ except ValueError as exc:+ # Same rationale as parse_engine_banner: _FIXED2_TEXT/_UINT_TEXT+ # have no digit-count cap, so a field beyond Python's+ # int-string conversion limit reaches here as a bare+ # ValueError, not this module's own PreambleError.+ raise PreambleError(f"engine load record field is not a valid "+ f"number: {line!r}") from excmtp = match.group("mtp")if not math.isfinite(load_s) or not math.isfinite(resident_mb):raise PreambleError("engine load metrics must be finite")@@ -91,9 +108,26 @@ def parse_engine_loaded(line):def parse_engine_preamble(line):"""Dispatch to the banner/loaded parser by prefix, or return None.- None means the line is not one of the two owned preambles at all (an- ordinary log line); a line that starts like one of them but fails to- parse still raises PreambleError rather than being treated as unowned.+ "Starts like one of them" is a literal, mechanical prefix test+ (``line.startswith("== GLM C engine")`` / ``line.startswith("loaded+ in")``), not a semantic resemblance check: any line -- owned by this+ engine or not -- that happens to share that literal prefix is routed+ to the matching parser and, if it does not go on to match that+ parser's exact grammar, raises PreambleError rather than being+ treated as an ordinary unowned log line. This is deliberately+ fail-loud (an unexpected line reaching this position is itself+ worth surfacing), but it means the dispatch is broader than the two+ records it is named for: "loaded index ..." also starts with+ "loaded in" purely because "index" itself starts with "in", and+ would be refused here even though it has nothing to do with the+ engine's load-timing record. No engine anywhere in this tree emits+ such a line today (confirmed against every "loaded"-prefixed printf+ in the C sources) -- this note exists so a future line that+ genuinely collides with the prefix is a documented, expected+ refusal rather than a surprise.++ None means the line did not even share one of the two literal+ prefixes above."""if not isinstance(line, str):raise PreambleError(f"engine preamble is not text: {line!r}")