Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
metal: COLI_METAL_MOE_EXACT covers all fmt=4 GPU paths (attn/layer decode + dense)
Doug Sharp36a555a721ff
diff --git a/c/colibri.c b/c/colibri.cindex fb345233..7b0af931 100644--- a/c/colibri.c+++ b/c/colibri.c@@ -99,6 +99,7 @@ static int g_metal_enabled;* single-threaded"). */static int g_metal_enabled;static int g_metal_gemm_min=16; /* COLI_METAL_GEMM_MIN: min rows to send a matmul_qt GEMM to GPU */+static int g_moe_exact=0;/* output dello shared expert gia' calcolato su GPU (solo Metal layer-CB) */static const float *g_pre_sh;#endif@@ -887,7 +888,7 @@ static void matmul_qt_ex(float *y, const float *x, QT *w, int S, int allow_idot)* fmt 1/2/4 in this build, so it fails CLOSED to the CPU branch below (matmul_fp8)* rather than being silently misread. coli_metal_gemm() also carries its own* internal fmt!=1&&fmt!=2&&fmt!=4 guard, so this is belt-and-braces. */- if(g_metal_enabled && S>=g_metal_gemm_min && !spec_pinned() && (w->fmt==1||w->fmt==2||w->fmt==4) && !omp_in_parallel()){+ if(g_metal_enabled && S>=g_metal_gemm_min && !spec_pinned() && (w->fmt==1||w->fmt==2||(w->fmt==4&&!g_moe_exact)) && !omp_in_parallel()){const void *wp = w->fmt==1 ? (const void*)w->q8 : (const void*)w->q4;if(coli_metal_gemm(y,x,wp,w->s,w->fmt,S,w->I,w->O,w->gs)) return;}@@ -3301,7 +3302,7 @@ static void attention_rows(Model *m, Layer *l, int layer, float *x, int S, int p* flow through the shared per-fmt shader. */if(g_metal_enabled && !kvs && g_absorb!=0 && (S<=4 || g_metal_prefill) && m->kv_start[layer]==0&& D==6144 && H==64 && c->q_lora==2048 && c->kv_lora==512 && c->qk_nope==192- && c->qk_rope==64 && vh==256 && (l->kv_b.fmt==2||l->kv_b.fmt==4)+ && c->qk_rope==64 && vh==256 && (l->kv_b.fmt==2||(l->kv_b.fmt==4&&!g_moe_exact))&& metal_fused_fmt_ok(l->q_a.fmt) && metal_fused_fmt_ok(l->q_b.fmt)&& metal_fused_fmt_ok(l->kv_a.fmt) && metal_fused_fmt_ok(l->o.fmt)){int sel_active = m->has_dsa && layer<c->n_layers && c->idx_type[layer] && (pos_base+S) > c->index_topk;@@ -5612,7 +5613,7 @@ static void layer_forward_rows(Model *m, Layer *l, int li, float *x, int S, intif(g_metal_enabled && !kvs && S<=4 && li<c->n_layers && l->sparse&& (g_absorb==1||(g_absorb<0&&S<=4)) && m->kv_start[li]==0&& D==6144 && c->n_heads==64 && c->q_lora==2048 && c->kv_lora==512- && c->qk_nope==192 && c->qk_rope==64 && c->v_head==256 && (l->kv_b.fmt==2||l->kv_b.fmt==4)+ && c->qk_nope==192 && c->qk_rope==64 && c->v_head==256 && (l->kv_b.fmt==2||(l->kv_b.fmt==4&&!g_moe_exact))&& c->n_experts==256 && c->topk==8 && c->n_shared==1 && c->moe_inter==2048&& metal_fused_fmt_ok(l->q_a.fmt) && metal_fused_fmt_ok(l->q_b.fmt)&& metal_fused_fmt_ok(l->kv_a.fmt) && metal_fused_fmt_ok(l->o.fmt)@@ -9387,6 +9388,7 @@ int main(int argc, char **argv){fprintf(stderr,"[METAL] mode: batched routed experts on GPU (unified-memory zero-copy)\n");if(getenv("COLI_METAL_SPIN") && atoi(getenv("COLI_METAL_SPIN"))){ coli_metal_spin_start(); fprintf(stderr,"[METAL] keep-alive spinner ON\n"); }if(getenv("COLI_METAL_GEMM_MIN")) g_metal_gemm_min=atoi(getenv("COLI_METAL_GEMM_MIN"));+ { const char *e=getenv("COLI_METAL_MOE_EXACT"); g_moe_exact=(e&&e[0]&&e[0]!='0'); }}#elseif(getenv("COLI_METAL") && atoi(getenv("COLI_METAL"))){