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

qwen36 on Windows: the CUDA_DLL build gets the tier, links, and is recognised

JustVugg3a0142acc7f5
diff --git a/c/Makefile b/c/Makefile
index 893b3096..75010ee2 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -1058,11 +1058,11 @@ olmoe$(EXE): olmoe.c cli_args.h st.h json.h compat.h sample.h tok.h tok_unicode.
# -DCOLI_CUDA and linking -lcudart for a build that calls neither only made
# `make qwen36` depend on a toolkit it never touches. With CUDA=1 the tier is
# real CUDA and takes the normal flags back.
-ifeq ($(CUDA),1)
-QWEN36_TIER_SRC = qwen36_tier.c
-QWEN36_CFLAGS = $(CFLAGS)
-QWEN36_LDFLAGS = $(LDFLAGS)
-else ifeq ($(HIP),1)
+# CUDA_DLL=1 / HIP_DLL=1 are the Windows spellings (CUDA=1 is refused there):
+# the tier compiles in through the runtime loader exactly as it does through
+# the direct link, or `make qwen36.exe CUDA_DLL=1` silently produced a CPU-only
+# engine (#1533).
+ifneq (,$(filter 1,$(CUDA) $(CUDA_DLL) $(HIP) $(HIP_DLL)))
QWEN36_TIER_SRC = qwen36_tier.c
QWEN36_CFLAGS = $(CFLAGS)
QWEN36_LDFLAGS = $(LDFLAGS)
diff --git a/c/backend_loader.c b/c/backend_loader.c
index 1f0bcf77..6932c649 100644
--- a/c/backend_loader.c
+++ b/c/backend_loader.c
@@ -62,6 +62,7 @@
typedef int (*fn_init)(const int *devices, int count);
typedef void (*fn_shutdown)(void);
typedef int (*fn_device_count)(void);
+typedef int (*fn_available_device_count)(void);
typedef int (*fn_device_at)(int index);
typedef int (*fn_mem_info)(int device, size_t *free_bytes, size_t *total_bytes);
typedef int (*fn_device_integrated)(int device);
@@ -159,6 +160,7 @@ static struct {
fn_init init;
fn_shutdown shutdown;
fn_device_count device_count;
+ fn_available_device_count available_device_count;
fn_device_at device_at;
fn_mem_info mem_info;
fn_device_integrated device_integrated;
@@ -1403,6 +1405,7 @@ static int coli_cuda_load(void){
RESOLVE(init, fn_init)
RESOLVE(shutdown, fn_shutdown)
RESOLVE(device_count, fn_device_count)
+ RESOLVE(available_device_count, fn_available_device_count)
RESOLVE(device_at, fn_device_at)
RESOLVE(mem_info, fn_mem_info)
/* Optional: a DLL predating #653 leaves this NULL; the wrapper then reports
@@ -1513,6 +1516,14 @@ int coli_cuda_device_count(void){
return g_cuda.device_count();
}
+/* qwen36_tier.c's device selection asks for the usable count; the loader had
+ * no wrapper for it, so the first CUDA_DLL build of qwen36 that compiled the
+ * tier in failed to link (#1533). */
+int coli_cuda_available_device_count(void){
+ if(!g_cuda.available) return 0;
+ return g_cuda.available_device_count();
+}
+
int coli_cuda_device_at(int index){
if(!g_cuda.available) return -1;
return g_cuda.device_at(index);
diff --git a/c/coli b/c/coli
index 730595fc..967ce32a 100755
--- a/c/coli
+++ b/c/coli
@@ -544,7 +544,7 @@ def env_for_engine(a, arch, plan=None):
if arch == "deepseek_v4":
if not dsv4_cuda_available(a.model):
sys.exit(f"{C.yel}--gpu needs the CUDA build:{C.r} {dsv4_cuda_build_hint()}")
- elif not cuda_binary():
+ elif not cuda_binary(engine_for_gpu_check(a)):
sys.exit(f"{C.yel}--gpu needs the CUDA build:{C.r} the engine binary is CPU-only")
env["COLI_CUDA"] = "1"
if gpu != "auto":
@@ -554,7 +554,7 @@ def env_for_engine(a, arch, plan=None):
if arch == "deepseek_v4":
if not dsv4_cuda_available(a.model):
sys.exit(f"{C.yel}--vram needs the CUDA build:{C.r} {dsv4_cuda_build_hint()}")
- elif not cuda_binary():
+ elif not cuda_binary(engine_for_gpu_check(a)):
sys.exit(f"{C.yel}--vram needs the CUDA build:{C.r} the engine binary is CPU-only")
env["COLI_CUDA"] = "1"
env["CUDA_EXPERT_GB"] = str(vram)
@@ -636,11 +636,24 @@ def need_worker_model(model):
build=f"make -C c {family.build_target}")
return engine
-def cuda_binary():
- if not os.path.exists(GLM): return False
+def engine_for_gpu_check(a):
+ """The family's engine path for cuda_binary(), or None (the GLM default)
+ when the model cannot be resolved here: the check must not turn a missing
+ config.json into a different error than the one need_model() gives."""
+ model = getattr(a, "model", None)
+ if not model: return None
+ try: return engine_for(model)
+ except (FamilyConfigError, UnknownFamilyError, OSError): return None
+
+def cuda_binary(engine=None):
+ """Was `engine` (default: the GLM binary) built with the GPU backend?
+ Callers that know the family pass its engine: checking colibri.exe for a
+ qwen36 run refused --gpu on a correct qwen36 CUDA build (#1533)."""
+ engine = engine or GLM
+ if not os.path.exists(engine): return False
if sys.platform == "linux":
try:
- linked=subprocess.run(["ldd",GLM],capture_output=True,text=True,timeout=3)
+ linked=subprocess.run(["ldd",engine],capture_output=True,text=True,timeout=3)
# Detect both CUDA (libcudart) and HIP (libamdhip64) builds.
return any(("libcudart" in line or "libamdhip64" in line) and "not found" not in line
for line in linked.stdout.splitlines())
@@ -652,9 +665,9 @@ def cuda_binary():
# marker string baked into glm.c's #ifdef COLI_CUDA block instead, and require
# coli_cuda.dll to actually sit next to glm.exe (else CUDA init fails at startup).
try:
- with open(GLM,"rb") as f: built=b"[CUDA] mode: routed experts" in f.read()
+ with open(engine,"rb") as f: built=b"[CUDA] mode: routed experts" in f.read()
except OSError: return False
- return built and os.path.exists(os.path.join(os.path.dirname(GLM),"coli_cuda.dll"))
+ return built and os.path.exists(os.path.join(os.path.dirname(engine),"coli_cuda.dll"))
return False
def resource_request(a, env):
diff --git a/c/qwen36_tier.c b/c/qwen36_tier.c
index 91b316e2..e06c2de6 100644
--- a/c/qwen36_tier.c
+++ b/c/qwen36_tier.c
@@ -720,6 +720,11 @@ int qt_init(int nl, int ne, int D, int Ih, int cap, int topk, int expert_gs,
G.on=1;
fprintf(stderr,"[qtier] CUDA VRAM expert tier active: %d device(s), %.2f MB/expert\n",
G.ndev, G.exp_bytes/1048576.0);
+ /* The launcher and coli doctor recognise a Windows CUDA_DLL build by this
+ * literal in the binary (they cannot read an import table for a DLL
+ * loaded at run time); without it a working GPU build of this engine read
+ * as CPU-only and --gpu was refused (#1533). */
+ fprintf(stderr,"[CUDA] mode: routed experts (qwen36 VRAM tier)\n");
return 1;
}
diff --git a/c/tests/test_cuda_binary_engine.py b/c/tests/test_cuda_binary_engine.py
new file mode 100644
index 00000000..6130cf44
--- /dev/null
+++ b/c/tests/test_cuda_binary_engine.py
@@ -0,0 +1,56 @@
+"""#1533: cuda_binary() must inspect the engine that will run, not always the
+GLM binary. On Windows a CUDA_DLL build is recognised by a marker string in
+the executable plus coli_cuda.dll next to it; a qwen36 build that carries
+both must pass even when colibri.exe is CPU-only or absent."""
+import importlib.machinery
+import importlib.util
+import os
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+from unittest import mock
+
+CLI = Path(__file__).resolve().parent.parent / "coli"
+
+
+def load_cli():
+ loader = importlib.machinery.SourceFileLoader("coli_cuda_binary_t", str(CLI))
+ spec = importlib.util.spec_from_loader(loader.name, loader)
+ module = importlib.util.module_from_spec(spec)
+ argv = sys.argv
+ sys.argv = ["coli"]
+ try:
+ loader.exec_module(module)
+ finally:
+ sys.argv = argv
+ return module
+
+
+class CudaBinaryEngineTest(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.m = load_cli()
+
+ def test_windows_probe_reads_the_given_engine(self):
+ with tempfile.TemporaryDirectory() as d:
+ qwen = Path(d) / "qwen36.exe"
+ qwen.write_bytes(b"MZ...[CUDA] mode: routed experts (qwen36 VRAM tier)...")
+ (Path(d) / "coli_cuda.dll").write_bytes(b"MZ")
+ glm = Path(d) / "colibri.exe"
+ glm.write_bytes(b"MZ cpu only")
+ with mock.patch.object(self.m.sys, "platform", "win32"), \
+ mock.patch.object(self.m, "GLM", str(glm)):
+ self.assertTrue(self.m.cuda_binary(str(qwen)))
+ self.assertFalse(self.m.cuda_binary()) # the default is still the GLM binary
+ self.assertFalse(self.m.cuda_binary(str(glm)))
+ (Path(d) / "coli_cuda.dll").unlink()
+ with mock.patch.object(self.m.sys, "platform", "win32"):
+ self.assertFalse(self.m.cuda_binary(str(qwen)), "no DLL next to the engine")
+
+ def test_missing_engine_is_false(self):
+ self.assertFalse(self.m.cuda_binary("/no/such/engine"))
+
+
+if __name__ == "__main__":
+ unittest.main()