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

vk_tier: vkt_begin_forward, for a model with a single MoE layer

JustVugg87a939156298
diff --git a/c/vk_tier.c b/c/vk_tier.c
index ac158509..60d6479c 100644
--- a/c/vk_tier.c
+++ b/c/vk_tier.c
@@ -45,6 +45,7 @@ static struct {
VSlot *s;
uint32_t tick, decay_at; /* tokens seen (rows of the forward's first layer) */
int last_layer, first_layer, promos, promo_cap;
+ int begin; /* vkt_begin_forward: the next issue starts a forward */
/* uploader */
pthread_t th; int th_on, stop;
pthread_mutex_t mx; pthread_cond_t cv, cv_room, cv_done;
@@ -490,7 +491,7 @@ int vkt_issue(int layer, const float *x, int S, int K, const int *idx, uint8_t *
if (T.on) { fprintf(stderr, "[VK] tier %s: the device stopped answering, the experts stay on the CPU\n", T.engine); T.on = 0; }
return 0;
}
- if (layer < T.last_layer) { T.first_layer = layer; new_forward(); }
+ if (layer < T.last_layer || T.begin) { T.begin = 0; T.first_layer = layer; new_forward(); }
if (layer == T.first_layer) { /* COLI_VK_TIER_RATE promotions per token of the forward */
T.tick += (uint32_t)S;
long cap = (long)T.promo_cap + (long)T.rate * S;
@@ -608,6 +609,7 @@ int vkt_join(const float **rows) {
return 1;
}
+void vkt_begin_forward(void) { if (T.on) T.begin = 1; }
int vkt_resident(int layer, int eid) {
return T.on && layer >= 0 && layer < T.c.layers && eid >= 0 && eid < T.c.experts &&
slot(layer, eid)->state == VS_RESIDENT;
diff --git a/c/vk_tier.h b/c/vk_tier.h
index 9e615733..2d7d89f7 100644
--- a/c/vk_tier.h
+++ b/c/vk_tier.h
@@ -168,6 +168,10 @@ void vkt_note(int layer, int eid, const VktExpertSrc *src);
int vkt_issue(int layer, const float *x, int S, int K, const int *idx, uint8_t *taken);
int vkt_join(const float **rows);
int vkt_resident(int layer, int eid);
+/* The next vkt_issue starts a forward (promotion rate, decay, eviction candidates).
+ * Optional: the tier tells forwards apart by the layer index going back, which a model
+ * with a single MoE layer never does; such an engine calls this at its first MoE layer. */
+void vkt_begin_forward(void);
void vkt_report(const char *scope, unsigned long long ram_hits, unsigned long long disk_loads);
/* Sizing helpers for engines: bytes one expert takes on the device in a source format. */
size_t vkt_expert_bytes(int hidden, int inter, VktFmt gate_up, VktFmt down);
@@ -183,6 +187,7 @@ static inline void vkt_note(int l,int e,const VktExpertSrc *s){(void)l;(void)e;(
static inline int vkt_issue(int l,const float *x,int S,int K,const int *i,uint8_t *t){(void)l;(void)x;(void)S;(void)K;(void)i;(void)t;return 0;}
static inline int vkt_join(const float **r){(void)r;return 0;}
static inline int vkt_resident(int l,int e){(void)l;(void)e;return 0;}
+static inline void vkt_begin_forward(void){}
static inline void vkt_report(const char *s,unsigned long long r,unsigned long long d){(void)s;(void)r;(void)d;}
static inline size_t vkt_expert_bytes(int h,int i,VktFmt a,VktFmt b){(void)h;(void)i;(void)a;(void)b;return 0;}
#endif