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

coli: apply the plan's VRAM tier on the sibling path, not just report it (#1581)

JustVugg28959fa1a6fb
diff --git a/c/coli b/c/coli
index 7082b4dc..e8ad444f 100755
--- a/c/coli
+++ b/c/coli
@@ -577,20 +577,18 @@ def env_for_engine(a, arch, plan=None):
ram,ctx,devices,vram=resource_request(a,env)
plan=build_plan(a.model,ram,ctx,devices,vram,policy=a.policy,
kv_slots=requested_kv_slots(a,env))
- # Preserve the existing non-GLM GPU contract: explicit --gpu/--vram
- # selects a capable build above. Merely asking for auto-tier must not
- # turn a CPU-only sibling binary into an attempted CUDA launch.
plan_must_not_choose_omp=("OMP_NUM_THREADS" not in env
and (arch == "deepseek_v4"
or env.get("COLI_NO_OMP_TUNE")))
- cuda_on = env.get("COLI_CUDA") == "1"
+ gpu_off_by_request = env.get("COLI_CUDA") == "0"
+ cuda_on = plan_cuda_enabled(a, arch, env)
env=environment_for_plan(plan,env,cuda_enabled=cuda_on)
except (OSError,ValueError,json.JSONDecodeError) as error:
sys.exit(f"{C.yel}invalid resource plan:{C.r} {error}")
# Outside the try on purpose: this only prints, and a display helper
# that stumbled inside it would be reported as "invalid resource plan"
# and take the launch down with it.
- if not cuda_on: report_unapplied_vram_tier(plan)
+ if not cuda_on: report_unapplied_vram_tier(plan, gpu_off_by_request)
if plan_must_not_choose_omp:
# environment_for_plan supplies the physical-core default used by
# the other engines. V4 deliberately computes logical CPUs minus
@@ -706,23 +704,52 @@ def requested_kv_slots(a, env):
if value is None: value=int(env.get("COLI_KV_SLOTS","1"))
return value
-def report_unapplied_vram_tier(plan):
- """Say so when --auto-tier keeps a real VRAM tier out of the launch.
+def plan_cuda_enabled(a, arch, env):
+ """Should --auto-tier apply the VRAM tier that `coli plan` printed?
+
+ Yes exactly when the engine that is about to run was built with a GPU
+ backend, which is the question the GLM path has always asked
+ (`has_cuda=cuda_binary()`), and which is what --auto-tier documents: apply
+ the plan.
+
+ The sibling path used to answer a narrower question -- "did the user pass
+ --gpu or --vram" -- and the comment that guarded it was right at the time:
+ cuda_binary() could only inspect the GLM binary, so a perfectly good qwen36
+ CUDA build looked CPU-only to it and auto-tier had to assume the worst
+ rather than risk launching a CPU-only sibling as a CUDA one. Since #1533
+ the check takes the engine that will actually run, so the thing that
+ contract was protecting against can be TESTED instead of assumed, and
+ assuming it costs the user the tier they were just shown. On the box in
+ #1581 that was 11.8 tok/s against 21, with nothing on screen to explain it.
+
+ A CPU-only build still never gets a CUDA launch: that is what the check
+ below says. `--gpu none` (COLI_CUDA=0) is still the off switch, and an
+ explicit --gpu/--vram has already proved the build before we get here.
+ """
+ value = env.get("COLI_CUDA")
+ if value == "1": return True # --gpu / --vram validated the build above
+ if value == "0": return False # --gpu none, or the user set it by hand
+ # DeepSeek V4 links its tier differently on each platform, so it has its own
+ # probe; using cuda_binary() here would reject valid V4 CUDA builds (#1219).
+ if arch == "deepseek_v4": return dsv4_cuda_available(getattr(a, "model", None))
+ return cuda_binary(engine_for_gpu_check(a))
+
+
+def report_unapplied_vram_tier(plan, gpu_off_by_request=False):
+ """Say so when a real VRAM tier from the plan is not going into the launch.
- Dropping it is deliberate, and the contract above explains why: --gpu and
- --vram are what select a CUDA-capable build, so merely asking for the plan
- must never turn a CPU-only sibling binary into an attempted CUDA launch.
+ After plan_cuda_enabled() there are only two ways to get here, and the user
+ can act on exactly one of them, so the notice says which: the GPU was turned
+ off by request, or the engine binary has no GPU backend to turn on.
- Doing it in SILENCE was not deliberate. `coli plan` and `coli doctor` print
- the VRAM tier as part of the plan, --auto-tier is documented as applying
- that plan, and then the tier vanishes with nothing on screen to connect the
- two. On the box in #1581 the silence cost most of the throughput -- 11.8
- tok/s became 21 once --gpu auto was added -- and the user had no way to see
- that the plan they had just read was not the plan that ran.
+ Being told matters because `coli plan` and `coli doctor` print the VRAM tier
+ as part of the plan and --auto-tier is documented as applying that plan. In
+ #1581 the tier vanished with nothing on screen connecting the two, and the
+ reporter only found it by watching nvidia-smi.
The test for "real" is the planner's own: a device qualified to drive
- placement, and a budget above zero. Anything else was already not going to
- be applied with the GPU on either, and saying so would be noise.
+ placement, and a budget above zero. Anything else was not going to be
+ applied with the GPU on either, and saying so would be noise.
"""
try:
from resource_plan import plans_placement, GB
@@ -734,11 +761,14 @@ def report_unapplied_vram_tier(plan):
if not devices or budget <= 0:
return
where = ", ".join(f"{d['index']}:{d.get('name') or 'GPU'}" for d in devices)
+ why = ("--gpu none turns the GPU off, so the tier is not applied. Drop it "
+ "to use the plan as printed."
+ if gpu_off_by_request else
+ "the engine binary has no GPU backend, so there is nothing to apply "
+ "it with. Rebuild the engine with CUDA=1 to use it.")
print(f" {C.yel}[PLAN] the plan's VRAM tier is not being applied{C.r}\n"
- f" {C.dim}{budget / GB:.1f} GB on {where} stays unused. --auto-tier "
- f"applies the RAM plan but never enables the GPU by itself, so a "
- f"CPU-only build is never launched as a CUDA one. Add --gpu auto "
- f"(or --vram N) to use it.{C.r}", file=sys.stderr)
+ f" {C.dim}{budget / GB:.1f} GB on {where} stays unused: {why}{C.r}",
+ file=sys.stderr)
def env_for(a):
diff --git a/c/tests/test_auto_tier_vram_notice.py b/c/tests/test_auto_tier_vram_notice.py
index c86280fd..b3754eb2 100644
--- a/c/tests/test_auto_tier_vram_notice.py
+++ b/c/tests/test_auto_tier_vram_notice.py
@@ -1,21 +1,25 @@
-"""--auto-tier must say when it is leaving the plan's VRAM tier on the floor.
-
-Dropping the tier without --gpu is the contract and stays the contract: --gpu
-and --vram are what select a CUDA-capable build, so asking for a plan must not
-turn a CPU-only sibling binary into an attempted CUDA launch.
-
-Doing it in silence was the defect. `coli plan` and `coli doctor` print the
-VRAM tier, --auto-tier says it applies the plan, and the tier then disappears
-with nothing on screen tying the two together -- which on the box in #1581 was
-the difference between 11.8 and 21 tok/s with no clue as to why.
-
-So this checks two things and they pull in opposite directions: the notice
-appears when the tier was real, and stays quiet when it was not. A warning that
-fires on every CPU-only launch is a warning people learn to scroll past.
-
-It also checks that a plan of the wrong shape prints nothing and raises
-nothing. This function only writes to a terminal; it must never be the reason a
-launch fails.
+"""--auto-tier must apply the VRAM tier it printed, or say why it cannot.
+
+`coli plan` and `coli doctor` print a VRAM tier. --auto-tier is documented as
+applying the plan those commands print. On the sibling-engine path it then
+dropped the tier whenever COLI_CUDA was not already "1", which --auto-tier on
+its own never sets, and it dropped it in silence: no [PLAN] line, no [CUDA]
+banner, just half the throughput. On the box in #1581, 11.8 tok/s against 21.
+
+The drop was deliberate once. cuda_binary() could only inspect the GLM binary,
+so a working qwen36 CUDA build looked CPU-only to it and the safe move was to
+require an explicit flag rather than risk launching a CPU-only sibling as a
+CUDA one. Since #1533 the check takes the engine that will actually run, so
+that risk is testable rather than assumed -- which is what these tests pin
+down, in both directions:
+
+ * a GPU build gets the tier without a flag, like the GLM path always has;
+ * a CPU-only build still does not, and is told so;
+ * --gpu none still wins over everything, and is told so differently, because
+ it is the one of the two the user can undo by dropping a flag.
+
+And the notice stays quiet when the tier was not real. A warning that fires on
+every CPU-only launch is a warning people learn to scroll past.
"""
import contextlib
import importlib.machinery
@@ -34,14 +38,19 @@ coli = importlib.util.module_from_spec(_spec)
_loader.exec_module(coli)
+class Args:
+ def __init__(self, model="/models/qwen36"):
+ self.model = model
+
+
def plan(devices, budget_bytes):
return {"tiers": {"vram": {"devices": devices, "budget_bytes": budget_bytes}}}
-def notice_for(p):
+def notice_for(p, gpu_off_by_request=False):
err = io.StringIO()
with contextlib.redirect_stderr(err):
- coli.report_unapplied_vram_tier(p)
+ coli.report_unapplied_vram_tier(p, gpu_off_by_request)
return err.getvalue()
@@ -49,13 +58,79 @@ QUALIFIED = [{"index": 0, "name": "NVIDIA GeForce RTX 4060 Ti",
"free_bytes": 8 * 1000 ** 3}]
+class PlanCudaEnabledTest(unittest.TestCase):
+ """Which binary gets asked, and who wins when answers disagree."""
+
+ def setUp(self):
+ self.asked = []
+ self._cuda_binary = coli.cuda_binary
+ self._engine_for_gpu_check = coli.engine_for_gpu_check
+ self._dsv4 = coli.dsv4_cuda_available
+ coli.engine_for_gpu_check = lambda a: "/build/qwen36"
+
+ def tearDown(self):
+ coli.cuda_binary = self._cuda_binary
+ coli.engine_for_gpu_check = self._engine_for_gpu_check
+ coli.dsv4_cuda_available = self._dsv4
+
+ def gpu_build(self, answer):
+ def probe(engine=None):
+ self.asked.append(engine)
+ return answer
+ coli.cuda_binary = probe
+
+ def test_a_gpu_build_gets_the_tier_without_a_flag(self):
+ """The defect in #1581: this used to be False, so the plan the user had
+ just read was not the plan that ran."""
+ self.gpu_build(True)
+ self.assertTrue(coli.plan_cuda_enabled(Args(), "qwen36", {}))
+ self.assertEqual(self.asked, ["/build/qwen36"],
+ "the family's own binary must be the one inspected; "
+ "asking colibri.exe about a qwen36 run is #1533")
+
+ def test_a_cpu_only_build_still_does_not(self):
+ self.gpu_build(False)
+ self.assertFalse(coli.plan_cuda_enabled(Args(), "qwen36", {}))
+
+ def test_gpu_none_wins_over_a_gpu_build(self):
+ """COLI_CUDA=0 is what --gpu none sets, and it is the off switch."""
+ self.gpu_build(True)
+ self.assertFalse(coli.plan_cuda_enabled(Args(), "qwen36", {"COLI_CUDA": "0"}))
+ self.assertEqual(self.asked, [], "an explicit off needs no probe")
+
+ def test_an_explicit_gpu_flag_is_taken_at_its_word(self):
+ """--gpu/--vram already validated the build and exited if it was not
+ capable; probing again could only disagree with a decision made."""
+ self.gpu_build(False)
+ self.assertTrue(coli.plan_cuda_enabled(Args(), "qwen36", {"COLI_CUDA": "1"}))
+ self.assertEqual(self.asked, [])
+
+ def test_deepseek_v4_uses_its_own_probe(self):
+ """V4 links the tier differently per platform; cuda_binary() would
+ reject valid V4 CUDA builds (#1219)."""
+ self.gpu_build(False)
+ seen = []
+ coli.dsv4_cuda_available = lambda model=None: (seen.append(model), True)[1]
+ self.assertTrue(coli.plan_cuda_enabled(Args("/models/v4"), "deepseek_v4", {}))
+ self.assertEqual(seen, ["/models/v4"])
+ self.assertEqual(self.asked, [], "the generic probe must not be used for V4")
+
+
class VramNoticeTest(unittest.TestCase):
- def test_a_real_tier_is_announced(self):
+ def test_a_cpu_only_build_is_told_what_is_missing(self):
out = notice_for(plan(QUALIFIED, 5_200_000_000))
self.assertIn("VRAM tier", out)
self.assertIn("5.2 GB", out, "the notice should say how much is unused")
self.assertIn("NVIDIA GeForce RTX 4060 Ti", out, "and on which device")
- self.assertIn("--gpu auto", out, "and what to do about it")
+ self.assertIn("CUDA=1", out, "and what would fix it")
+
+ def test_gpu_none_is_told_something_it_can_act_on(self):
+ """Dropping a flag and rebuilding an engine are not the same advice."""
+ out = notice_for(plan(QUALIFIED, 5_200_000_000), gpu_off_by_request=True)
+ self.assertIn("--gpu none", out)
+ self.assertNotIn("CUDA=1", out,
+ "telling someone to rebuild when they asked for no GPU "
+ "sends them to fix something that is not broken")
def test_an_unqualified_device_is_not_worth_a_warning(self):
"""free_bytes None means the planner never qualified that memory as a