Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

resource_plan.py/doctor.py: say why a cache is pending, not "no probe yet" (#379)

monotophicd6115981411c
diff --git a/c/doctor.py b/c/doctor.py
index 092d71e2..b723d242 100644
--- a/c/doctor.py
+++ b/c/doctor.py
@@ -8,7 +8,8 @@ import re
import subprocess
from pathlib import Path
-from resource_plan import GB, build_plan, discover_gpus, format_plan, memory_available
+from resource_plan import (GB, SSD_PROBE_PENDING, build_plan, discover_gpus, format_plan,
+ memory_available)
SAFETENSORS_MAX_HEADER = 512 << 20
MODEL_INDEX_MAX_BYTES = SAFETENSORS_MAX_HEADER
@@ -512,11 +513,17 @@ def run_doctor(model, ram_gb=0, context=4096, gpu_indices=None, vram_gb=0, *,
else:
checks.append(_check("placement.plan", "pass", "tier placement has no warnings"))
# #379: read-and-display only -- the cached value colibri.c already measured
- # (F_NOCACHE probe) on a Metal+darwin startup, never re-probed here.
+ # (F_NOCACHE probe) on a Metal+darwin startup, never re-probed here. A cache
+ # that exists but is not trusted says WHY (#386 r2, F10) -- "no cached probe
+ # yet" would be a lie with a file sitting right there.
ssd_gbs = plan.get("ssd_probe_gbs")
+ ssd_state = plan.get("ssd_probe_state")
if ssd_gbs is not None:
checks.append(_check("storage.ssd_probe", "pass",
f"F_NOCACHE probe: {ssd_gbs:.1f} GB/s (cached, .coli_ssd)", gbs=ssd_gbs))
+ elif ssd_state in SSD_PROBE_PENDING:
+ checks.append(_check("storage.ssd_probe", "skip",
+ SSD_PROBE_PENDING[ssd_state], state=ssd_state))
else:
checks.append(_check("storage.ssd_probe", "skip",
"no cached probe yet; measured on the first Metal+darwin engine start"))
diff --git a/c/resource_plan.py b/c/resource_plan.py
index fa6ef49d..5197f6af 100644
--- a/c/resource_plan.py
+++ b/c/resource_plan.py
@@ -177,23 +177,54 @@ def parse_ssd_cache(data):
return (None, None, None)
-def read_ssd_probe(model_dir):
- """Read the cached F_NOCACHE storage probe the C engine writes to
+def ssd_probe_state(model_dir):
+ """Classify the cached F_NOCACHE storage probe the C engine writes to
<model>/.coli_ssd on its first Metal+darwin startup (colibri.c
coli_ssd_probe_cached, issue #379). Read-only: never re-measures, never
guesses -- mirrors S4's "read-and-display only" contract for `coli
- doctor`/`coli plan`. Returns the measured GB/s as a float, or None.
- Trust matches the engine exactly: only a v2 cache whose recorded st_dev
- still matches the model dir's volume counts -- a legacy bare number or a
- cache carried to another drive is one the engine will re-measure, so
- surfacing it here would show a number the engine no longer believes."""
+ doctor`/`coli plan`. Returns (state, gbs):
+ ("ok", gbs) v2 cache recorded on THIS volume -- the one case the
+ engine itself would trust
+ ("legacy", None) pre-v2 bare number; the engine re-probes + upgrades
+ ("foreign", None) v2 from another volume (st_dev mismatch); re-probed
+ ("garbage", None) a file exists but fails the strict grammar
+ ("absent", None) no cache file at all
+ The distinctions matter for wording (#386 r2, F10): "no cached probe yet"
+ is a lie when a file exists. The read is bounded to 65 bytes (F13): the
+ strict grammar caps a well-formed cache at 64, so byte 65 alone already
+ convicts -- no reason to slurp an arbitrarily large impostor file."""
try:
- kind, gbs, dev = parse_ssd_cache((Path(model_dir) / ".coli_ssd").read_bytes())
- if kind == "v2" and dev == os.stat(model_dir).st_dev:
- return gbs
- return None
+ with open(Path(model_dir) / ".coli_ssd", "rb") as fh:
+ data = fh.read(65)
except OSError:
- return None
+ return ("absent", None)
+ kind, gbs, dev = parse_ssd_cache(data)
+ if kind == "v2":
+ try:
+ if dev == os.stat(model_dir).st_dev:
+ return ("ok", gbs)
+ except OSError:
+ pass
+ return ("foreign", None)
+ if kind == "legacy":
+ return ("legacy", None)
+ return ("garbage", None)
+
+
+def read_ssd_probe(model_dir):
+ """The measured GB/s as a float when the engine itself would trust the
+ cache (ssd_probe_state "ok"), else None."""
+ return ssd_probe_state(model_dir)[1]
+
+
+# What doctor/plan say for a cache that exists but is not trusted (#386 r2,
+# F10): each state names what will actually happen, never "no cached probe
+# yet" while a file sits right there.
+SSD_PROBE_PENDING = {
+ "legacy": "legacy cache pending engine upgrade; re-measured on the next Metal+darwin start",
+ "foreign": "cache from another volume; the engine will re-probe here",
+ "garbage": "unreadable cache; the engine will re-probe",
+}
def discover_gpus():
@@ -561,6 +592,7 @@ def build_plan(model, ram_gb=0, context=4096, gpu_indices=None, vram_gb=0,
tune = _auto_tune(bottleneck_class, projected_hit, gpus, cpu_sockets,
plan_has_metal=False)
+ probe_state, probe_gbs = ssd_probe_state(info["path"])
return {
"version": 2,
@@ -592,9 +624,11 @@ def build_plan(model, ram_gb=0, context=4096, gpu_indices=None, vram_gb=0,
],
"warnings": warnings,
# #379: read-only surfacing of the cached Metal-cache storage probe, if
- # the engine has already measured this model dir. None before the first
- # Metal+darwin startup -- never re-measured or guessed here.
- "ssd_probe_gbs": read_ssd_probe(info["path"]),
+ # the engine has already measured this model dir. gbs is None unless
+ # the engine itself would trust the cache; the state says WHY (#386 r2,
+ # F10) -- never re-measured or guessed here.
+ "ssd_probe_gbs": probe_gbs,
+ "ssd_probe_state": probe_state,
}
@@ -667,6 +701,8 @@ def format_plan(plan):
lines.append("VRAM no NVIDIA device detected · CPU path")
if plan.get("ssd_probe_gbs") is not None:
lines.append(f"ssd {plan['ssd_probe_gbs']:.1f} GB/s F_NOCACHE (cached probe, #379)")
+ elif plan.get("ssd_probe_state") in SSD_PROBE_PENDING:
+ lines.append(f"ssd {SSD_PROBE_PENDING[plan['ssd_probe_state']]}")
lines.append(f"limit {plan['expected_bottleneck']}")
hit = plan.get("projected_hit_rate", 0)
lines.append(f"hit {hit:.0%} projected expert residency")
diff --git a/c/tests/test_doctor.py b/c/tests/test_doctor.py
index 675336a5..5d46fe8f 100644
--- a/c/tests/test_doctor.py
+++ b/c/tests/test_doctor.py
@@ -162,6 +162,24 @@ class DoctorTest(unittest.TestCase):
self.assertEqual(checks["storage.ssd_probe"]["status"], "pass")
self.assertEqual(checks["storage.ssd_probe"]["details"]["gbs"], 14.3)
+ def test_ssd_probe_wording_names_why_a_cache_is_pending(self):
+ # #386 r2, F10: "no cached probe yet" is a lie when a file exists --
+ # each untrusted state names what will actually happen instead.
+ cases = (
+ ("14.3\n", "legacy cache pending engine upgrade"),
+ (f"v2 14.3 {os.stat(self.model).st_dev + 1}\n", "cache from another volume"),
+ ("not-a-number\n", "unreadable cache"),
+ )
+ for content, expected in cases:
+ (self.model / ".coli_ssd").write_text(content)
+ check = self.checks_by_id(self.report())["storage.ssd_probe"]
+ self.assertEqual(check["status"], "skip", content)
+ self.assertIn(expected, check["summary"], content)
+ self.assertNotIn("no cached probe yet", check["summary"], content)
+ (self.model / ".coli_ssd").unlink()
+ check = self.checks_by_id(self.report())["storage.ssd_probe"]
+ self.assertIn("no cached probe yet", check["summary"])
+
def test_ssd_probe_check_never_emits_json_infinity(self):
# float("inf") used to sail through the old reader; json.dumps renders
# it as the bare literal Infinity, which is not JSON -- machine
diff --git a/c/tests/test_resource_plan.py b/c/tests/test_resource_plan.py
index 608043c0..32c208d0 100644
--- a/c/tests/test_resource_plan.py
+++ b/c/tests/test_resource_plan.py
@@ -19,6 +19,7 @@ from resource_plan import (
parse_ssd_cache,
physical_cpu_count,
read_ssd_probe,
+ ssd_probe_state,
)
@@ -151,12 +152,33 @@ class ResourcePlanTest(unittest.TestCase):
checked += 1
self.assertGreaterEqual(checked, 40, "vector file suspiciously short")
+ def test_ssd_probe_state_classifies_every_case(self):
+ # #386 r2, F10: doctor/plan wording keys off these states -- a cache
+ # that exists but is not trusted must never read "no cached probe yet".
+ self.assertEqual(ssd_probe_state(self.model), ("absent", None))
+ self._write_v2_cache("14.322")
+ self.assertEqual(ssd_probe_state(self.model), ("ok", 14.322))
+ self._write_v2_cache("14.322", dev=os.stat(self.model).st_dev + 1)
+ self.assertEqual(ssd_probe_state(self.model), ("foreign", None))
+ (self.model / ".coli_ssd").write_text("14.322\n")
+ self.assertEqual(ssd_probe_state(self.model), ("legacy", None))
+ (self.model / ".coli_ssd").write_text("inf\n")
+ self.assertEqual(ssd_probe_state(self.model), ("garbage", None))
+
def test_ssd_probe_surfaces_in_plan_and_format(self):
self._write_v2_cache("14.3")
plan = build_plan(self.model, available_memory=16 * GB, available_disk=1)
self.assertEqual(plan["ssd_probe_gbs"], 14.3)
+ self.assertEqual(plan["ssd_probe_state"], "ok")
self.assertIn("14.3 GB/s", format_plan(plan))
+ def test_ssd_probe_pending_states_surface_in_format(self):
+ (self.model / ".coli_ssd").write_text("14.3\n") # legacy
+ plan = build_plan(self.model, available_memory=16 * GB, available_disk=1)
+ self.assertIsNone(plan["ssd_probe_gbs"])
+ self.assertEqual(plan["ssd_probe_state"], "legacy")
+ self.assertIn("legacy cache pending engine upgrade", format_plan(plan))
+
def test_ssd_probe_absent_from_plan_and_format_when_not_cached(self):
plan = build_plan(self.model, available_memory=16 * GB, available_disk=1)
self.assertIsNone(plan["ssd_probe_gbs"])