Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
qwen36 tier: dnout follows its layer's dnproj under auto; COLI_PLACE experts=all
kreuzzelg764a7b9bca74
diff --git a/c/qwen36_tier.c b/c/qwen36_tier.cindex 37effa41..ad1f2f4d 100644--- a/c/qwen36_tier.c+++ b/c/qwen36_tier.c@@ -248,6 +248,7 @@ static struct {static int G_place_n = 0, G_place_done = 0;/* one component spec: "cpu" | "<dev>" | "<dev>:<n>+<dev>:<n>..." */+#define QT_PLACE_ALL (-2) /* only meaningful for "experts" */static void place_add(const char *name, size_t nlen, const char *spec){if(G_place_n >= QT_PLACE_MAX) return;if(nlen >= sizeof(G_place[0].name)) nlen = sizeof(G_place[0].name)-1;@@ -258,6 +259,7 @@ static void place_add(const char *name, size_t nlen, const char *spec){while(*p==' ') p++;int dev, count = -1;if(!strncmp(p,"cpu",3)){ dev = QT_PLACE_CPU; p += 3; }+ else if(!strncmp(p,"all",3)){ dev = QT_PLACE_ALL; p += 3; } /* experts=all: every COLI_GPUS card, reserved or not */else { dev = atoi(p); while(*p && *p!=':' && *p!='+') p++; }if(*p==':'){ count = atoi(p+1); p++; while(*p && *p!='+') p++; }G_place[G_place_n].seg[ns].dev = dev;@@ -463,6 +465,11 @@ static void auto_place(int nl, int ne, int topk, const size_t *capacity, const usize_t bytes = G_offer[o].bytes;int di = 0;for(int i = 1; i < G.ndev; i++) if(room[i] > room[di]) di = i;+ /* a layer's out_proj goes where its in_proj went when that card has+ * the room: with both on one device the whole DeltaNet layer can run+ * there (qt_dn_gpu_init), which is worth more than balancing bytes */+ if(!strcmp(G_offer[o].name, "dnout") && G_offer[o].layer < QT_DN_MAX_LAYERS && G_auto_dnp[G_offer[o].layer] != QT_PLACE_CPU)+ for(int i = 0; i < G.ndev; i++) if(G.dev[i] == G_auto_dnp[G_offer[o].layer] && room[i] >= bytes) di = i;if(room[di] < bytes){ kept++; continue; }int k = (int)((bytes + G.exp_bytes - 1) / G.exp_bytes);double pm = 0;@@ -702,7 +709,11 @@ int qt_init(int nl, int ne, int D, int Ih, int cap, int topk, int expert_gs,* -- including the slow card, whose take() paces every layer (the* measured reason asymmetric expert placement lost). */int ed=qt_place_of("experts",0);- if(ed!=QT_PLACE_CPU){+ if(ed==QT_PLACE_ALL){+ /* experts=all: every COLI_GPUS card keeps its experts, reserved or+ * not -- the form for "trunk on the fast card, experts on both" */+ fprintf(stderr,"[place] experts=all -> Experten auf allen %d Karten, auch den reservierten\n",G.ndev);+ } else if(ed!=QT_PLACE_CPU){int present=0; for(int i=0;i<G.ndev;i++) if(G.dev[i]==ed) present=1;if(present){G.dev[0]=ed; G.ndev=1;diff --git a/c/tests/test_qwen36_tier_autoplace.c b/c/tests/test_qwen36_tier_autoplace.cindex 790b2214..5d2cf996 100644--- a/c/tests/test_qwen36_tier_autoplace.c+++ b/c/tests/test_qwen36_tier_autoplace.c@@ -184,6 +184,34 @@ int main(void) {check(qt_place_of("lmhead", 0) == QT_PLACE_CPU && G.budget[0] == 64 * MiB, "no offers: nothing placed, full budget");qt_shutdown();+ /* ---- 8. auto, two devices: a layer's dnout follows its dnproj ---- */+ printf(" 8. auto, dnout follows dnproj\n");+ fresh("", "0,1", 2, "0.0625");+ qt_trunk_offer("lmhead", 0, 10 * MiB); /* dev0: 54 left */+ qt_trunk_offer("dnproj", 0, 20 * MiB); /* most room -> dev1: 44 left */+ qt_trunk_offer("dnout", 0, 2 * MiB); /* greedy would say dev0 (54 > 44) */+ qt_trunk_offer("dnout", 1, 2 * MiB); /* layer 1 has no dnproj on a card: greedy */+ check(start(8, 16, 4), "tier starts on two fake devices");+ check(qt_place_of("dnproj", 0) == 1, "the projection went to the device with the most room");+ check(qt_place_of("dnout", 0) == 1, "its out_proj followed it, so the whole layer can run on one card");+ check(qt_place_of("dnout", 1) == 0, "an out_proj without a placed in_proj is still placed by room");+ check(G.budget[1] == 64 * MiB - 22 * MiB && G.budget[0] == 64 * MiB - 12 * MiB, "both budgets charge what landed on them");+ qt_shutdown();++ /* ---- 9. experts=all keeps every card for the experts despite a reservation ---- */+ printf(" 9. experts=all\n");+ fresh("lmhead=0,dnproj=0", "0,1", 2, "0.0625");+ qt_trunk_offer("lmhead", 0, 10 * MiB);+ check(start(8, 16, 4), "tier starts with device 0 reserved for the trunk");+ check(G.ndev == 1 && G.dev[0] == 1, "without experts=all the reserved card hands its experts to the other (#1361)");+ qt_shutdown();+ fresh("lmhead=0,dnproj=0,experts=all", "0,1", 2, "0.0625");+ qt_trunk_offer("lmhead", 0, 10 * MiB);+ check(start(8, 16, 4), "tier starts with experts=all");+ check(G.ndev == 2, "experts=all: both cards keep their experts, the reserved one included");+ check(qt_place_of("experts", 0) == QT_PLACE_ALL, "experts=all parses to the all marker");+ qt_shutdown();+if (fails) { printf("test_qwen36_tier_autoplace: %d failure(s)\n", fails); return 1; }printf("test_qwen36_tier_autoplace: ok\n");return 0;