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

fix(registry): make the plan and the engine agree about the engine

Gawr Gura 072109b1b6465743
diff --git a/c/deepseek_v41.c b/c/deepseek_v41.c
index 2341c0aa..172ee5bd 100644
--- a/c/deepseek_v41.c
+++ b/c/deepseek_v41.c
@@ -178,6 +178,26 @@ static void cfg_load(Cfg *c, const char *snap) {
c->hc_iters = (int)jnum(t, "hc_sinkhorn_iters", 20);
c->hc_eps = (float)jnum(t, "hc_eps", 1e-6);
c->max_positions = (int)jnum(t, "max_seq_len", jnum(t, "max_position_embeddings", 4096));
+ /* CTX caps the context, and with it every buffer sized from it: the compressed
+ * KV and index keys of the four source layers, and both rope tables. Every
+ * other engine in the registry reads its own context variable (CTX, GLM53_MAXT,
+ * CTX_MAX, K3_MAXT, Q36_MAXT, Q38_MAXT); this one read none, so `coli --ctx`
+ * set CTX for the planner and the engine ignored it. The planner sizes those
+ * buffers from the context it was asked for, which at the default 4096 is
+ * 0.02 GiB against the 6.25 GiB the engine allocated for the checkpoint's
+ * 1,048,576 -- 6.23 GiB of unbudgeted allocation, and a machine planned to the
+ * number would not have it. Keeping CTX <= max_positions also means the
+ * checkpoint's own ceiling still wins: this can only ask for less. */
+ const char *ctx_env = getenv("CTX");
+ if (ctx_env && *ctx_env) {
+ int ctx = atoi(ctx_env);
+ if (ctx >= 2 && ctx < c->max_positions) c->max_positions = ctx;
+ else if (ctx >= 2)
+ fprintf(stderr, "[v41] CTX=%d is at or above the checkpoint's own ceiling "
+ "of %d positions; keeping the ceiling\n", ctx, c->max_positions);
+ else
+ fprintf(stderr, "[v41] CTX=%d is below the 2-position minimum; ignored\n", ctx);
+ }
/* YaRN, as the vendor spells it: rope_scaling.factor when present */
jval *scaling = json_get(t, "rope_scaling");
if (scaling && scaling->t == J_OBJ) {
diff --git a/c/family_registry.py b/c/family_registry.py
index a9cbb50b..19c8c3aa 100644
--- a/c/family_registry.py
+++ b/c/family_registry.py
@@ -1216,6 +1216,10 @@ FAMILIES = (
planner_id="olmoe_gqa",
planner_geometry=_olmoe_geometry,
planner_unsupported_reason="",
+ # CPU-only, and olmoe.c says so in its own serve telemetry: "CPU-only (no
+ # CUDA/Metal backend), so the GPU fields are always empty". The build rule
+ # links NOCUDA_LDFLAGS. Left at the default this advertised a VRAM tier.
+ supports_accelerator=False,
expert_inventory=_individual_expert_inventory(_GLM_EXPERT),
config_section="root",
# implicit_cap 0, not 8: the engine sizes its expert cache from the RAM
@@ -1349,6 +1353,13 @@ FAMILIES = (
planner_id="deepseek_v41",
planner_geometry=_dsv41_geometry,
planner_unsupported_reason="",
+ # CPU-only: the engine links no CUDA/Metal/Vulkan path and its build rule
+ # carries no backend object, so the planner must not offer a VRAM tier it
+ # cannot execute. Left at the default True it wrote "VRAM 296.0 GB hot
+ # tier ... 100% projected expert residency" into `coli plan` for this
+ # model; resource_plan.py:945 is the gate and says the same thing in
+ # words ("a CPU-only engine has no VRAM tier").
+ supports_accelerator=False,
expert_inventory=_dsv41_expert_inventory,
resident_inventory=_dsv41_resident_inventory,
config_section="text_config",
diff --git a/c/tests/test_registry_engine_agreement.py b/c/tests/test_registry_engine_agreement.py
new file mode 100644
index 00000000..d90e931c
--- /dev/null
+++ b/c/tests/test_registry_engine_agreement.py
@@ -0,0 +1,80 @@
+"""The plan and the engine have to agree about the engine.
+
+Both checks here are the same defect in two costumes: a shared mechanism that
+every engine (or the planner) adopted and one engine did not, with no error at
+the point of divergence.
+
+ * `context_env` -- every family declares the environment variable that caps its
+ context, `coli --ctx` sets it, and resource_plan.py sizes the buffers it
+ implies from that number. deepseek_v41 read none of them, so the planner
+ budgeted 0.02 GiB of compressed KV and index keys where the engine allocated
+ 6.25 GiB for the checkpoint's own 1,048,576-position ceiling.
+
+ * `supports_accelerator` -- resource_plan.py refuses a VRAM budget and drops
+ the GPUs for a CPU-only engine, with a comment saying that announcing a tier
+ nobody can execute is worse than saying nothing. The flag defaults to True,
+ so an engine has to opt out, and the two CPU-only engines did not: `coli
+ plan` offered DeepSeek V4.1 a "296.0 GB hot tier ... 100% projected expert
+ residency" on eight H200s it cannot address.
+
+The accelerator check derives "CPU-only" from the build rule rather than from a
+list, so it cannot rot: an engine whose link line carries no backend object is
+CPU-only, and the registry has to say so.
+"""
+import re
+import sys
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parent.parent
+sys.path.insert(0, str(ROOT))
+
+import family_registry as fr # noqa: E402
+
+
+BACKEND_OBJECTS = ("CUDA_OBJ", "METAL_OBJ", "VK_OBJ", "VK_SPV", "INK_CUDA_OBJ",
+ "QWEN36_TIER_SRC")
+
+
+def engine_rule(artifact: str) -> str:
+ """The Makefile prerequisites and recipe for one engine, or ''."""
+ makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
+ match = re.search(rf"^{re.escape(artifact)}\$\(EXE\):.*?(?=\n\S|\Z)",
+ makefile, re.M | re.S)
+ return match.group(0) if match else ""
+
+
+class RegistryEngineAgreementTest(unittest.TestCase):
+ def test_every_engine_reads_its_declared_context_variable(self):
+ for family in fr.FAMILIES:
+ with self.subTest(family=family.id):
+ env = family.limits.context_env
+ source = (ROOT / f"{family.engine_artifact}.c").read_text(
+ encoding="utf-8", errors="replace")
+ self.assertTrue(
+ f'getenv("{env}")' in source,
+ f"{family.id} declares context_env={env!r} but "
+ f"{family.engine_artifact}.c never reads it, so `coli --ctx` "
+ f"is silently ignored and the planner and the engine disagree "
+ f"about how much state the context costs")
+
+ def test_a_cpu_only_engine_does_not_claim_an_accelerator(self):
+ for family in fr.FAMILIES:
+ if family.engine_artifact == "deepseek_v4":
+ continue # built by Makefile.deepseek-v4, linked with the CUDA tier
+ with self.subTest(family=family.id):
+ rule = engine_rule(family.engine_artifact)
+ self.assertTrue(rule, f"no Makefile rule for {family.engine_artifact}")
+ has_backend = any(obj in rule for obj in BACKEND_OBJECTS)
+ self.assertEqual(
+ has_backend, family.supports_accelerator,
+ f"{family.id}: the build rule "
+ f"{'links' if has_backend else 'links no'} backend object but the "
+ f"registry says supports_accelerator="
+ f"{family.supports_accelerator}; the planner trusts the registry, "
+ f"so the two have to agree")
+
+
+if __name__ == "__main__":
+ unittest.main()