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, qwen38: the Vulkan device goes down at exit, after the tier

JustVugg05d2422708b9
diff --git a/c/qwen36.c b/c/qwen36.c
index 11a41576..3a7324b2 100644
--- a/c/qwen36.c
+++ b/c/qwen36.c
@@ -4565,6 +4565,7 @@ static void vk_tier_start(Model *m, const char *snap, int cap, int expert_is_int
if (h > 0) fprintf(stderr, "[USAGE] expert history: %lld selections (%s)\n", (long long)h, g_vk_usage);
if (!vkt_init(&vc, rt_counts_all())) { rt_destroy(); return; }
m->vk_hist = 1;
+ atexit(coli_vk_shutdown); /* runs after the tier's teardown: the device goes before the drivers unload */
atexit(vkt_shutdown);
int all = c->n_layers * c->n_experts;
int *pl = malloc((size_t)all * sizeof(int)), *pe = malloc((size_t)all * sizeof(int));
diff --git a/c/qwen38.c b/c/qwen38.c
index 4102a6f2..bba4e429 100644
--- a/c/qwen38.c
+++ b/c/qwen38.c
@@ -2487,6 +2487,7 @@ static void q38_vk_tier_start(Model *m,int cap){
if(vc.max_rows<64)vc.max_rows=64;
uint32_t **heat=rt_counts_all();
if(!vkt_init(&vc,heat))return;
+ atexit(coli_vk_shutdown); /* runs after the tier's teardown: the device goes before the drivers unload */
atexit(vkt_shutdown);
/* the warm start: the history's hottest experts, read in parallel */
int all=c->layers*c->experts,*pl=(int*)malloc((size_t)all*sizeof(int)),*pe=(int*)malloc((size_t)all*sizeof(int));
diff --git a/c/vk_tier.h b/c/vk_tier.h
index 41b29458..dc2acff2 100644
--- a/c/vk_tier.h
+++ b/c/vk_tier.h
@@ -33,7 +33,10 @@
* .ram_reserve = bytes the RAM expert cache may still grow by,
* .dense_bytes = bytes of dense weights the engine will put
* on the device after this call};
- * if (vkt_init(&c, rt_counts_all())) atexit(vkt_shutdown);
+ * if (vkt_init(&c, rt_counts_all())) {
+ * atexit(coli_vk_shutdown); // runs second: the device goes before
+ * atexit(vkt_shutdown); // the drivers unload (a driver can still
+ * } // be compiling the tier's pipelines)
*
* .in_ram (optional) lets the tier hand experts the CPU holds in RAM back to the
* CPU when the device is the slower side of a step (an integrated GPU at its