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(qwen36, olmoe): the chain's pipelines come up after its fit

JustVuggd769e412760c
diff --git a/c/olmoe_chain.h b/c/olmoe_chain.h
index fa840979..f8800ce7 100644
--- a/c/olmoe_chain.h
+++ b/c/olmoe_chain.h
@@ -226,7 +226,7 @@ static int olc_bufs(OlmChain *ch, Model *m, int rows);
static void olc_fit_start(Model *m) {
Cfg *c = &m->c; int L = c->n_layers, D = c->hidden, E = c->n_experts, H = c->n_heads, hd = c->head_dim;
if (!g_vk_ready || !olc_geometry_ok(c)) return;
- if (!coli_vk_chain_decide(NULL, vkt_wanted() && E > 0, OLMOE_CHAIN_IGPU) || !vkc_init()) return;
+ if (!coli_vk_chain_decide(NULL, vkt_wanted() && E > 0, OLMOE_CHAIN_IGPU)) return;
size_t *per = calloc((size_t)L, sizeof *per), *mat = calloc((size_t)L, sizeof *mat);
if (!per || !mat) { free(per); free(mat); return; }
const char *e = getenv("COLI_VK_KV_BLOCK");
@@ -248,13 +248,12 @@ static void olc_fit_start(Model *m) {
size_t tail = m->lm_head ? vkc_fit_tensor(10, D, c->vocab, 0) : 0;
int n = vkc_fit("olmoe", L, per, mat, fixed, tail, &g_olc_fit);
free(per); free(mat);
+ /* the chain's pipelines now, after the fit read the free memory */
+ if (n > 0 && !vkc_init()) return; /* no chain after all (olc_start finds it so too): no fit */
g_olc_fit_on = 1;
for (int i = n; i < L; i++) olc_layer_cpu(NULL, m, i);
if (!g_olc_fit.tail && !m->vk_lm_head) m->vk_lm_head = &g_vk_refused;
- if (n == 0) { /* the chain off: its blocks and pipelines go, every byte is the tier's */
- vkc_shutdown();
- vkc_fit_placed("olmoe", &g_olc_fit);
- }
+ if (n == 0) vkc_fit_placed("olmoe", &g_olc_fit); /* the chain off: nothing of it on the device */
}
/* After the dense-host decision, before the tier: the chain's N layers (and the head) on
* the device now, so the tier sizes its budget from what is left. */
diff --git a/c/qwen36.c b/c/qwen36.c
index 0116e959..31fe7c95 100644
--- a/c/qwen36.c
+++ b/c/qwen36.c
@@ -5812,7 +5812,8 @@ int main(int argc, char **argv) {
"a dense model on a device sharing the CPU's RAM; COLI_VK_IMPORT=0 copies them")
: "this device cannot import host memory");
}
- if (g_vk_chain && !vkc_init()) g_vk_chain = 0;
+ /* the chain's pipelines come up with its fit (q36c_start, below): nothing of the
+ * chain is on the device before it has decided how many layers fit */
#endif
if (ref_image && ref_image->t == J_OBJ) {
jval *gh = json_get(ref_image, "grid_h"), *gw = json_get(ref_image, "grid_w");
@@ -6017,6 +6018,7 @@ int main(int argc, char **argv) {
#ifdef COLI_VULKAN
q36c_start(&m); /* COLI_VK_CHAIN: how many layers the chain places (vkc_fit), before any upload */
+ if (g_vk_chain && !g_q36c_fit_on && !vkc_init()) g_vk_chain = 0; /* no fit (PILOT, a geometry, ...): as before */
q36_dho_start(&m); /* COLI_VK_DENSE_HOST: the dense matrices on the device only, before the tier sizes its budget */
if (g_q36c_fit_on && g_vk_chain) { /* the chain's layers on the device now, so the tier sizes after them */
q36c_place(&m);
diff --git a/c/qwen36_chain.h b/c/qwen36_chain.h
index d8a895f3..d900c7f8 100644
--- a/c/qwen36_chain.h
+++ b/c/qwen36_chain.h
@@ -426,12 +426,14 @@ static void q36c_start(Model *m) {
q36c_fit_qw(&m->lm_head, &tail, &tail_m);
int n = vkc_fit("qwen36", L, per, mat, fixed, tail, &g_q36c_fit);
free(per); free(mat);
+ /* the chain's pipelines now, after the fit read the free memory: nothing of it was on
+ * the device before (vkc_init's own buffer counts in the pools' share) */
+ if (n > 0 && !vkc_init()) { g_vk_chain = 0; return; } /* no chain after all: no fit, as before */
g_q36c_fit_on = 1;
for (int i = n; i < L; i++) q36c_layer_cpu(NULL, m, i);
if (!g_q36c_fit.tail) m->lm_head.vk_off = 1;
- if (n == 0) { /* the chain off: its blocks and pipelines go, every byte is the tier's */
+ if (n == 0) { /* the chain off: nothing of it on the device, every byte is the tier's */
g_vk_chain = 0;
- vkc_shutdown();
vkc_fit_placed("qwen36", &g_q36c_fit);
}
}