Run frontier MoE models on hardware you already own β pure C, zero deps, experts streamed from disk. Tiny engine, immense model. π¦
C
fix(qwen36 tier): drive the production offer path in the test (#1391)
Petteri Kosonen13157f00d588
diff --git a/c/qwen36.c b/c/qwen36.cindex 54b58736..eda6747b 100644--- a/c/qwen36.c+++ b/c/qwen36.c@@ -959,6 +959,21 @@ static int g_expert_gs = 0; /* set from qwen36_meta.json (expert_gs) at load ** Same signal main's nbytes probe and tier_warmstart receive; the decode path* needs it to offer int8 experts (#1391): on an int8 container e->g4 is NULL. */static int g_expert_is_int4 = 1;++/* The single offer decision the decode path makes for a routed expert: offer+ * whichever format the container actually packed, exactly what tier_warmstart+ * does (int4 β the packed g4/u4/d4, int8 β the live RAM weights, tier fmt=1+ * since #1334). moe()'s resident offer, the pilot-prefetch lookahead, and the+ * #1391 test all call THIS function, so the gate can't drift between them.+ * Read-only: never frees, never rewrites -- ownership stays in warmstart+ * (#1341). */+static void tier_offer_slot(int layer, int eid, const Slot *s) {+ if (s->g4)+ qt_note(layer, eid, s->g4, s->u4, s->d4, s->gs, s->us, s->ds);+ else if (!g_expert_is_int4 && s->g)+ qt_note(layer, eid, (const uint8_t *)s->g, (const uint8_t *)s->u,+ (const uint8_t *)s->d, s->gs, s->us, s->ds);+}static void matmul_q_gs(float *y, const float *x, const int8_t *q, const float *scale,int I, int O, int gs) {int ng = (I + gs - 1) / gs;@@ -1973,14 +1988,9 @@ static void moe(Model *m, Layer *l, int layer, float *x, int S, float *out) {/* Offer whichever format the container actually packed. The old* gate `if (e->g4)` never fired on an int8 container (g4 is* NULL there), so the tier stayed at 0 uploads for the life of- * the process (#1391). Same pointer choice tier_warmstart- * makes: int4 β packed, int8 β the weights themselves. The- * priority on g4 first keeps mid-flight format flips harmless. */- if (e->g4)- qt_note(layer, idx[kk], e->g4, e->u4, e->d4, e->gs, e->us, e->ds);- else if (!g_expert_is_int4 && e->g)- qt_note(layer, idx[kk], (const uint8_t *)e->g, (const uint8_t *)e->u,- (const uint8_t *)e->d, e->gs, e->us, e->ds);+ * the process (#1391). tier_offer_slot is the shared decision:+ * same pointer choice tier_warmstart makes, one place. */+ tier_offer_slot(layer, idx[kk], e);}double _q0 = tm_now();uint32_t qmask = qt_issue(layer, idx, K, xs);@@ -2387,12 +2397,8 @@ static void pilot_prefetch(Model *m, int lnext, const float *x, int S) {Slot *ps = &lc->slots[fz];/* Same int8 container case as the resident offer in moe():* on an int8 container ps->g4 is NULL and the prefetch offer- * never fired (#1391). Offer the int8 weights instead. */- if (ps->g4)- qt_note(lnext, eid, ps->g4, ps->u4, ps->d4, ps->gs, ps->us, ps->ds);- else if (!g_expert_is_int4 && ps->g)- qt_note(lnext, eid, (const uint8_t *)ps->g, (const uint8_t *)ps->u,- (const uint8_t *)ps->d, ps->gs, ps->us, ps->ds);+ * never fired (#1391). tier_offer_slot handles both formats. */+ tier_offer_slot(lnext, eid, ps);}if (!found) {int gidx = lnext*E + eid;diff --git a/c/qwen36_tier.h b/c/qwen36_tier.hindex f99311be..3d9bdcfd 100644--- a/c/qwen36_tier.h+++ b/c/qwen36_tier.h@@ -88,7 +88,9 @@ int qt_is_resident(int layer, int eid);void qt_shutdown(void);/* Call once per routed expert per token (pointers to the RAM slot: packed- * int4 + per-row scales). Updates heat and may enqueue a background upload. */+ * int4 or, on an int8 container, the live int8 weights -- tier fmt=1 is+ * accepted since #1334; see also #1391 for the decode-path offer). Updates+ * heat and may enqueue a background upload. */void qt_note(int layer, int eid,const uint8_t *g4, const uint8_t *u4, const uint8_t *d4,const float *gs, const float *us, const float *ds);diff --git a/c/tests/test_qwen36_tier_int8_decode.c b/c/tests/test_qwen36_tier_int8_decode.cindex cf344ef6..7aa49286 100644--- a/c/tests/test_qwen36_tier_int8_decode.c+++ b/c/tests/test_qwen36_tier_int8_decode.c@@ -23,6 +23,12 @@* the tier accepted an int8 pointer (fake_uploads > 0) and that the resident* set grows -- the assertion from #1391 that fails on the old expression.*/+/* The production offer path itself: qwen36.c's tier_offer_slot() is the exact+ * function moe()'s resident offer and the pilot-prefetch lookahead call, so+ * this test drives the real code, not a copy. The two sites and the warmstart+ * can no longer drift apart: reverting the production gate to the bare+ * `if (s->g4)` makes the int8 case below fail exactly the way #1391 reports. */+#define decode_offer tier_offer_slot#define main qwen36_main_unused#include "../qwen36.c"#undef main@@ -131,18 +137,6 @@ static int wait_resident(void) {return 0;}-/* The offer decision both decode-path sites now make, lifted verbatim from- * moe()'s resident offer (the prefetch site is the same choice on `ps`). If- * this expression regresses to the bare `if (e->g4)`, the int8 case below- * fails exactly the way the issue describes. */-static void decode_offer(int layer, int eid, Slot *s) {- if (s->g4)- qt_note(layer, eid, s->g4, s->u4, s->d4, s->gs, s->us, s->ds);- else if (!g_expert_is_int4 && s->g)- qt_note(layer, eid, (const uint8_t *)s->g, (const uint8_t *)s->u,- (const uint8_t *)s->d, s->gs, s->us, s->ds);-}-/* --- an int8 container, QT_NO_WARMSTART=1: the decode offer must promote --- */static void case_int8_decode(void) {printf("int8 container, decode-path offer (no warmstart)\n");@@ -230,4 +224,4 @@ int main(void) {if (fails) { printf("FAILED %d\n", fails); return 1; }printf("OK test_qwen36_tier_int8_decode\n");return 0;-}\ No newline at end of file+}